[Python-Dev] A little GC confusion

David Abrahams David Abrahams" <david.abrahams@rcn.com
Fri, 22 Feb 2002 07:34:23 -0500

----- Original Message -----
From: "Martin v. Loewis" <martin@v.loewis.de>
> "Jason Orendorff" <jason@jorendorff.com> writes:
> > I think David is asking about line 1404 of Objects/typeobject.c,
> > where it says that PyType_Type is Py_TPFLAGS_HAVE_GC.
> > How can it have GC when many instances are static objects, not
> > allocated with PyObject_GC_VarNew()?
> Because the type type implements tp_is_gc (typeobject.c:1378),
> declaring static type objects as not being gc. In turn, garbage
> collection will not attempt to look at the GC header of these type
> objects.

Aha! And the implementation is...

static int
type_is_gc(PyTypeObject *type)
    return type->tp_flags & Py_TPFLAGS_HEAPTYPE;

so, wouldn't it make more sense that the Python source always checks
Py_TPFLAGS_HEAPTYPE before tp_is_gc?

Also, is there any guideline for which type slots get automatically copied
from the base type? Since my slots are nearly all zero I expected to inherit
most of the slots from type_type.