Sisyphus <[EMAIL PROTECTED]> writes: >Hi, > >In an Inline C script I'm trying to pass a wide character string from perl. > >The perl side would look like (eg): > >$s = chr(12345) . chr(54321);
SvPV of s now has two chars utf8 encoded. >pass_wide_string($s); > >and the Inline C function: > >void pass_wide_string(SV * w) { > wchar_t * widestring = SvPV_nolen(w); > . > . > >Is that a correct way for pass_wide_string() to grab the argument ? No. >I >get a compiler warning that the line in question performs an >"initialization from incompatible pointer type". Because SvPV is a char * not a wchar_t * You need to convert to wide chars somewhere. Which may mean knowing what kind of wide char it is. e.g. pass_wide_string(encode('UCS-2',$s)); # say and then cast in XS side: wchar_t * widestring = (wchar_t *) SvPV_nolen(w); Or assuing wchar_t hold Unicode probably more robust leave perl side way it is and build a wchar_t string on XS side: U8 *src = (U8 *) SvPV_nolen(sv); wchar_t *dst; STRLEN len; wchar_t * widestring; Newz(32,widestring,wchar_t,SvCUR(sv)); // Bigger than needed dst = widestring; while (*src) { *dst++ = utf8_to_uv(src,&len); src += len; } *dst++ = 0; ... Safefree(widestring);