diff options
author | Miss Islington (bot) <31488909+miss-islington@users.noreply.github.com> | 2020-05-28 15:12:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-28 15:12:23 (GMT) |
commit | bcbe5c59dde5fcb9ad21991c2afd91837b14bbd5 (patch) | |
tree | 9952d8e5d30daad42d284486a79c89705d0a34e7 /Doc/c-api | |
parent | 1d82f003678816ff8dd822452ec91669844d2d09 (diff) | |
download | cpython-bcbe5c59dde5fcb9ad21991c2afd91837b14bbd5.zip cpython-bcbe5c59dde5fcb9ad21991c2afd91837b14bbd5.tar.gz cpython-bcbe5c59dde5fcb9ad21991c2afd91837b14bbd5.tar.bz2 |
bpo-40217: Ensure Py_VISIT(Py_TYPE(self)) is always called for PyType_FromSpec types (reverts GH-19414) (GH-20264)
Heap types now always visit the type in tp_traverse. See added docs for details.
This reverts commit 0169d3003be3d072751dd14a5c84748ab63a249f.
Automerge-Triggered-By: @encukou
(cherry picked from commit 1cf15af9a6f28750f37b08c028ada31d38e818dd)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
Diffstat (limited to 'Doc/c-api')
-rw-r--r-- | Doc/c-api/typeobj.rst | 16 |
1 files changed, 15 insertions, 1 deletions
diff --git a/Doc/c-api/typeobj.rst b/Doc/c-api/typeobj.rst index ce4e8c9..385c7f9 100644 --- a/Doc/c-api/typeobj.rst +++ b/Doc/c-api/typeobj.rst @@ -1223,11 +1223,25 @@ and :c:type:`PyType_Type` effectively act as defaults.) but the instance has no strong reference to the elements inside it, as they are allowed to be removed even if the instance is still alive). - Note that :c:func:`Py_VISIT` requires the *visit* and *arg* parameters to :c:func:`local_traverse` to have these specific names; don't name them just anything. + Heap-allocated types (:const:`Py_TPFLAGS_HEAPTYPE`, such as those created + with :c:func:`PyType_FromSpec` and similar APIs) hold a reference to their + type. Their traversal function must therefore either visit + :c:func:`Py_TYPE(self) <Py_TYPE>`, or delegate this responsibility by + calling ``tp_traverse`` of another heap-allocated type (such as a + heap-allocated superclass). + If they do not, the type object may not be garbage-collected. + + .. versionchanged:: 3.9 + + Heap-allocated types are expected to visit ``Py_TYPE(self)`` in + ``tp_traverse``. In earlier versions of Python, due to + `bug 40217 <https://bugs.python.org/issue40217>`_, doing this + may lead to crashes in subclasses. + **Inheritance:** Group: :const:`Py_TPFLAGS_HAVE_GC`, :attr:`tp_traverse`, :attr:`tp_clear` |