[PyKDE] SIP: unicode to wchar_t* in C modules

Phil Thompson phil at riverbankcomputing.co.uk
Wed Mar 29 16:43:14 BST 2006


On Wednesday 29 March 2006 4:16 pm, Matteo Beniamino wrote:
> Hi,
>
> I'm having some trouble mapping a unicode Python variable to a C
> wchar_t* . I reused a MappedType directive that works flawlessy for a
> C++ module.

%MappedTypes are for mapping classes and structs, not for basic types. If it 
works in a C++ context then it's down to luck.

I'm happy to add support for wchar_t in C++ modules in a future version of SIP 
(because it is a basic type in C++ - something I hadn't realised until 
recently). I will only add support for it in C modules if it comes for free 
with the C++ support.

> First problem: SIP generates .c files containing some C++ 
> directives (i.e.: delete and reinterpret_cast<>).

This is fixed in current snapshots.

> I patched gencode.c[1] 
> to handle C modules, but even so there are still some problems, in fact
> while for C++ SIP correctly refers to "wchar_t", for C it refers to
>
> "struct wchar_t", like here:
> > struct wchar_t **sipCppPtr = (struct wchar_t **)(sipCppPtrV);
>
> and here:
> > sipMappedType sipMappedTypeDef_wchar_t = {
> >   "struct wchar_t",
> >   release_wchar_t,
> >   forceConvertTo_wchar_t,
> >   convertTo_wchar_t,
> >   convertFrom_wchar_t
> >  };
>
> Source compiles with some warnings, but passing unicode variables to
> functions has strange effects (the string changes or I get access
> violations).
>
> Is this a bug or a known limitation? Any suggestion?
>
> I attached a test case and the gencode.c patch (against 20060325 cvs
> snapshot).
>
> Thank you for any help.
>
> [1] This patch uses free instead of delete for mapped types in C
> modules, so if you map a struct containing data that needs to be
> deallocated there is no way to do it, since there is no destructor
> in C.

Phil




More information about the PyQt mailing list