Opened 14 years ago
Closed 14 years ago
#2584 closed Bugs (fixed)
boost::enable_shared_from_this + boost.python library
Reported by: | Owned by: | Peter Dimov | |
---|---|---|---|
Milestone: | Boost 1.39.0 | Component: | smart_ptr |
Version: | Boost 1.37.0 | Severity: | Problem |
Keywords: | enable_shared_from_this | Cc: |
Description
A problem that was raised, on february, on c++-sig mailing list about a problem happening when wrapping classes derived from 'enable_shared_from_this' using boost.python library.
The problem is briefly described in this post - including a patch to boost/shared_ptr.hpp that would allow to work around the problem. http://mail.python.org/pipermail/cplusplus-sig/2008-February/012973.html
To make it short, boost.python creates shared_ptr objects, holding the wrapped c++ objects, with a custom deleter managing the python object reference count. This leads to something like that :
#include <boost/enable_shared_from_this.hpp>
namespace {
class A : public boost::enable_shared_from_this<A>
{
public:
~A() {};
};
void my_deleter(void*)
{
}
};
BOOST_AUTO_TEST_CASE( test_enable_shared_from_this )
{
boost::shared_ptr<A> a( new A );
{
boost::shared_ptr<A> ater =
boost::shared_ptr<A>( a.get(), my_deleter );
OP patch proposal:
boost::shared_ptr<A> ater =
boost::shared_ptr<A>( a.get(), my_deleter
, boost::dont_enable_shared_from_this() );
BOOST_CHECK( a == ater );
}
boost::shared_ptr<A> abug = a->shared_from_this(); this throws bad_weak_ptr
}
Change History (6)
comment:1 by , 14 years ago
comment:2 by , 14 years ago
I don't know if you're aware of a patch that I've submitted to boost.python, that uses shared_ptr aliasing constructor to fix the problem.
http://mail.python.org/pipermail/cplusplus-sig/2008-December/014103.html
The patch has been integrated in boost.python svn trunk, but I doubt it has been released in boost 1.38.
comment:3 by , 14 years ago
Ah! I'm glad to hear it's in the trunk. I have integrated the patch into my 1.37 local installation, but ultimately I'd like to get back to using standard installs. Do you think the patch will be included in 1.39?
Thanks!
-dt
comment:4 by , 14 years ago
Milestone: | Boost 1.38.0 → Boost 1.39.0 |
---|---|
Status: | new → assigned |
This is a fairly major issue for my Boost.Python project. I'm currently using a patched 1.37 distribution, but I'd like to go back to a standard distribution for 1.39. Is this issue on the radar for that release?