]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-108634: Py_TRACE_REFS uses a hash table (#108663)
authorVictor Stinner <vstinner@python.org>
Thu, 31 Aug 2023 16:33:34 +0000 (18:33 +0200)
committerGitHub <noreply@github.com>
Thu, 31 Aug 2023 16:33:34 +0000 (18:33 +0200)
commit13a00078b81776b23b0b6add69b848382240d1f2
tree612a10a02aeb749d9c5bff72133b2ae1d25a5cc6
parent013a99a47b3299f48cf7f95aa451a116441b029c
gh-108634: Py_TRACE_REFS uses a hash table (#108663)

Python built with "configure --with-trace-refs" (tracing references)
is now ABI compatible with Python release build and debug build.
Moreover, it now also supports the Limited API.

Change Py_TRACE_REFS build:

* Remove _PyObject_EXTRA_INIT macro.
* The PyObject structure no longer has two extra members (_ob_prev
  and _ob_next).
* Use a hash table (_Py_hashtable_t) to trace references (all
  objects): PyInterpreterState.object_state.refchain.
* Py_TRACE_REFS build is now ABI compatible with release build and
  debug build.
* Limited C API extensions can now be built with Py_TRACE_REFS:
  xxlimited, xxlimited_35, _testclinic_limited.
* No longer rename PyModule_Create2() and PyModule_FromDefAndSpec2()
  functions to PyModule_Create2TraceRefs() and
  PyModule_FromDefAndSpec2TraceRefs().
* _Py_PrintReferenceAddresses() is now called before
  finalize_interp_delete() which deletes the refchain hash table.
* test_tracemalloc find_trace() now also filters by size to ignore
  the memory allocated by _PyRefchain_Trace().

Test changes for Py_TRACE_REFS:

* Add test.support.Py_TRACE_REFS constant.
* Add test_sys.test_getobjects() to test sys.getobjects() function.
* test_exceptions skips test_recursion_normalizing_with_no_memory()
  and test_memory_error_in_PyErr_PrintEx() if Python is built with
  Py_TRACE_REFS.
* test_repl skips test_no_memory().
* test_capi skisp test_set_nomemory().
31 files changed:
Doc/c-api/typeobj.rst
Doc/using/configure.rst
Doc/whatsnew/3.13.rst
Include/internal/pycore_object.h
Include/internal/pycore_object_state.h
Include/internal/pycore_runtime_init.h
Include/modsupport.h
Include/object.h
Include/pyport.h
Lib/test/support/__init__.py
Lib/test/test_capi/test_mem.py
Lib/test/test_exceptions.py
Lib/test/test_import/__init__.py
Lib/test/test_repl.py
Lib/test/test_sys.py
Lib/test/test_tracemalloc.py
Misc/NEWS.d/next/Build/2023-08-30-02-52-52.gh-issue-108634.3dpBvf.rst [new file with mode: 0644]
Misc/NEWS.d/next/C API/2023-08-30-02-54-06.gh-issue-108634.oV3Xzk.rst [new file with mode: 0644]
Misc/SpecialBuilds.txt
Modules/_testcapi/parts.h
Objects/object.c
Objects/setobject.c
Objects/sliceobject.c
Objects/structseq.c
Objects/typeobject.c
Python/bltinmodule.c
Python/hashtable.c
Python/pylifecycle.c
Python/pystate.c
configure
configure.ac