[C++-sig] Boost.Python and lifetime of instances of C++ classes

Ralf W. Grosse-Kunstleve rwgk at yahoo.com
Thu Jan 24 20:18:16 CET 2002


--- Hugo van der Merwe <s13361562 at bach.sun.ac.za> wrote:
> Thanks! So making it boost::shared_ptr causes Boost.Python to
> automatically call Py_INCREF and Py_DECREF?

When you pass a shared_ptr to Python, you have a
ref-counted object (shared_ptr, please read the docs!)
inside another ref-counted object (PyObject).

Note: In classic Boost.Python, passing a reference to a C++
object to Python is equivalent to passing the object by 
value.  This is known as the "returned reference problem"
(and is the subject of the top development goal shown on
the main C++ SIG web page.)

> Another question: is it possible for a second wrapper to use things from
> a first? (I want to make another wrapper, which must be usable at the
> same time as the first, but there are e.g. parameters in the second that
> are of types wrapped in the first.) I think this is probably not
> possible, and the two will have to be combined into one?

Have you looked at the section about cross-module support?
Please note that there lures another problem: classic
Boost.Python does not support cross-module declare_base().
Resolving this is the second most important development
goal (SIG page) (at least as I see it :-).

> Last question: where can I learn more about exceptions? (E.g. how to get
> a C++ exception passed on into Python.)

grep for "error_already_set" in the example directory.

Ralf


__________________________________________________
Do You Yahoo!?
Great stuff seeking new owners in Yahoo! Auctions! 
http://auctions.yahoo.com




More information about the Cplusplus-sig mailing list