]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
gh-118789: Add `PyUnstable_Object_ClearWeakRefsNoCallbacks` (#118807)
authorSam Gross <colesbury@gmail.com>
Tue, 18 Jun 2024 13:57:23 +0000 (09:57 -0400)
committerGitHub <noreply@github.com>
Tue, 18 Jun 2024 13:57:23 +0000 (09:57 -0400)
commite8752d7b80775ec2a348cd4bf38cbe26a4a07615
treeaf381ff07ef5c47aa18731fb03d5eb88452a3189
parent360f14a493d8461d42dc646be40b4b6fb20db57a
gh-118789: Add `PyUnstable_Object_ClearWeakRefsNoCallbacks` (#118807)

This exposes `PyUnstable_Object_ClearWeakRefsNoCallbacks` as an unstable
C-API function to provide a thread-safe mechanism for clearing weakrefs
without executing callbacks.

Some C-API extensions need to clear weakrefs without calling callbacks,
such as after running finalizers like we do in subtype_dealloc.
Previously they could use `_PyWeakref_ClearRef` on each weakref, but
that's not thread-safe in the free-threaded build.

Co-authored-by: Petr Viktorin <encukou@gmail.com>
Doc/c-api/weakref.rst
Include/cpython/object.h
Include/internal/pycore_weakref.h
Lib/test/test_capi/test_object.py
Misc/NEWS.d/next/C API/2024-05-08-21-57-50.gh-issue-118789.Ni4UQx.rst [new file with mode: 0644]
Modules/_testcapi/object.c
Objects/typeobject.c
Objects/weakrefobject.c