Opened 14 years ago

Closed 14 years ago

#2584 closed Bugs (fixed)

boost::enable_shared_from_this + boost.python library

Reported by: Nicolas Lelong <nico_ml@…> 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 trotterdylan@…, 14 years ago

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?

comment:2 by nico_ml@…, 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 trotterdylan@…, 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 Peter Dimov, 14 years ago

Milestone: Boost 1.38.0Boost 1.39.0
Status: newassigned

comment:5 by Peter Dimov, 14 years ago

(In [51581]) Fix enable_shared_from_this-related tickets in trunk. Refs #2126. Refs #2584.

comment:6 by Peter Dimov, 14 years ago

Resolution: fixed
Status: assignedclosed

(In [51632]) Merge [51581] to release. Fixes #2126. Fixes #2584.

Note: See TracTickets for help on using tickets.