summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-18 14:54:51 (GMT)
committerGitHub <noreply@github.com>2024-06-18 14:54:51 (GMT)
commit1ce59849610fe03beebcddfacb3d055a7074ef16 (patch)
tree1000c3c2e89c99a3a77dd19fa640f2ebc4998cc1 /Include
parent4f4973d740839757e888c854a1994a64cb900d7b (diff)
downloadcpython-1ce59849610fe03beebcddfacb3d055a7074ef16.zip
cpython-1ce59849610fe03beebcddfacb3d055a7074ef16.tar.gz
cpython-1ce59849610fe03beebcddfacb3d055a7074ef16.tar.bz2
[3.13] gh-118789: Add `PyUnstable_Object_ClearWeakRefsNoCallbacks` (GH-118807) (#120695)
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. (cherry picked from commit e8752d7b80775ec2a348cd4bf38cbe26a4a07615) Co-authored-by: Sam Gross <colesbury@gmail.com> Co-authored-by: Petr Viktorin <encukou@gmail.com>
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/object.h2
-rw-r--r--Include/internal/pycore_weakref.h2
2 files changed, 3 insertions, 1 deletions
diff --git a/Include/cpython/object.h b/Include/cpython/object.h
index e624326..6cb2c40 100644
--- a/Include/cpython/object.h
+++ b/Include/cpython/object.h
@@ -288,6 +288,8 @@ PyAPI_FUNC(PyObject **) _PyObject_GetDictPtr(PyObject *);
PyAPI_FUNC(void) PyObject_CallFinalizer(PyObject *);
PyAPI_FUNC(int) PyObject_CallFinalizerFromDealloc(PyObject *);
+PyAPI_FUNC(void) PyUnstable_Object_ClearWeakRefsNoCallbacks(PyObject *);
+
/* Same as PyObject_Generic{Get,Set}Attr, but passing the attributes
dict as the last parameter. */
PyAPI_FUNC(PyObject *)
diff --git a/Include/internal/pycore_weakref.h b/Include/internal/pycore_weakref.h
index cc6c7ff..94aadb2 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.
-extern void _PyWeakref_ClearWeakRefsExceptCallbacks(PyObject *obj);
+extern void _PyWeakref_ClearWeakRefsNoCallbacks(PyObject *obj);
PyAPI_FUNC(int) _PyWeakref_IsDead(PyObject *weakref);