[C++-sig] pybindgen add_function_as_constructor

Robin Gilks robin.gilks at tait.co.nz
Mon Apr 27 06:06:11 CEST 2009

Robin Gilks wrote:
> Following on from my expanding embedded code thread, I'm making 
> progress in that if I hack the class instantiation in the wrapper that 
> pybindgen produces I can get it all to work.
> With that in mind, I'm trying to use add_function_as_constructor but 
> it won't let me use a 'void *' or 'PyObject *' pointer as a parameter. 
> I have to use 'uint32_t *' and then edit the code!!
> My generator code looks like this...
> testclass = mod.add_class('testclass')
>    testclass.add_function_as_constructor('PyCObject_AsVoidPtr', None, 
> [Parameter.new(''PyObject *', 'instance', transfer_ownership = False)])
> which results in the traceback of...
> Traceback (most recent call last):
>  File "testclassgen.py", line 31, in <module>
>    my_module_gen(sys.stdout)
>  File "testclassgen.py", line 28, in my_module_gen
>    mod.generate(FileCodeSink(out_file) )
>  File "/usr/local/lib/python2.5/site-packages/pybindgen/module.py", 
> line 839, in generate
>    self.do_generate(sink_manager, module_file_base_name)
>  File "/usr/local/lib/python2.5/site-packages/pybindgen/module.py", 
> line 721, in do_generate
>    class_.generate(sink, self)
>  File "/usr/local/lib/python2.5/site-packages/pybindgen/cppclass.py", 
> line 1481, in generate
>    have_constructor = self._generate_constructor(code_sink)
>  File "/usr/local/lib/python2.5/site-packages/pybindgen/cppclass.py", 
> line 1620, in _generate_constructor
>    overload.generate(code_sink)
>  File 
> "/usr/local/lib/python2.5/site-packages/pybindgen/overloading.py", 
> line 183, in generate
>    (code_sink,), {}, self.all_wrappers[0])
>  File "/usr/local/lib/python2.5/site-packages/pybindgen/utils.py", 
> line 124, in call_with_error_handling
>    return callback(*args, **kwargs)
>  File "/usr/local/lib/python2.5/site-packages/pybindgen/cppmethod.py", 
> line 520, in generate
>    % self._class.name)
> AssertionError: something went wrong with the type handlers; 
> constructors need parameter names, yet no names were given for the 
> class testclass constructor
I've found the pybindgen commit for revision 628 and that fixes the 
PyObject problem - got a new one now!! I can't work out the syntax to 
return any sort of pointer for example
    mod.add_method('methodA', ReturnValue.new('uint8_t *'), [])
This is probably me again not understanding the Python side of things - 
how would I return a string otherwise?

I see that some of the fixes are in the NS-3 project as 
pybindgen- (I assume this means up to and including commit 
630) but there is no waf included in this project so I can't build it :-(

Again, any help would be appreciated...



This email, including any attachments, is only for the intended
addressee.  It is subject to copyright, is confidential and may be
the subject of legal or other privilege, none of which is waived or
lost by reason of this transmission.
If the receiver is not the intended addressee, please accept our
apologies, notify us by return, delete all copies and perform no
other act on the email.
Unfortunately, we cannot warrant that the email has not been
 altered or corrupted during transmission.

More information about the Cplusplus-sig mailing list