]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
[3.13] gh-127582: Make object resurrection thread-safe for free threading. (GH-127612...
authorSam Gross <colesbury@gmail.com>
Thu, 5 Dec 2024 23:49:33 +0000 (23:49 +0000)
committerGitHub <noreply@github.com>
Thu, 5 Dec 2024 23:49:33 +0000 (18:49 -0500)
commit69bb1c6c41c9840e4ae9537ff3e8e6eef718a0a8
tree75fd841e58796b7cf596f97f478c1c7133679665
parent304111e96741ff94c1970fe3f2ab9c804e78ecb8
[3.13] gh-127582: Make object resurrection thread-safe for free threading. (GH-127612) (GH-127659)

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.
(cherry picked from commit f4f530804b9d8f089eba0f157ec2144c03b13651)
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