[C++-sig] Shared_ptr created by python wrapper doesn't know about the python reference?

Peter Dimov pdimov at gmail.com
Fri May 13 20:12:23 CEST 2005


David Abrahams wrote:
> "Peter Dimov" <pdimov at gmail.com> writes:
>
>> David Abrahams wrote:
>>
>>> Peter: it would be interesting if there was a way to get ahold of
>>> the weak_ptr management stuff in the deleter of the outer
>>> shared_ptr, so that when (*) is destroyed its weak_ptrs could be
>>> re-seated to work on (**)... am I making any sense?
>>
>> I don't think that this would be possible. Weak_ptr instances cannot
>> be reseated since they can't be enumerated.
>
> I guess if you expanded the deleter's control block you could add a
> fallback method for the weak_ptr's conversion to shared_ptr... (?)
>
> I'm sure this is outside the scope of the library, but it's fun to
> speculate ;-)

As long as we're just speculating, yes, it would be possible for lock() to 
ask the deleter when it sees use_count() == 0, I guess. This is an odd 
situation, though; if you can put the original shared_ptr in the deleter, 
you can also just return this shared_ptr instead of wrapping it. At least in 
pure C++ code, that is. :-) 






More information about the Cplusplus-sig mailing list