diff options
author | Victor Stinner <vstinner@python.org> | 2023-11-03 17:18:57 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-11-03 17:18:57 (GMT) |
commit | 20cfab903db70cf952128bc6b606e3ec4a216498 (patch) | |
tree | dfed10d60f9b45ebc0cf52c2351859a328371e53 /Include/object.h | |
parent | e0afed7e276b6611a2142ec70a0440298d528305 (diff) | |
download | cpython-20cfab903db70cf952128bc6b606e3ec4a216498.zip cpython-20cfab903db70cf952128bc6b606e3ec4a216498.tar.gz cpython-20cfab903db70cf952128bc6b606e3ec4a216498.tar.bz2 |
gh-111506: Implement Py_SET_REFCNT() as opaque function in limited C API (#111508)
In the limited C API version 3.13, Py_SET_REFCNT() function is now
implemented as an opaque function call.
Add _Py_SetRefcnt() to the stable ABI.
Diffstat (limited to 'Include/object.h')
-rw-r--r-- | Include/object.h | 13 |
1 files changed, 11 insertions, 2 deletions
diff --git a/Include/object.h b/Include/object.h index 1c7d7f4..bdc07d9 100644 --- a/Include/object.h +++ b/Include/object.h @@ -327,7 +327,15 @@ static inline int Py_IS_TYPE(PyObject *ob, PyTypeObject *type) { #endif +// Py_SET_REFCNT() implementation for stable ABI +PyAPI_FUNC(void) _Py_SetRefcnt(PyObject *ob, Py_ssize_t refcnt); + static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { +#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. + _Py_SetRefcnt(ob, refcnt); +#else // This immortal check is for code that is unaware of immortal objects. // The runtime tracks these objects and we should avoid as much // as possible having extensions inadvertently change the refcnt @@ -335,7 +343,7 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { if (_Py_IsImmortal(ob)) { return; } -#if !defined(Py_NOGIL) +#ifndef Py_NOGIL ob->ob_refcnt = refcnt; #else if (_Py_IsOwnedByCurrentThread(ob)) { @@ -352,7 +360,8 @@ static inline void Py_SET_REFCNT(PyObject *ob, Py_ssize_t refcnt) { ob->ob_ref_local = 0; ob->ob_ref_shared = _Py_REF_SHARED(refcnt, _Py_REF_MERGED); } -#endif +#endif // Py_NOGIL +#endif // Py_LIMITED_API+0 < 0x030d0000 } #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 < 0x030b0000 # define Py_SET_REFCNT(ob, refcnt) Py_SET_REFCNT(_PyObject_CAST(ob), (refcnt)) |