]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-121794: Don't set `ob_tid` to zero in fast-path dealloc (#121799)
authorSam Gross <colesbury@gmail.com>
Mon, 15 Jul 2024 21:50:10 +0000 (17:50 -0400)
committerGitHub <noreply@github.com>
Mon, 15 Jul 2024 21:50:10 +0000 (17:50 -0400)
commitd23be3947ced081914f4458c84f729c9c37f0219
tree6e4866f6c0bb0161a918566642fe37a0520da968
parent82a4dac9f6131954c32dac9d0277283fc5b499a9
gh-121794: Don't set `ob_tid` to zero in fast-path dealloc (#121799)

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.
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