]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-145921: Add "_DuringGC" functions for tp_traverse (GH-145925)
authorPetr Viktorin <encukou@gmail.com>
Wed, 8 Apr 2026 07:15:11 +0000 (09:15 +0200)
committerGitHub <noreply@github.com>
Wed, 8 Apr 2026 07:15:11 +0000 (09:15 +0200)
commit8923ca418cef1d07cd79ab810d12a24f7817dd89
tree4a5adfe06f59f486f2816816d89247f9613fc262
parent0b20bff386141ee0e8c62da8366f674bad17e048
gh-145921: Add "_DuringGC" functions for tp_traverse (GH-145925)

There are newly documented restrictions on tp_traverse:

    The traversal function must not have any side effects.
    It must not modify the reference counts of any Python
    objects nor create or destroy any Python objects.

* Add several functions that are guaranteed side-effect-free,
  with a _DuringGC suffix.
* Use these in ctypes
* Consolidate tp_traverse docs in gcsupport.rst, moving unique
  content from typeobj.rst there

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Co-authored-by: Victor Stinner <vstinner@python.org>
22 files changed:
Doc/c-api/gcsupport.rst
Doc/c-api/typeobj.rst
Doc/data/refcounts.dat
Doc/data/stable_abi.dat
Doc/whatsnew/3.15.rst
Include/cpython/object.h
Include/internal/pycore_moduleobject.h
Include/moduleobject.h
Include/object.h
Lib/test/test_stable_abi_ctypes.py
Misc/NEWS.d/next/C_API/2026-03-13-16-37-54.gh-issue-145921.ssA7HZ.rst [new file with mode: 0644]
Misc/stable_abi.toml
Modules/_ctypes/_ctypes.c
Modules/_ctypes/ctypes.h
Modules/_testcapi/heaptype.c
Modules/_testcapi/module.c
Modules/_testlimitedcapi/heaptype_relative.c
Modules/_testmultiphase.c
Modules/_testsinglephase.c
Objects/moduleobject.c
Objects/typeobject.c
PC/python3dll.c