Skip to content

gh-111506: Implement Py_REFCNT() as opaque function call #112747

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 2 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
1 change: 1 addition & 0 deletions Lib/test/test_stable_abi_ctypes.py

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

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.
3 changes: 3 additions & 0 deletions Misc/stable_abi.toml
Original file line number Diff line number Diff line change
Expand Up @@ -2478,6 +2478,9 @@
added = '3.13'
[function.PySys_AuditTuple]
added = '3.13'
[function._Py_GetRefcnt]
added = '3.13'
abi_only = true
[function._Py_SetRefcnt]
added = '3.13'
abi_only = true
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
1 change: 1 addition & 0 deletions PC/python3dll.c

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.