[Python-Dev] Re: C new-style classes and GC (original) (raw)

Guido van Rossum guido@python.org
Sun, 18 May 2003 16:39:30 -0400


Guido, would you be agreeable to making this magic even more magical? It seems to me that we can know whether the current type intends to participate in cyclic gc, and give it a correct default tpfree value instead if so. The hairier typenew() function already has this extra level of PyTPFLAGSHAVEGC-dependent magic for dynamically created types, setting tpfree to PyObjectDel in one case and to PyObjectGCDel in the other. PyTypeReady() can supply a wrong deallocation function by default ("explicit is better than implicit" has no force when talking about PyTypeReady() ).

Yes, I think this is the right thing to do -- either only inherit tp_free when the GC bit of the base and derived class are the same, or -- in addition -- special case inheriting PyObject_Del and turn it into PyObject_GC_Del when the base class adds the GC bit.

--Guido van Rossum (home page: http://www.python.org/~guido/)