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

Hugo van der Merwe s13361562 at bach.sun.ac.za
Tue Jan 22 11:26:42 CET 2002


> 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).

Not sure I followed that 100%. Here is how I understand it at the
moment, quite possibly incorrectly, correct me where I go wrong:

It uses refcounts, right, so if you do:

a = NewClass()

the instance of NewClass's refcount just went up by one. Then I do

someCPPClass.Add(a)

This puts the instance mentioned above in some list. If I now reassign
the python "a" to something else, e.g.:

a = 0

The refcount for the instance of NewClass will go down by one again,
won't it? In which case it will be disposed? Unless the refcount is
increased by the someCPPClass.Add(a) call, something that Boost.Python
will have to take care of, if I'm correct so far.

Where am I going wrong? Or does Boost.Python take care of this? Or will
there be a GC problem? I have not yet tested this. Maybe I should some
time soon.

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

Ah, thanks a lot. I suspected as much. I think in my case NN will be
something like 17. ;) (I've seen at least one constructor with 17
parameters.)

Thanks,
Hugo van der Merwe




More information about the Cplusplus-sig mailing list