Boost logo

Boost :

Subject: Re: [boost] enable_shared_from_this2
From: Daniel F. (the.source_at_[hidden])
Date: 2010-03-09 18:32:04


You are right, I had my include paths jumbled up (it was including
headers from an older version of boost) - sorry about that. Also, thanks
for providing some insight on why the assertion fails. The object being
deleted before the name is bound (resulting in the assignment to the
external shared_ptr) sounds like a reasonable explanation. The code was
a bit of a contrived example anyways - and it is easy to fix:

temp = obj2.shared()
obj2 = temp

However, it does mean that as long as this issue exists, extra caution
is necessary. This behavior could be surprising to some users,
especially those coming from python.

Frank Mori Hess wrote:
> -----BEGIN PGP SIGNED MESSAGE-----
> Hash: SHA1
>
> On Sunday 07 March 2010, Daniel F. wrote:
>> I would also like to express my interest in a solution to the
>> enable_shared_from_this/python problem. In my opinion providing an
>> adequate solution would really benefit boost::python and I'm glad to see
>> work is being done. I've checked out the latest code from svn and played
>> around with it. I had to modify enable_shared_from_raw.hpp slightly in
>> order to get it to compile (mainly insert esft2_deleter_wrapper from the
>> old enable_shared_from_this2.hpp).
>
> What errors did you see? Can you provide a test program which shows the
> errors? The trunk works fine for me. esft2_deleter_wrapper is defined in
> shared_ptr.hpp right above get_deleter.
>
>> The results look good: the RuntimeError is gone, the objects are being
>> destroyed. Unfortunately, I only know little about the inner workings
>> smart pointers and even less about boost::python, so the before
>> mentioned code should be regarded with caution. So far, I've discovered
>> one case where this breaks, i.e. the following python code "obj2 =
>> obj2.shared()" causes the assertion in the destructor of
>> enable_shared_from_raw to fail. I'll assume that this is work in
>> progress (or really difficult to solve).
>
> I don't know anything about Boost.Python, but the assertion will fail if you
> create a shared_ptr with shared_from_raw() and then the object is destroyed
> before ever being given to an external shared_ptr. It's fine if the external
> shared_ptr has a null deleter, but you have to construct such a shared_ptr
> explicitly if that's what you want.
> -----BEGIN PGP SIGNATURE-----
> Version: GnuPG v1.4.9 (GNU/Linux)
>
> iEYEARECAAYFAkuWdy8ACgkQ5vihyNWuA4WkpgCggqvLM1ImFLmyYA+R7GqT+PDe
> L/MAoIA5IRf9vpV/39inCU5GJZ2+Yy0M
> =stxS
> -----END PGP SIGNATURE-----
> _______________________________________________
> Unsubscribe & other changes: http://lists.boost.org/mailman/listinfo.cgi/boost
>


Boost list run by bdawes at acm.org, gregod at cs.rpi.edu, cpdaniel at pacbell.net, john at johnmaddock.co.uk