]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-121794: Don't set `ob_tid` to zero in fast-path dealloc (GH-121799) (#121821)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Mon, 15 Jul 2024 22:15:23 +0000 (00:15 +0200)
committerGitHub <noreply@github.com>
Mon, 15 Jul 2024 22:15:23 +0000 (22:15 +0000)
commit0794220a6935a25bd9667be60b0c67403bc73f47
treeabfbf472fe853d9c1ac9ecec8ec831c4d54ae1c7
parent6396c77571aee99386a7b5a5863bbe0b8c5df4b1
[3.13] gh-121794: Don't set `ob_tid` to zero in fast-path dealloc (GH-121799) (#121821)

We should maintain the invariant that a zero `ob_tid` implies the
refcount fields are merged.

* Move the assignment in `_Py_MergeZeroLocalRefcount` to immediately
  before the refcount merge.
* Update `_PyTrash_thread_destroy_chain` to set `ob_ref_shared` to
  `_Py_REF_MERGED` when setting `ob_tid` to zero.

Also check this invariant with assertions in the GC in debug builds.
That uncovered a bug when running out of memory during GC.
(cherry picked from commit d23be3947ced081914f4458c84f729c9c37f0219)

Co-authored-by: Sam Gross <colesbury@gmail.com>
Misc/NEWS.d/next/Core and Builtins/2024-07-15-16-26-32.gh-issue-121794.fhBtiQ.rst [new file with mode: 0644]
Objects/object.c
Python/gc_free_threading.c