[C++-sig] ANNOUNCE: PyBindGen 0.8

Hans Meine meine at informatik.uni-hamburg.de
Sun Jun 1 21:45:36 CEST 2008


Hi!

On Dienstag 04 Dezember 2007, Gustavo Carneiro wrote:
> The other day I released PyBindGen 0.8.  Main news is that it features a
> new experimental header file scanner based on pygccxml (i.e., it's similar
> to py++ in scope, if not in maturity, but does not use
> boost.pythonunderneath).

This all sounded very interesting, so I have just tried pybindgen out.

First, I noticed, that void return type is handled with Py_BuildValue, which 
is slight overkill, isn't it (since one of PyBindGen's design goals is to 
write lean, nearly-handwritten style code)?  I have registered on launchpad 
to be able to submit a patch when I would have managed to make it return 
Py_None directly, but I have more serious problems when trying to wrap the 
following simple type declaration:

union Word
{
	short word;
	struct
	{
		char low, high;
	};
};

The gccxml module does not seem to recognize the "short" return value:

.../word.h:6: Warning: Return value 'short int' error (used in Word::word 
[variable]): TypeLookupError('short int',)
  short word;

However, when looking at pybindgen/typehandlers/inttype.py, fixing this seems 
to be possible, but I wonder if a more general approach than adding one class 
for each combination of const/ptr/ref/unsigned/width integer type would be 
more sensible?  Obviously, I'd better leave this decision & fix to the 
original authors.

Finally, the anonymous struct inside the union is not yet supported.  AFAICS, 
PyBindGen would "simply" need to descend into the struct and export its 
members like direct members of the surrounding type.  Right now, it produces 
illegal code because it tries to wrap a data member with an empty string as 
name:

static PyObject* _wrap_PyWord__get_(PyWord *self)
{
    PyObject *py_retval;
    PyWord *py_Word;

    py_Word = PyObject_New(PyWord, &PyWord_Type);
    py_Word->obj = new Word(self->obj->);
    py_retval = Py_BuildValue("N", py_Word);
    return py_retval;
}
[...]
static PyGetSetDef PyWord__getsets[] = {
    {
        "", /* attribute name */
        (getter) _wrap_PyWord__get_, /* C function to get the attribute */
        (setter) _wrap_PyWord__set_, /* C function to set the attribute */
        NULL, /* optional doc string */
        NULL /* optional additional data for getter and setter */
    },
    { NULL, NULL, NULL, NULL, NULL }
};

Ciao, /  /                                                    .o.
     /--/                                                     ..o
    /  / ANS                                                  ooo
-------------- next part --------------
A non-text attachment was scrubbed...
Name: not available
Type: application/pgp-signature
Size: 197 bytes
Desc: This is a digitally signed message part.
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20080601/bcc7ae60/attachment.pgp>


More information about the Cplusplus-sig mailing list