nikolaus has asked for the wisdom of the Perl Monks concerning the following question:

When using XS from a C++ app that uses UTF16 internally (multi-platform), what's the right way to send strings back and forth?

I can transcode to UTF8 and newSVpv( ) them, but do I then need to SvUTF8_on( ) every one of those? Or does perl figure it out on its own?

What about XPUSHp( ) and POPp( )? Do I need to test for UTF8 on each of those?

Is giving the interpreter -Mutf8 on startup the Right Thing to do?

Replies are listed 'Best First'.
Re: XS from C++/UTF16
by PodMaster (Abbot) on Jul 17, 2003 at 20:38 UTC
      Ah, perlguts; missed that one. That seems to provide a unifrom answer to all of my questions: I have to keep telling perl that my strings are UTF8, and I have to check every string I get back from perl to see if it is UTF8, and transcode from either UTF8 or the current locale back to UTF16, as appropriate.

      A consequence is that -Mutf8 neither helps nor hurts me; since I'm telling perl that my strings are utf8 one-at-a-time, the global flag is irrelevant.

      Thanks for the pointer. -nik