Thanks. I have perl 5.6 installed. I looked at the typemap and i find both
mapped as follows..
char * T_PV
wchar_t * T_PV
Is there something wrong here ?
The other thing if I had to map const wchar_t**, how would I do it ? I also
have API's with such return types.
Thanks once again.
-----Original Message-----
From: Nick Ing-Simmons [mailto:[EMAIL PROTECTED]]
Sent: Tuesday, December 12, 2000 2:08 PM
To: [EMAIL PROTECTED]
Cc: [EMAIL PROTECTED]
Subject: Re: Return Value : Constants
Soumen Das <[EMAIL PROTECTED]> writes:
>Hi,
>
>I am having some problem with constants as return values.
No you aren't - you are having problems with wchar_t ...
>
>I am trying to Perl wrap this API.
>const wchar_t* ErrorString(long hr)
>
>
>My typemap is :
>const wchar_t* T_PV
But a PV is a char * not a wchar_t *
>
>While compiling I do get the following error. I am using the Sun's CC
>compiler.
>
>"XSConfig.c", line 59: Error: Formal argument ptr of type const char* in
>call to Perl_sv_setpv(sv*, const char*) is being passed const wchar_t*.
>
>What am I doing wrong ? Is there a special way to deal with constants ?
There isn't a built in mapping for wchar_t - you can't just use T_PV
as that passes just one arg and you need something that gives the length
as well. When sv_setpv() does strlen() in a wchar_t * then it will see
a very short "string" in most cases as a '\0' will occur in the extra bytes
of the "wide characters".
If you just want to save the string and then pass it back into XS code
later then a custom typemap which called sv_setpvn() would do:
const wchar_t* T_WCHAR
INPUT:
T_WCHAR
$var = ($type)SvPV_nolen($arg)
OUTPUT:
T_WCHAR
sv_setpv((SV*)$arg, (char *) $var, wcslen($var)*sizeof($type));
But if you want perl to see a sane string you need
(a) perl5.6.0 or later
(b) something to translate wchar_t * into UTF-8 encoded Unicode.
This is still work-in-progress
--
Nick Ing-Simmons