[C++-sig] BPL and Py_Clear()

David Abrahams dave at boost-consulting.com
Sun Jun 12 18:05:45 CEST 2005


"Niall Douglas" <s_sourceforge at nedprod.com> writes:

> On 10 Jun 2005 at 13:08, David Abrahams wrote:
>
>> > How do you absolutely ensure a BPL wrapped object ceases to exist?
>> > In other words, if python code has ten references to a BPL wrapped
>> > object and I want that object to die immediately, therefore I would
>> > have to ensure either (a) the BPL wrapped object becomes a zombie or
>> > (b) each and every reference to that object is set to None.
>> >
>> > The latter sounds more appealing. I'm assuming I'd have to walk some
>> > table in Python?
>> 
>> There is no known mechanism for the latter.
>> 
>> The former is easy: make sure the object is held by auto_ptr<T>, and
>> pass the object to a function accepting an auto_ptr<T>.
>
> The latter could probably be made to work if given enough time, but 
> it would require a substantial amount of alterations to pyste to 
> achieve it - and even then, I still can see issues which may arise.
>
> Hence I must go the quick & dirty route. I was thinking of throwing a 
> dummy exception, reading the traceback & stack frame info and 
> recursing up through the globals() in each deleting any references to 
> my object. This would surely do it for the current interpreter at 
> least?

No, there may be references hiding in other pythong objects and, for
that matter, in extension modules.

I don't see what advantage you gain from it either.  A variable or
attribute in Python has to be bound to *something*, be it None or a
zombie (which will act almost like None) or whatever.  You'll reclaim
a small amount of memory, but that's about it.

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




More information about the Cplusplus-sig mailing list