[C++-sig] pybindgen add_function_as_constructor

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


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

If I change the 'PyObject *' to a 'void *' I get...Traceback (most 
recent call last):
  File "testclassgen.py", line 31, in <module>
    my_module_gen(sys.stdout)
  File "testclassgen.py", line 16, in my_module_gen
    testclass.add_function_as_constructor('PyCObject_AsVoidPtr', None, 
[Parameter.new('void *', 'instance', transfer_ownership = False)])
  File 
"/usr/local/lib/python2.5/site-packages/pybindgen/typehandlers/base.py", 
line 1221, in new
    param_type_matcher.lookup(ctype)
  File 
"/usr/local/lib/python2.5/site-packages/pybindgen/typehandlers/base.py", 
line 1350, in lookup
    raise TypeLookupError(tried_names)
pybindgen.typehandlers.base.TypeLookupError: ['void *']

but looking at pybindgen-0.10.0/pybindgen/typehandlers/base.py it looks 
like at least void * should be OK!!

I either still missing something (very likely) or there is a problem here!

-- 
Robin






=======================================================================
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