summaryrefslogtreecommitdiffstats
path: root/Include
diff options
context:
space:
mode:
authorSam Gross <colesbury@gmail.com>2024-12-19 15:17:15 (GMT)
committerGitHub <noreply@github.com>2024-12-19 15:17:15 (GMT)
commit7b811d0562a0bf7433165785f1549ac199610f8b (patch)
tree75314e9af7386a3e43f724a2ef9c9203699bcbbe /Include
parentb9b3e4a076caddf7876d1d4d762a117a26faffcf (diff)
downloadcpython-7b811d0562a0bf7433165785f1549ac199610f8b.zip
cpython-7b811d0562a0bf7433165785f1549ac199610f8b.tar.gz
cpython-7b811d0562a0bf7433165785f1549ac199610f8b.tar.bz2
gh-128008: Add `PyWeakref_IsDead()` (GH-128009)
The `PyWeakref_IsDead()` function tests if a weak reference is dead without any side effects. Although you can also detect if a weak reference is dead using `PyWeakref_GetRef()`, that function returns a strong reference that must be `Py_DECREF()`'d, which can introduce side effects if the last reference is concurrently dropped (at least in the free threading build).
Diffstat (limited to 'Include')
-rw-r--r--Include/cpython/weakrefobject.h3
1 files changed, 3 insertions, 0 deletions
diff --git a/Include/cpython/weakrefobject.h b/Include/cpython/weakrefobject.h
index 9aa1a92..da8e77c 100644
--- a/Include/cpython/weakrefobject.h
+++ b/Include/cpython/weakrefobject.h
@@ -45,6 +45,9 @@ PyAPI_FUNC(void) _PyWeakref_ClearRef(PyWeakReference *self);
#define _PyWeakref_CAST(op) \
(assert(PyWeakref_Check(op)), _Py_CAST(PyWeakReference*, (op)))
+// Test if a weak reference is dead.
+PyAPI_FUNC(int) PyWeakref_IsDead(PyObject *ref);
+
Py_DEPRECATED(3.13) static inline PyObject* PyWeakref_GET_OBJECT(PyObject *ref_obj)
{
PyWeakReference *ref = _PyWeakref_CAST(ref_obj);