Skip to content

Commit 4fd7ed6

Browse files
committed
pythongh-111506: Implement Py_REFCNT() as opaque function call
In the limited C API version 3.13, the Py_REFCNT() function is now implemented as an opaque function call.
1 parent 268415b commit 4fd7ed6

File tree

3 files changed

+17
-1
lines changed

3 files changed

+17
-1
lines changed

Include/object.h

+7-1
Original file line numberDiff line numberDiff line change
@@ -290,8 +290,14 @@ _Py_IsOwnedByCurrentThread(PyObject *ob)
290290
}
291291
#endif
292292

293+
PyAPI_FUNC(Py_ssize_t) _Py_GetRefcnt(PyObject *ob);
294+
293295
static inline Py_ssize_t Py_REFCNT(PyObject *ob) {
294-
#if !defined(Py_GIL_DISABLED)
296+
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030d0000
297+
// Stable ABI implements Py_SET_REFCNT() as a function call
298+
// on limited C API version 3.13 and newer.
299+
return _Py_GetRefcnt(ob);
300+
#elif !defined(Py_GIL_DISABLED)
295301
return ob->ob_refcnt;
296302
#else
297303
uint32_t local = _Py_atomic_load_uint32_relaxed(&ob->ob_ref_local);
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
In the limited C API version 3.13, the :c:func:`Py_REFCNT` function is now
2+
implemented as an opaque function call. Patch by Victor Stinner.

Objects/object.c

+8
Original file line numberDiff line numberDiff line change
@@ -2932,6 +2932,14 @@ int Py_IsFalse(PyObject *x)
29322932
}
29332933

29342934

2935+
// Py_REFCNT() implementation for stable ABI
2936+
Py_ssize_t
2937+
_Py_GetRefcnt(PyObject *ob)
2938+
{
2939+
return Py_REFCNT(ob);
2940+
}
2941+
2942+
29352943
// Py_SET_REFCNT() implementation for stable ABI
29362944
void
29372945
_Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)

0 commit comments

Comments
 (0)