Subject: [Boost-bugs] [Boost C++ Libraries] #2584: boost::enable_shared_from_this + boost.python library
From: Boost C++ Libraries (noreply_at_[hidden])
Date: 2008-12-12 09:33:33
#2584: boost::enable_shared_from_this + boost.python library
--------------------------------------------------+-------------------------
Reporter: Nicolas Lelong <nico_ml_at_[hidden]> | Owner: pdimov
Type: Bugs | Status: new
Milestone: Boost 1.38.0 | Component: smart_ptr
Version: Boost 1.37.0 | Severity: Problem
Keywords: enable_shared_from_this |
--------------------------------------------------+-------------------------
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 {[[BR]]
class A : public boost::enable_shared_from_this<A>[[BR]]
{[[BR]]
public:[[BR]]
~A() {};[[BR]]
};[[BR]]
void my_deleter(void*)[[BR]]
{[[BR]]
}[[BR]]
};[[BR]]
BOOST_AUTO_TEST_CASE( test_enable_shared_from_this )[[BR]]
{[[BR]]
boost::shared_ptr<A> a( new A );[[BR]]
{[[BR]]
boost::shared_ptr<A> ater = [[BR]]
boost::shared_ptr<A>( a.get(), my_deleter );[[BR]]
// OP patch proposal:[[BR]]
// boost::shared_ptr<A> ater = [[BR]]
// boost::shared_ptr<A>( a.get(), my_deleter[[BR]]
// , boost::dont_enable_shared_from_this() );[[BR]]
BOOST_CHECK( a == ater );[[BR]]
}[[BR]]
boost::shared_ptr<A> abug = a->shared_from_this(); // this throws
bad_weak_ptr[[BR]]
}
-- Ticket URL: <https://svn.boost.org/trac/boost/ticket/2584> Boost C++ Libraries <http://www.boost.org/> Boost provides free peer-reviewed portable C++ source libraries.
This archive was generated by hypermail 2.1.7 : 2017-02-16 18:49:59 UTC