[C++-sig] new to python wrapping...

David Abrahams david.abrahams at rcn.com
Mon Jan 21 22:35:56 CET 2002


----- Original Message -----
From: "Hugo van der Merwe" <s13361562 at bach.sun.ac.za>
To: <c++-sig at python.org>
Sent: Monday, January 21, 2002 4:24 PM
Subject: [C++-sig] new to python wrapping...


> Hello,
>
> I've lately started playing with Python wrapping. Tried both SWIG and
> Boost.Python, I'm thinking so far that Boost.Python's C++ and Python
> specific nature will make it more ideally suited to what I want to do (I
> don't care about bidnings other scripting languages).
>
> I've got two questions so far. One is what happens with garbage
> collection: if I create an instance of an object from a Python script,
> then add this to e.g. a list in some other C++ class, Python won't know
> it is still being used, and will try to garbage collect it?

No; it took me a while to understand this myself, but Python uses a
different sort of GC which is more conservative. Instead of collecting
everything it can't prove is referenced, it looks for reference cycles that
it /can/ find, and which it can prove are not referenced from outside the
cycle (it can do that by looking at the reference counts).

> The other is a problem I'm having with a constructor. It worked
> previously, but after the latest changes in the source, I'm getting the
> following (it's a pretty ugly looking constructor ;) :
>
> C++ header:
>
> <SNIP>

> I hope this isn't something silly I've done that causes this, but I
> definately count 11 parameters in the C++ constructor, as well as my
> attempt at a python wrapping of it...

You just exceeded Boost.Python's builtin limits, but you can extend them by
running

    python libs/python/src/gen_all.py NN

where NN is the maximum number of arguments you need to support. That will
generate some C++ header files which you use in place of the corresponding
ones in your Boost installation.

-Dave







More information about the Cplusplus-sig mailing list