Common path all PyObjects take on destruction?

Ryan Stutsman stutsman at cs.stanford.edu
Fri Jan 9 19:39:24 EST 2009


I've added a field to all PyObjects in the interpreter which is of type
PyObject*.  Most of the time this pointer is NULL but occassionally I
want to track some information in there.  The problem I'm running into
is that I can add a reference to a PyObject inside any of my PyObjects,
but it seems that there isn't any one path that all objects follow on
destruction so that I can later Py_DECREF that reference.

Eventually most of the types seem to call PyObject_Free, but this gets
called with void* and it seems it isn't always the case that PyObject*s
are passed in.

Where is the best place to implement something like this?  It really
won't work to implement this in the destructor of each of the individual
types because other types added later won't know to DECREF this field on
destruction.

Any hints would be appreciated.  Hopefully I'm just missing something
simple.



More information about the Python-list mailing list