[PyKDE] SIP: MappedType for pointers?

Jim Bublitz jbublitz at nwinternet.com
Tue Mar 21 20:41:14 GMT 2006

On Tuesday 21 March 2006 10:23, Giovanni Bajo wrote:
> Hello,
> I'm writing a SIP wrapper for a serie of overloaded functions like this:
> void Foo(char *str);
> void Foo(wchar_t *str);
> void Bar(char *str);
> void Bar(wchar_t *str);
> [etc.]
> Python supports conversion to/from wchar_t buffers using
> PyUnicode_From/AsWideChar, but SIP does not support it. Could this be added
> automatically?
> This notwithstanding, I couldn't find a way to use %MappedType to solve my
> problem, without having to write many duplicated %MappedCode. Any pointer?

Same as the following, except "%MappedType wchar_t" and other obvious changes. 
You'd only have to write it once - all conversions will be handled correctly 
wherever wchar_t is referenced. 

%MappedType longlong
//converts a Python long
typedef long long longlong;
    if (!sipCpp)
        Py_INCREF (Py_None);
        return Py_None;

    return PyLong_FromLongLong (*(LONG_LONG *)sipCpp);

    if (sipIsErr == NULL)
        return PyLong_Check (sipPy) || PyInt_Check (sipPy);

    long long *ll = new long long;
    *ll = 0;

    if (PyLong_Check (sipPy))
        *ll = PyLong_AsLongLong (sipPy);
    else if (PyInt_Check (sipPy))
        *ll = (long long)PyInt_AS_LONG (sipPy);

    *sipCppPtr = ll;

    return 1;



More information about the PyQt mailing list