[C++-sig] const shared_ptr and py++ / boost.python
roman.yakovenko at gmail.com
Sun Jun 7 08:26:00 CEST 2009
On Thu, Jun 4, 2009 at 11:37 PM, Nicolas
Regnault<nicolas.regnault at lpnhe.in2p3.fr> wrote:
> Dear all:
> I am wrapping a library which relies heavily on boost smart pointers (mainly
> boost::shared_ptr< T >). In particular, many functions and methods have
> signatures like:
> void my_func( const boost::shared_ptr< MyClass > & );
> Everything works well from within C++ programs. But I encounter a serious
> problem with the wrappers I have generated with py++. Indeed, when passing
> from python, something which wraps a "shared_ptr< MyClass >" to
> my_function(), the code within the function apparently gets a shared_ptr
> with a use_count equal to 1 (pointing to the same address), whatever the
> use_count of the shared_ptr passed to the function.
> I haven't been able to see what boost.python is doing in between, but
> something gets altered. Any idea of what is wrong with the wrappers ?
I am pretty sure, there is nothing wrong with the generated code. It
is pretty close to the code, you would write.
I think it happens, because Boost.Python is able to construct smart
pointer class instance( shared_ptr ) from an Python object( which
holds C++ class instance ) on the fly. It does so with custom deleter.
If your projects works a lot with boost::shared_ptr, may be it makes
sense for you to redefine HeldType (
C++ Python language binding
More information about the Cplusplus-sig