[Python-Dev] Bizarre new test failure

Martin v. Loewis martin@v.loewis.de
09 Jun 2002 22:56:00 +0200


Guido van Rossum <guido@python.org> writes:

> When tp_dict is cleared, this can remove the __del__ method before it
> can be called (it is called by the instance's tp_dealloc).  

That cannot happen: an object whose type has an __del__ cannot refer
to an object for which tp_clear has been called. Objects with
finalizers go into gc.garbage, so in this case, the type is
resurrected, and not cleared.

> tp_mro participates in a cycle too: it is a tuple whose first element
> is the type itself.  Tuples are immutable, so the tp_clear for tuples
> doesn't do anything.  So type_clear is our only hope to break this
> cycle.

I see. So tp_mro must be cleared in tp_clear; it's not used from
subtype_dealloc, so it won't cause problems to clear it.

Regards,
Martin