mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
bpo-28737: Document when tp_dealloc should call PyObject_GC_UnTrack() (GH-29246)
Objects that support garbage collection ("container" objects) should call PyObject_GC_UnTrack() from their destructors before clearing any fields which may point to other "container" objects.
This commit is contained in:
parent
4776b07d17
commit
35e1ff38ee
3 changed files with 33 additions and 9 deletions
|
@ -33,6 +33,14 @@ Constructors for container types must conform to two rules:
|
|||
#. Once all the fields which may contain references to other containers are
|
||||
initialized, it must call :c:func:`PyObject_GC_Track`.
|
||||
|
||||
Similarly, the deallocator for the object must conform to a similar pair of
|
||||
rules:
|
||||
|
||||
#. Before fields which refer to other containers are invalidated,
|
||||
:c:func:`PyObject_GC_UnTrack` must be called.
|
||||
|
||||
#. The object's memory must be deallocated using :c:func:`PyObject_GC_Del`.
|
||||
|
||||
.. warning::
|
||||
If a type adds the Py_TPFLAGS_HAVE_GC, then it *must* implement at least
|
||||
a :c:member:`~PyTypeObject.tp_traverse` handler or explicitly use one
|
||||
|
@ -100,14 +108,6 @@ Constructors for container types must conform to two rules:
|
|||
|
||||
.. versionadded:: 3.9
|
||||
|
||||
Similarly, the deallocator for the object must conform to a similar pair of
|
||||
rules:
|
||||
|
||||
#. Before fields which refer to other containers are invalidated,
|
||||
:c:func:`PyObject_GC_UnTrack` must be called.
|
||||
|
||||
#. The object's memory must be deallocated using :c:func:`PyObject_GC_Del`.
|
||||
|
||||
|
||||
.. c:function:: void PyObject_GC_Del(void *op)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue