Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork33.7k
Closed
Labels
Description
In the limited C API 3.14 and newer, I propose to change Py_REFCNT() implementation to an opaque function call to hide implementation details. I made a similar change for Py_INCREF() and Py_DECREF() in Python 3.12.
The problem is that with Free Threading (PEP 703), the implementation of this functions becomes less trivial than just getting the object memberPyObject.ob_refcnt:
staticinlinePy_ssize_t_Py_REFCNT(PyObject*ob) {uint32_tlocal=_Py_atomic_load_uint32_relaxed(&ob->ob_ref_local);if (local==_Py_IMMORTAL_REFCNT_LOCAL) {return_Py_IMMORTAL_REFCNT; }Py_ssize_tshared=_Py_atomic_load_ssize_relaxed(&ob->ob_ref_shared);return_Py_STATIC_CAST(Py_ssize_t,local)+Py_ARITHMETIC_RIGHT_SHIFT(Py_ssize_t,shared,_Py_REF_SHARED_SHIFT);}
_Py_atomic_load_uint32_relaxed() and_Py_atomic_load_ssize_relaxed() must now be called. But I would prefer to not "leak" such implementation detail into the limited C API.
cc@colesbury@Fidget-Spinner@encukou