[C++-sig] how to handle bare references with a shared_ptr HeldType

David Abrahams dave at boost-consulting.com
Tue Nov 1 17:52:44 CET 2005


Hans Meine <hans_meine at gmx.net> writes:

> On Saturday 24 September 2005 00:38, David Abrahams wrote:
>> Hans Meine <meine at kogs1.informatik.uni-hamburg.de> writes:
>> > OTOH, if you use return_internal_reference, BP should know that creating
>> > a shared_ptr with a refcount of 1 is evil..  is that really what it does?
>>
>> No, that's not what it does.  When you use return_internal_reference
>> it creates a Python object holding the C++ object with a raw pointer.
>> Isn't that in the documentation?
>
> That's how I understood it in the past, but I am not experienced with 
> customized HeldTypes, and Gregory seemed to be concerned that it does so:
>
>> > On Thursday 22 September 2005 16:37, Gregory Price wrote:
>> >> Is there a way to tell Boost.Python not to make a shared_ptr
>> >> for this return value -- to override the HeldType just for this
>> >> function's return value?
>
> So the answer really is: Use return_internal_reference.
>
> Concerning the documentation question:  The class_ documentation reads 
> "Heldtype [...] Specifies the type which is actually embedded in a Python 
> object wrapping a T instance. More details below."
> So I would've assumed that every T wrapper actually contains a smart_ptr if 
> that's the HeldType.  One could then make more clear that it's not always the 
> case.

Clarified, thanks.

-- 
Dave Abrahams
Boost Consulting
www.boost-consulting.com




More information about the Cplusplus-sig mailing list