]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
GH-135552: Make the GC clear weakrefs later (GH-136189)
authorNeil Schemenauer <nas-github@arctrix.com>
Thu, 7 Aug 2025 23:32:17 +0000 (16:32 -0700)
committerGitHub <noreply@github.com>
Thu, 7 Aug 2025 23:32:17 +0000 (16:32 -0700)
commit350c58ba4ee13019b0cde70b49bfeadc63f4ceb8
tree87e1f5a21688c74a83fc98a4be2d1ccb7d6a683d
parentdeb385a14337bc3e38442b4cee3aac4a57364adc
GH-135552: Make the GC clear weakrefs later (GH-136189)

Fix a bug caused by the garbage collector clearing weakrefs too early.  The
weakrefs in the ``tp_subclasses`` dictionary are needed in order to correctly
invalidate type caches (for example, by calling ``PyType_Modified()``).
Clearing weakrefs before calling finalizers causes the caches to not be
correctly invalidated.  That can cause crashes since the caches can refer to
invalid objects.  Defer the clearing of weakrefs without callbacks until after
finalizers are executed.
InternalDocs/garbage_collector.md
Lib/test/test_finalization.py
Lib/test/test_gc.py
Lib/test/test_io.py
Misc/NEWS.d/next/Core_and_Builtins/2025-07-03-06-04-42.gh-issue-135552.CbBQof.rst [new file with mode: 0644]
Modules/_datetimemodule.c
Modules/gc_weakref.txt
Python/gc.c
Python/gc_free_threading.c