summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2021-08-04 18:23:41 (GMT)
committerGitHub <noreply@github.com>2021-08-04 18:23:41 (GMT)
commitf4b3217874743762c3e157979c0cd315853f18a9 (patch)
tree9fd281abb4c6cfdb6f01a702e1dccaa5d5ea3aba
parent40a863185ee53b7c9044d970dfa0207a971764c2 (diff)
downloadcpython-f4b3217874743762c3e157979c0cd315853f18a9.zip
cpython-f4b3217874743762c3e157979c0cd315853f18a9.tar.gz
cpython-f4b3217874743762c3e157979c0cd315853f18a9.tar.bz2
Note that tp_clear and m_clear are not always called (GH-27581)
(cherry picked from commit 10faada709561663d6b1f623d308ff45e3808cca) Co-authored-by: Petr Viktorin <encukou@gmail.com>
-rw-r--r--Doc/c-api/module.rst6
-rw-r--r--Doc/c-api/typeobj.rst6
2 files changed, 12 insertions, 0 deletions
diff --git a/Doc/c-api/module.rst b/Doc/c-api/module.rst
index a2541af..94c8d9f 100644
--- a/Doc/c-api/module.rst
+++ b/Doc/c-api/module.rst
@@ -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.
diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst
index 5fda9b0..7ef081a 100644
--- a/Doc/c-api/typeobj.rst
+++ b/Doc/c-api/typeobj.rst
@@ -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