Boost logo

Boost Users :

From: John Meinel (boost_at_[hidden])
Date: 2004-10-30 08:24:15


I realize this may not be the right list, but since I'm already
subscribed...

I've been using boost::python to wrap some C++ code for quite a while
now, and I've been quite happy with it. However, I decided to get into
boost more, and I've found that shared_ptr/shared_array are quite nice.
So I've started changing my functions from returning a raw pointer to
returning a shared_ptr.

In the boost::python tutorial, they talk about when you return a raw
reference or pointer, you need to wrap it to manage lifetime of the object.
http://www.boost.org/libs/python/doc/tutorial/doc/call_policies.html

In the beginning of that page, they talk about how smart pointers are
better for defining the scope and lifetime of objects, but sometimes raw
pointers are necessary. I've gotten pretty good about when to
manage_new_object, or return_internal_reference, etc.

However, now that I have changed my return functions to actually return
a smart pointer, it doesn't seem like I should need to wrap the return
value anymore. Only now, when I try to do a "get" it gives me the error:

" No to_python (by-value) converter found for C++ type: class
boost::shared_ptr<class mine> "

I have a converter for "class mine". I actually thought that the
lifetime managers were using a shared_ptr, so if I did it myself, it
would just be transparent.

Does anyone know what the proper way to export a shared_ptr into python
is? I suppose I could define the shared_ptr<class mine>, and only expose
the "get()" function. But that would certainly be less than optimal. (I
also obviously cannot wrap my function in another function that returns
get(), because that would cause the shared_ptr to have the wrong lifetime.)

Thanks for any help,
John
=:->


Boost-users list run by williamkempf at hotmail.com, kalb at libertysoft.com, bjorn.karlsson at readsoft.com, gregod at cs.rpi.edu, wekempf at cox.net