This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author colesbury
Recipients colesbury, docs@python
Date 2016-11-18.16:47:35
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1479487656.43.0.616591816842.issue28737@psf.upfronthosting.co.za>
In-reply-to
Content
In general, an a PyTypeObject that has Py_TPFLAGS_HAVE_GC set must call PyObject_GC_UnTrack() before it frees any PyObject* references it owns. The only reference to this requirement I found is in https://docs.python.org/3/c-api/gcsupport.html#c._PyObject_GC_TRACK.

This requirement should be documented in:

1. https://docs.python.org/3/c-api/typeobj.html#c.PyTypeObject.tp_dealloc
2. https://docs.python.org/3/extending/newtypes.html

A call to PyObject_GC_UnTrack() should also be added to he official "noddy4" example. Currently, the example is incorrect and can crash if a referred-to object triggers a GC from it's destructor. See the following example which segfaults:

https://github.com/colesbury/noddy

It may be worthwhile to have _Py_Dealloc call PyObject_GC_UnTrack() if the PyTypeObject has Py_TPFLAGS_HAVE_GC set. Considering that the official Python extension example is missing the call, it seems likely that extension writers often forget to include it.
History
Date User Action Args
2016-11-18 16:47:36colesburysetrecipients: + colesbury, docs@python
2016-11-18 16:47:36colesburysetmessageid: <1479487656.43.0.616591816842.issue28737@psf.upfronthosting.co.za>
2016-11-18 16:47:36colesburylinkissue28737 messages
2016-11-18 16:47:35colesburycreate