From 0d5ae9b32e1aa40f49e37624228ba77125da2410 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 8 May 2024 19:44:03 +0000 Subject: [PATCH 1/4] gh-118789: Restore hidden `_PyWeakref_ClearRef` _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 | 2 ++ Include/internal/pycore_weakref.h | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/Include/cpython/weakrefobject.h b/Include/cpython/weakrefobject.h index 9a796098c6b48f..1053e4ad285a91 100644 --- a/Include/cpython/weakrefobject.h +++ b/Include/cpython/weakrefobject.h @@ -59,3 +59,5 @@ Py_DEPRECATED(3.13) static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_o return Py_None; } #define PyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref)) + +PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self); diff --git a/Include/internal/pycore_weakref.h b/Include/internal/pycore_weakref.h index e057a27340f718..f834210dcc22eb 100644 --- a/Include/internal/pycore_weakref.h +++ b/Include/internal/pycore_weakref.h @@ -109,9 +109,7 @@ extern Py_ssize_t _PyWeakref_GetWeakrefCount(PyObject *obj); // Clear all the weak references to obj but leave their callbacks uncalled and // intact. -extern void _PyWeakref_ClearWeakRefsExceptCallbacks(PyObject *obj); - -extern void _PyWeakref_ClearRef(PyWeakReference *self); +PyAPI_FUNC(void) _PyWeakref_ClearWeakRefsExceptCallbacks(PyObject *obj); PyAPI_FUNC(int) _PyWeakref_IsDead(PyObject *weakref); From 1cd8d00a45859245eee45eea9119009a5465a074 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 8 May 2024 20:13:06 +0000 Subject: [PATCH 2/4] Blurb --- .../next/C API/2024-05-08-20-13-00.gh-issue-118789.m88uUa.rst | 2 ++ 1 file changed, 2 insertions(+) create mode 100644 Misc/NEWS.d/next/C API/2024-05-08-20-13-00.gh-issue-118789.m88uUa.rst 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 index 00000000000000..a2acc16b2c1d01 --- /dev/null +++ b/Misc/NEWS.d/next/C API/2024-05-08-20-13-00.gh-issue-118789.m88uUa.rst @@ -0,0 +1,2 @@ +Restore ``_PyWeakref_ClearRef`` that was previously removed in Python 3.13 +alpha 1. From bad74c272ccd5eefd8b5f8b16732f640ff76dc8b Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Wed, 8 May 2024 21:53:49 +0000 Subject: [PATCH 3/4] Only address _PyWeakref_ClearRef in this PR --- Include/internal/pycore_weakref.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Include/internal/pycore_weakref.h b/Include/internal/pycore_weakref.h index f834210dcc22eb..cc6c7ff9a9b438 100644 --- a/Include/internal/pycore_weakref.h +++ b/Include/internal/pycore_weakref.h @@ -109,7 +109,7 @@ extern Py_ssize_t _PyWeakref_GetWeakrefCount(PyObject *obj); // Clear all the weak references to obj but leave their callbacks uncalled and // intact. -PyAPI_FUNC(void) _PyWeakref_ClearWeakRefsExceptCallbacks(PyObject *obj); +extern void _PyWeakref_ClearWeakRefsExceptCallbacks(PyObject *obj); PyAPI_FUNC(int) _PyWeakref_IsDead(PyObject *weakref); From 35a62afabe1b626798cb117f5ae4de97a8bb0053 Mon Sep 17 00:00:00 2001 From: Sam Gross Date: Thu, 9 May 2024 15:06:22 +0000 Subject: [PATCH 4/4] Move definition up to match 3.12 --- Include/cpython/weakrefobject.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Include/cpython/weakrefobject.h b/Include/cpython/weakrefobject.h index 1053e4ad285a91..dcca166d7357cc 100644 --- a/Include/cpython/weakrefobject.h +++ b/Include/cpython/weakrefobject.h @@ -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; @@ -59,5 +61,3 @@ Py_DEPRECATED(3.13) static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_o return Py_None; } #define PyWeakref_GET_OBJECT(ref) PyWeakref_GET_OBJECT(_PyObject_CAST(ref)) - -PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self); pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy