[Python-Dev] Bizarre new test failure

Martin v. Loewis martin@v.loewis.de
09 Jun 2002 09:38:45 +0200


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

> I tried the simplest possible fix, which was to visit self->ob_type in
> the new-style instance tp_traverse handler (subtype_traverse() in
> typeobject.c).  But this caused assertions to fail all over the place.
> It turns out that when the collector decides to break a cycle like
> this, it calls the tp_clear handler for each object in the cycle, and
> then the subsequent deletion of the instance references the type in
> ways that have been made invalid by the clearing of the type.  So this
> was a dead end.

I'd like to question this statement. It ought to be possible, IMO, to
dealloc an instance whose type has been cleared.

The problem appears to be in the tp_clear. The task of tp_clear is to
clear all references that may participate in cycles (*not* to clear
all references per se). Now, if type_clear would clear tp_dict,
tp_subclasses, and et->slots, but leave alone tp_base, tp_bases, and
tp_mro, the type would still be "good enough" for subtype_dealloc, no?

Regards,
Martin