I wrote to this list a few weeks ago asking about Py_TPFLAGS_HEAPTYPE
(http://thread.gmane.org/gmane.comp.python.devel/105648). It occurred
to me today that I could probably make object instances INCREF and
DECREF my type appropriately, without setting Py_TPFLAGS_HEAPTYPE, by
writing my own tp_alloc and tp_dealloc functions. My tp_alloc function
could be:
PyObject *my_tp_alloc(PyTypeObject *type, Py_ssize_t nitems)
{
PyObject *obj = PyType_GenericAlloc(type, nitems);
if(obj) Py_INCREF(type);
return obj;
}
This seems right since it is PyType_GenericAlloc that contains this
excerpt:
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
Py_INCREF(type);
I don't want to set Py_TPFLAGS_HEAPTYPE, but I want to get that
Py_INCREF(), so far so good.
But I couldn't find the corresponding Py_DECREF() in typeobject.c to
the above Py_INCREF(). Notably, object_dealloc() does not call
Py_DECREF(self->ob_type) if self->ob_type has the Py_TPFLAGS_HEAPTYPE
flag set.
So where does the Py_DECREF() for the above Py_INCREF() live? I
expected to find this code snippet somewhere, but couldn't:
if (type->tp_flags & Py_TPFLAGS_HEAPTYPE)
Py_DECREF(type);
Josh
_______________________________________________
Python-Dev mailing list
[email protected]
http://mail.python.org/mailman/listinfo/python-dev
Unsubscribe:
http://mail.python.org/mailman/options/python-dev/archive%40mail-archive.com