[docs] [issue16195] Difficult or impossible to figure out how garbage collector and weak references should interact for user-defined extension types

Jean-Paul Calderone report at bugs.python.org
Thu Oct 11 15:10:21 CEST 2012


New submission from Jean-Paul Calderone:

There appears to be very little, if any, documentation about how to handle the list at tp_weaklistoffset for types supporting being weak referenced, particularly with respect to garbage collection.

Who owns the list?  Who owns the objects in the list?  Should the list be traversed by the extension type's tp_traverse?  Should it ever be INCREF'd or DECREF'd?  Does tp_dealloc have any responsibilities with respect to it?

>From looking at CPython's own source, it appears that tp_traverse should not touch it (Yhg1s confirmed this on #python).  Cython, at least, appears to have come to an alternate conclusion though - it generates tp_traverse functions which visit the list (and provoke gc assertions to fail on Python 2.7 in debug mode).

Some documentation about what is correct to do would be excellent, and would make it easier to explain to Cython developers what they're doing wrong (or confirm that they're doing something right, in which case there are some more bugs to file against the CPython stdlib, since they do something different from Cython).

----------
assignee: docs at python
components: Documentation
messages: 172639
nosy: docs at python, exarkun
priority: normal
severity: normal
status: open
title: Difficult or impossible to figure out how garbage collector and weak references should interact for user-defined extension types

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


More information about the docs mailing list