]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-118789: Restore hidden `_PyWeakref_ClearRef` (#118797)
authorSam Gross <colesbury@gmail.com>
Fri, 10 May 2024 13:54:18 +0000 (09:54 -0400)
committerGitHub <noreply@github.com>
Fri, 10 May 2024 13:54:18 +0000 (15:54 +0200)
_PyWeakref_ClearRef was previously exposed in the public C-API, although
it begins with an underscore and is not documented. It's used by a few
C-API extensions. There is currently no alternative public API that can
replace its use.

_PyWeakref_ClearWeakRefsExceptCallbacks is the only thread-safe way to
use _PyWeakref_ClearRef in the free-threaded build. This exposes the C
symbol, but does not make the API public.

Include/cpython/weakrefobject.h
Include/internal/pycore_weakref.h
Misc/NEWS.d/next/C API/2024-05-08-20-13-00.gh-issue-118789.m88uUa.rst [new file with mode: 0644]

index 9a796098c6b48f07973bea2e2b82b4afc9795aae..dcca166d7357cc72383d3074f4fc8998479ae1a6 100644 (file)
@@ -40,6 +40,8 @@ struct _PyWeakReference {
 #endif
 };
 
+PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
+
 Py_DEPRECATED(3.13) static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_obj)
 {
     PyWeakReference *ref;
index e057a27340f71840ce772b565e22b6c0d6c99645..cc6c7ff9a9b4380a204394412abb3bd8a5b9a57f 100644 (file)
@@ -111,8 +111,6 @@ extern Py_ssize_t _PyWeakref_GetWeakrefCount(PyObject *obj);
 // intact.
 extern void _PyWeakref_ClearWeakRefsExceptCallbacks(PyObject *obj);
 
-extern void _PyWeakref_ClearRef(PyWeakReference *self);
-
 PyAPI_FUNC(int) _PyWeakref_IsDead(PyObject *weakref);
 
 #ifdef __cplusplus
diff --git a/Misc/NEWS.d/next/C API/2024-05-08-20-13-00.gh-issue-118789.m88uUa.rst b/Misc/NEWS.d/next/C API/2024-05-08-20-13-00.gh-issue-118789.m88uUa.rst
new file mode 100644 (file)
index 0000000..a2acc16
--- /dev/null
@@ -0,0 +1,2 @@
+Restore ``_PyWeakref_ClearRef`` that was previously removed in Python 3.13
+alpha 1.