diff options
author | Pablo Galindo <Pablogsal@gmail.com> | 2020-05-27 10:03:38 +0100 |
---|---|---|
committer | GitHub <noreply@github.com> | 2020-05-27 02:03:38 -0700 |
commit | 1cf15af9a6f28750f37b08c028ada31d38e818dd (patch) | |
tree | 19918a3d6cc25f3f2bcd14687be59c8926825020 /Doc/whatsnew/3.9.rst | |
parent | 404b23b85b17c84e022779f31fc89cb0ed0d37e8 (diff) | |
download | cpython-git-1cf15af9a6f28750f37b08c028ada31d38e818dd.tar.gz |
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
Diffstat (limited to 'Doc/whatsnew/3.9.rst')
-rw-r--r-- | Doc/whatsnew/3.9.rst | 49 |
1 files changed, 49 insertions, 0 deletions
diff --git a/Doc/whatsnew/3.9.rst b/Doc/whatsnew/3.9.rst index d72fea2c67..8a04f72513 100644 --- a/Doc/whatsnew/3.9.rst +++ b/Doc/whatsnew/3.9.rst @@ -933,6 +933,55 @@ Changes in the Python API (Contributed by Inada Naoki in :issue:`34538`.) +Changes in the C API +-------------------- + +* Instances of heap-allocated types (such as those created with + :c:func:`PyType_FromSpec` and similar APIs) hold a reference to their type + object since Python 3.8. As indicated in the "Changes in the C API" of Python + 3.8, for the vast majority of cases, there should be no side effect but for + types that have a custom :c:member:`~PyTypeObject.tp_traverse` function, + ensure that all custom ``tp_traverse`` functions of heap-allocated types + visit the object's type. + + Example: + + .. code-block:: c + + int + foo_traverse(foo_struct *self, visitproc visit, void *arg) { + // Rest of the traverse function + #if PY_VERSION_HEX >= 0x03090000 + // This was not needed before Python 3.9 (Python issue 35810 and 40217) + Py_VISIT(Py_TYPE(self)); + #endif + } + + If your traverse function delegates to ``tp_traverse`` of its base class + (or another type), ensure that ``Py_TYPE(self)`` is visited only once. + Note that only heap types are expected to visit the type in ``tp_traverse``. + + For example, if your ``tp_traverse`` function includes: + + .. code-block:: c + + base->tp_traverse(self, visit, arg) + + then add: + + .. code-block:: c + + #if PY_VERSION_HEX >= 0x03090000 + // This was not needed before Python 3.9 (Python issue 35810 and 40217) + if (base->tp_flags & Py_TPFLAGS_HEAPTYPE) { + // a heap type's tp_traverse already visited Py_TYPE(self) + } else { + Py_VISIT(Py_TYPE(self)); + } + #else + + (See :issue:`35810` and :issue:`40217` for more information.) + CPython bytecode changes ------------------------ |