]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Note that tp_clear and m_clear are not always called (GH-27581)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Wed, 4 Aug 2021 18:23:41 +0000 (11:23 -0700)
committerGitHub <noreply@github.com>
Wed, 4 Aug 2021 18:23:41 +0000 (11:23 -0700)
(cherry picked from commit 10faada709561663d6b1f623d308ff45e3808cca)

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Doc/c-api/module.rst
Doc/c-api/typeobj.rst

index a2541afb685c30e2142cc728a6161a9b4c24f9da..94c8d9f981713f820eb502253d90e9eb4c080668 100644 (file)
@@ -221,6 +221,12 @@ or request "multi-phase initialization" by returning the definition struct itsel
       than 0 and the module state (as returned by :c:func:`PyModule_GetState`)
       is ``NULL``.
 
+      Like :c:member:`PyTypeObject.tp_clear`, this function is not *always*
+      called before a module is deallocated. For example, when reference
+      counting is enough to determine that an object is no longer used,
+      the cyclic garbage collector is not involved and
+      :c:member:`~PyModuleDef.m_free` is called directly.
+
       .. versionchanged:: 3.9
          No longer called before the module state is allocated.
 
index 5fda9b086c00629bfa0c6bf04eae5234c0d51232..7ef081a13a6e18e9084376fe5c25cf2edd09a6f6 100644 (file)
@@ -1380,6 +1380,12 @@ and :c:type:`PyType_Type` effectively act as defaults.)
    so that *self* knows the contained object can no longer be used.  The
    :c:func:`Py_CLEAR` macro performs the operations in a safe order.
 
+   Note that :c:member:`~PyTypeObject.tp_clear` is not *always* called
+   before an instance is deallocated. For example, when reference counting
+   is enough to determine that an object is no longer used, the cyclic garbage
+   collector is not involved and :c:member:`~PyTypeObject.tp_dealloc` is
+   called directly.
+
    Because the goal of :c:member:`~PyTypeObject.tp_clear` functions is to break reference cycles,
    it's not necessary to clear contained objects like Python strings or Python
    integers, which can't participate in reference cycles. On the other hand, it may