]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-127582: Make object resurrection thread-safe for free threading. (GH-127612)
authorSam Gross <colesbury@gmail.com>
Thu, 5 Dec 2024 21:07:31 +0000 (21:07 +0000)
committerGitHub <noreply@github.com>
Thu, 5 Dec 2024 21:07:31 +0000 (16:07 -0500)
commitf4f530804b9d8f089eba0f157ec2144c03b13651
treece40d723b8c991d786924c16dd04dfa96ff8689b
parent657d0e99aa8754372786120d6ec00c9d9970e775
gh-127582: Make object resurrection thread-safe for free threading. (GH-127612)

Objects may be temporarily "resurrected" in destructors when calling
finalizers or watcher callbacks. We previously undid the resurrection
by decrementing the reference count using `Py_SET_REFCNT`. This was not
thread-safe because other threads might be accessing the object
(modifying its reference count) if it was exposed by the finalizer,
watcher callback, or temporarily accessed by a racy dictionary or list
access.

This adds internal-only thread-safe functions for temporary object
resurrection during destructors.
Include/internal/pycore_object.h
Misc/NEWS.d/next/Core_and_Builtins/2024-12-05-19-25-00.gh-issue-127582.ogUY2a.rst [new file with mode: 0644]
Objects/codeobject.c
Objects/dictobject.c
Objects/funcobject.c
Objects/object.c