Skip to content

Commit 92a9087

Browse files
committed
bpo-38206: Clarify tp_dealloc requirements for heap allocated types.
1 parent b9877cd commit 92a9087

File tree

2 files changed

+8
-3
lines changed

2 files changed

+8
-3
lines changed

Doc/c-api/type.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ The following functions and structs are used to create
118118
119119
.. c:function:: PyObject* PyType_FromSpecWithBases(PyType_Spec *spec, PyObject *bases)
120120
121-
Creates and returns a heap type object from the *spec*.
121+
Creates and returns a heap type object from the *spec*
122+
(:const:`Py_TPFLAGS_HEAPTYPE`).
122123
123124
If *bases* is a tuple, the created heap type contains all types contained
124125
in it as base types.

Doc/c-api/typeobj.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -654,8 +654,8 @@ and :c:type:`PyType_Type` effectively act as defaults.)
654654
the instance is still in existence, but there are no references to it. The
655655
destructor function should free all references which the instance owns, free all
656656
memory buffers owned by the instance (using the freeing function corresponding
657-
to the allocation function used to allocate the buffer), and finally (as its
658-
last action) call the type's :c:member:`~PyTypeObject.tp_free` function. If the type is not
657+
to the allocation function used to allocate the buffer), and then call the
658+
type's :c:member:`~PyTypeObject.tp_free` function. If the type is not
659659
subtypable (doesn't have the :const:`Py_TPFLAGS_BASETYPE` flag bit set), it is
660660
permissible to call the object deallocator directly instead of via
661661
:c:member:`~PyTypeObject.tp_free`. The object deallocator should be the one used to allocate the
@@ -664,6 +664,10 @@ and :c:type:`PyType_Type` effectively act as defaults.)
664664
:c:func:`PyObject_GC_Del` if the instance was allocated using
665665
:c:func:`PyObject_GC_New` or :c:func:`PyObject_GC_NewVar`.
666666

667+
Finally, if the type is heap allocated (:const:`Py_TPFLAGS_HEAPTYPE` or
668+
built with :c:func:`PyType_FromSpec`), the deallocator should decrement the
669+
reference count for its type object.
670+
667671
**Inheritance:**
668672

669673
This field is inherited by subtypes.

0 commit comments

Comments
 (0)