[C++-sig] application exit and shared_ptr

David Abrahams dave at boostpro.com
Wed Aug 6 17:03:13 CEST 2008


on Fri Aug 01 2008, "Philip Winston" <pwinston-AT-gmail.com> wrote:

> Thanks, wow so maybe we are wrong to use shared_ptr at all in our
> situation.  Does weak_ptr work as nicely with Boost.Python, 

No, there's no built-in support for weak_ptr.  It wouldn't be (too) hard
to add, though.

> because
> shared_ptr works great and that's why we were using it.   But weak_ptr
> semantics would be ideal.  The main C++ application needs to be in
> charge, no interpreter variable should be able to prevent something
> from being deleted.  Yet at the same time using a "stale" variable in
> Python can't crash the, it can throw but not crash everything.  Does
> weak_ptr with Boost.Python behave like this?  

No, weak_ptr isn't actually a ptr.  So here's the question: if we
implemented a holder-by-weak_ptr, what would the semantics be when the
object has been released and it is passed to a function accepting a
shared_ptr?  Specifically, should we throw or should we generate an
empty shared_ptr?  Note, if it's the latter, and your C++ code assumes a
valid pointee, it will crash.

-- 
Dave Abrahams
BoostPro Computing
http://www.boostpro.com



More information about the Cplusplus-sig mailing list