[issue9141] Allow objects to decide if they can be collected by GC

Kristján Valur Jónsson report at bugs.python.org
Wed Apr 4 12:56:03 CEST 2012


Kristján Valur Jónsson <kristjan at ccpgames.com> added the comment:

I just noticed that PyTypeObjects have a gc slot already:
inquiry tp_is_gc; /* For PyObject_IS_GC */

Now, this is used in only one place in 2.7, for type objects:
return type->tp_flags & Py_TPFLAGS_HEAPTYPE;

This is thus used to dynamically query if an object was allocated with a GC header or not, since static types cannot have this.

Now, it would be perfectly possible to change the semantics of this function to return a bit flag, with bit 0 being the "has head" and bit 1 meaning "is collectable"

This might simplify some stuff.  Any thoughts?

----------

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue9141>
_______________________________________


More information about the Python-bugs-list mailing list