[capi-sig] [C++-sig] ANNOUNCE: PyBindGen 0.8

Gustavo Carneiro gjcarneiro at gmail.com
Sat Dec 8 13:19:10 CET 2007

On 08/12/2007, Joseph Lisee <jlisee at gmail.com> wrote:
> That is very cool to here I have one concern and a few comments.  I am not
> sure
> what to think of the annotations in the comments.  It feel at same time
> both a
> hack because it replaces a API around your generator

 It does not really replace the API.  Think of PyBindGen as two separate
layers: 1. an low level API layer, and 2. header file scanning and
annotations, which are built on top of that layer.  The first layer would be
needed anyway, for code modularity and readability.  And the first layer can
be used directly; I don't see any problem with that.

and elegant because you
> don't have to maintain a separate set of files to represent the
> wrapping.  The
> downside of this is that you would have to modify the source of any code
> you
> would wish to wrap, and that will get quite cumbersome.

It is very true.  Sometimes you cannot modify the header files you're trying
to wrap.

On the other hand, experience tells me you can't fully automate wrapping
C/C++ code without either 1) strict displine in the C/C++ code, to use
certain memory management conventions (e.g. "callee should never take
ownership of the objects in parameters"). or 2) the python bindings have
extra information not explicit in the C language.  Bottom line is, in the
real world you cannot fully automate bindings; you need to give the bindings
generator extra information besides the header files.

Annotations is IMHO a nice way to give that extra information, when you
can.  Not only it's easier to follow the annotations since they're right
next to the API declarations, but it gives information that even C/C++
coders will find useful.

How to enter annotations when you can't modify the header files is, however,
an open question.  I don't have a clear answer yet, and suggestions are

I am also wondering if you have decent support for standard containers?
> Something like Boost.Python indexing suite version 2.

Right again.  PyBindGen does not have that as of yet.  I would like to
implement it some day.  But I don't think it's as hard as it sounds, so
don't lose hope just yet :)

One question, though, if someone can answer.  How does BP indexing suite map
e.g. sequence containers?  Just convert all elements to a python list?  Or
does it implement an object that supports iteration and sequence special

BTW, there are more limitations in PyBindGen that people should be aware of,
such as:
  - Does not support multiple inheritance (I don't like MI and have no plans
to implement it any time soon, unless a patch is brought to me);
  - Generates a single potentially big C/C++ file, no splitting done as of
  - No support yet for one module importing definitions from another module;
  - Definitions nested inside class namespaces not supported (though should
not be hard to implement);

Thanks for the comments,
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 capi-sig mailing list