Skip to content

Commit d880c83

Browse files
authored
Doc: C API: Move tp_dealloc paragraph to tp_dealloc section (#125737)
It looks like commit 43cf44d (gh-31501) accidentally moved the paragraph to the `tp_finalize` section when the intent was to move it to the `tp_dealloc` section (according to the commit message). Also: * Convert the paragraph to a warning. * Apply the appropriate font style to `tp_dealloc`. * Unlinkify the first mention of `tp_dealloc` since the paragraph is already in the `tp_dealloc` section.
1 parent d67bf2d commit d880c83

File tree

1 file changed

+13
-11
lines changed

1 file changed

+13
-11
lines changed

Doc/c-api/typeobj.rst

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -682,6 +682,19 @@ and :c:data:`PyType_Type` effectively act as defaults.)
682682
Py_DECREF(tp);
683683
}
684684
685+
.. warning::
686+
687+
In a garbage collected Python, :c:member:`!tp_dealloc` may be called from
688+
any Python thread, not just the thread which created the object (if the
689+
object becomes part of a refcount cycle, that cycle might be collected by
690+
a garbage collection on any thread). This is not a problem for Python
691+
API calls, since the thread on which :c:member:`!tp_dealloc` is called
692+
will own the Global Interpreter Lock (GIL). However, if the object being
693+
destroyed in turn destroys objects from some other C or C++ library, care
694+
should be taken to ensure that destroying those objects on the thread
695+
which called :c:member:`!tp_dealloc` will not violate any assumptions of
696+
the library.
697+
685698

686699
**Inheritance:**
687700

@@ -2109,17 +2122,6 @@ and :c:data:`PyType_Type` effectively act as defaults.)
21092122
PyErr_Restore(error_type, error_value, error_traceback);
21102123
}
21112124

2112-
Also, note that, in a garbage collected Python,
2113-
:c:member:`~PyTypeObject.tp_dealloc` may be called from
2114-
any Python thread, not just the thread which created the object (if the object
2115-
becomes part of a refcount cycle, that cycle might be collected by a garbage
2116-
collection on any thread). This is not a problem for Python API calls, since
2117-
the thread on which tp_dealloc is called will own the Global Interpreter Lock
2118-
(GIL). However, if the object being destroyed in turn destroys objects from some
2119-
other C or C++ library, care should be taken to ensure that destroying those
2120-
objects on the thread which called tp_dealloc will not violate any assumptions
2121-
of the library.
2122-
21232125
**Inheritance:**
21242126

21252127
This field is inherited by subtypes.

0 commit comments

Comments
 (0)