[Python-Dev] Re: C new-style classes and GC

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 tp_free value instead if so.
> The hairier type_new() function already has this extra level of
> Py_TPFLAGS_HAVE_GC-dependent magic for dynamically created types, setting
> tp_free to PyObject_Del in one case and to PyObject_GC_Del in the other.
> PyType_Ready() can supply a wrong deallocation function by default
> ("explicit is better than implicit" has no force when talking about
> PyType_Ready() <wink>).

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/)