[C++-sig] Pybindgen/pygccxml integration

Ben Fitzpatrick bfitzpatrick at vtiinstruments.com
Tue Jun 23 18:43:55 CEST 2009


Thanks for the suggestions!

I tried the first one, just as a test. I'd like to do the second 
programatically if I can, but I just wanted to make sure annotations 
were going to fix this. It still seems to be giving me the same error:
(...)/pure_virtual.h:5: WrapperWarning: Parameter 'int * value' error 
(used in int pure_virtual_class::get_value(int * value) [member 
function]): <pybindgen.typehandlers.base.TypeConfigurationError instance 
at 0xb780326c>
  virtual int get_value(int* value) = 0;

Here is what I changed my code to:

    // -#- @value(transfer_ownership=true) -#-
   virtual int get_value(int* value)=0;

This appears to be similar to the declaration you pointed me to in foo.h:
// -#- @zbr(transfer_ownership=true) -#-
void store_zbr (Zbr *zbr);

Also tried renaming it to 'foobaz' in case 'value' was a keyword. Is 
there something I'm missing?

Thanks,
Ben Fitzpatrick


Gustavo Carneiro wrote:
>
>
> 2009/6/23 Ben Fitzpatrick <bfitzpatrick at vtiinstruments.com 
> <mailto:bfitzpatrick at vtiinstruments.com>>
>
>     Hi everyone,
>
>     I'm just starting to check out pybindgen after the messages I've
>     seen floating around on this mailing list, and I have a question
>     about the pygccxml integration. I've made a pure-virtual class
>     with a pointer return type, like so:
>
>     class pure_virtual_class
>     {
>       virtual int get_value(int* value)=0;
>       virtual int put_value(int value)=0;
>
>       static pure_virtual_class* Create();
>     };
>
>     Normally I'd call add_function('get_value', retval(int),
>     [param('int *', 'value', transfer_ownership=True)]) (I think)
>     But since I'm scanning the headers with gccxml, I'm not sure how
>     to tell it to transfer the ownership.
>     Right now it's giving me a TypeConfigurationError during 'parse',
>     which appears to be because it doesn't know how to deal with the
>     ownership.
>
>     I looked in the documentation and couldn't find anything
>     referencing this, and none of the examples use gccxml.
>
>     Any ideas?
>
>
> Yes, there are two possible (alternative) ways to deal with this:
>
>   1. Add inline annotations as C++ comments in the header file to be 
> scanned;
>   2. Add scanning hooks to inject annotations via a function callback;
>
> For inline annotations, see tests/foo.h, look for the comment lines 
> containing -#-.  I must warn you, though, that annotations are kind of 
> a "brittle" system.  The annotations are searched upwards starting in 
> the line immediately before the line that gccxml reports as the line 
> the declaration is defined.  The problem here is that gccxml reports 
> the line of a declaration sometimes in weird and unexpected places.
>
> The other way is more complicated in terms of code, but doable with 
> some pacience.  You can see an example in ns-3 [1], in the 
> pre_scan_hook function.
>
>
> [1] 
> http://code.nsnam.org/ns-3-dev/file/96811f76c3e2/bindings/python/ns3modulescan.py
>
> I hope this helps.
>
> -- 
> Gustavo J. A. M. Carneiro
> INESC Porto, Telecommunications and Multimedia Unit
> "The universe is always one step beyond logic." -- Frank Herbert



More information about the Cplusplus-sig mailing list