develooper Front page | perl.xs | Postings from February 2012

wchar_t and XS

Thread Next
From:
Alberto Simões
Date:
February 27, 2012 08:30
Subject:
wchar_t and XS
Message ID:
4F4BAF85.10906@alfarrabio.di.uminho.pt
Hello

I really need to make my code work with XS and wchar_t.
As far as I can tell there is no typemap for that in the core:

xs/NATools.c:733: warning: passing argument 3 of ‘Perl_sv_setpv’ from 
incompatible pointer type

I googled for that, and found a typemap, but I do not understand how 
typemaps work. My typemap looks like:

------ 8< ----------


TYPEMAP
wchar_t

INPUT
T_WCHAR
    {
    // Alloc memory for wide char string. This could be a bit more
    // then necessary.
    Newz(0, $var, SvLEN($arg), wchar_t);

    U8* src = (U8*) SvPV_nolen($arg);
    wchar_t* dst = (wchar_t*) $var;

    if (SvUTF8($arg)) {
       // UTF8 to wide char mapping
       STRLEN len;
       while (*src) {
           *dst++ = utf8_to_uvuni(src, &len);
           src += len;
       }
    } else {
        // char to wide char mapping
        while (*src) {
            *dst++ = (wchar_t) *src++;
        }
    }
    *dst = 0;
    SAVEFREEPV($var);
    }
------ 8< -------------

But then, this seems to be a Perl => wchar only. I would need the other 
way around too.

Any help?

Thanks
Ambs

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About