[C++-sig] Pybindgen/pygccxml integration

Gustavo Carneiro gjcarneiro at gmail.com
Tue Jun 23 17:39:09 CEST 2009


2009/6/23 Ben Fitzpatrick <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
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/cplusplus-sig/attachments/20090623/6b610191/attachment.htm>


More information about the Cplusplus-sig mailing list