Skip to content

Commit

Permalink
pythongh-111506: Implement Py_REFCNT() as opaque function call
Browse files Browse the repository at this point in the history
In the limited C API version 3.13, the Py_REFCNT() function is now
implemented as an opaque function call.
  • Loading branch information
vstinner committed Dec 5, 2023
1 parent 268415b commit 4fd7ed6
Show file tree
Hide file tree
Showing 3 changed files with 17 additions and 1 deletion.
8 changes: 7 additions & 1 deletion Include/object.h
Original file line number Diff line number Diff line change
Expand Up @@ -290,8 +290,14 @@ _Py_IsOwnedByCurrentThread(PyObject *ob)
}
#endif

PyAPI_FUNC(Py_ssize_t) _Py_GetRefcnt(PyObject *ob);

static inline Py_ssize_t Py_REFCNT(PyObject *ob) {
#if !defined(Py_GIL_DISABLED)
#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 >= 0x030d0000
// Stable ABI implements Py_SET_REFCNT() as a function call
// on limited C API version 3.13 and newer.
return _Py_GetRefcnt(ob);
#elif !defined(Py_GIL_DISABLED)
return ob->ob_refcnt;
#else
uint32_t local = _Py_atomic_load_uint32_relaxed(&ob->ob_ref_local);
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
In the limited C API version 3.13, the :c:func:`Py_REFCNT` function is now
implemented as an opaque function call. Patch by Victor Stinner.
8 changes: 8 additions & 0 deletions Objects/object.c
Original file line number Diff line number Diff line change
Expand Up @@ -2932,6 +2932,14 @@ int Py_IsFalse(PyObject *x)
}


// Py_REFCNT() implementation for stable ABI
Py_ssize_t
_Py_GetRefcnt(PyObject *ob)
{
return Py_REFCNT(ob);
}


// Py_SET_REFCNT() implementation for stable ABI
void
_Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt)
Expand Down

0 comments on commit 4fd7ed6

Please sign in to comment.