On Fri, Jul 27, 2012 at 9:53 AM, David Mertens <dcmertens.p...@gmail.com>wrote:
> > Yeah. What one should do here depends on how much control you have > over the code. You can have Perl downgrade the string to a true byte > string if you use SvPVbyte_nolen, as I suggest, but then you loose any > unicode characters that your user may have passed in. If you don't > control your C++ library and it expects true C-style strings, then you > haven't much of an option. > I kind of got lost on the last part of this discussion. But I just realized I'm doing something wrong related to encoding. But as for the memory management, I'm using Newx() to create the array, the populating it directly with SvPV, then after calling the C++ constructor I Safefree() the array. But what I'm doing wrong is not handling encoding. If the C++ code is expecting utf8-encoded strings then I need to check if the SV has the utf8 flag on and then call bytes_to_utf8() if the flag is NOT set. If it's already set I should be able to copy directly. Is that correct? perlguts doesn't provide an example of how to use bytes_to_utf8(). Plus perlapi says it's experimental. Or the other option is to upgrade the SV in place, right? But, I'm then upgrading the passed in string which the caller may not expect. Hum, but then perlguts says don't do this: 1. if (!SvUTF8(left)) 2. sv_utf8_upgrade(left); So, I guess I have to ask for help with this. If I need to pass utf8 encoded strings to the C++ methods what's the correct way to upgrade/convert to utf8 and not have side-effects to the calling code? -- Bill Moseley mose...@hank.org