@@ -341,7 +341,7 @@ static inline PyFrameObject* PyThreadState_GetFrame(PyThreadState *tstate)
341341#endif
342342
343343#if ((!defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000) \
344- && !defined (PYPY_VERSION ))
344+ && ( !defined (PYPY_VERSION ) || PY_VERSION_HEX >= 0x030B0000 ))
345345static inline PyFrameObject*
346346_PyThreadState_GetFrameBorrow (PyThreadState *tstate)
347347{
@@ -432,7 +432,8 @@ static inline PyObject* PyObject_CallNoArgs(PyObject *func)
432432// bpo-39245 made PyObject_CallOneArg() public (previously called
433433// _PyObject_CallOneArg) in Python 3.9.0a4
434434// PyObject_CallOneArg() added to PyPy 3.9.16-v7.3.11
435- #if !defined(PyObject_CallOneArg) && PY_VERSION_HEX < 0x030900A4
435+ #if (!defined(PyObject_CallOneArg) \
436+ && (PY_VERSION_HEX < 0x030900A4 || defined (Py_LIMITED_API)))
436437static inline PyObject* PyObject_CallOneArg (PyObject *func, PyObject *arg)
437438{
438439 return PyObject_CallFunctionObjArgs (func, arg, NULL );
@@ -1076,6 +1077,7 @@ PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *str, Py_ssize_t str_
10761077#endif
10771078 {
10781079#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000
1080+ // Limited C API 3.9 and older
10791081 bytes = PyUnicode_AsUTF8String (unicode);
10801082 if (bytes == NULL ) {
10811083 // Memory allocation failure. The API cannot report error,
@@ -1086,7 +1088,8 @@ PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *str, Py_ssize_t str_
10861088 utf8 = PyBytes_AsString (bytes);
10871089 len = PyBytes_Size (bytes);
10881090#else
1089- // Python 3.10 added PyUnicode_AsUTF8AndSize() to the limited C API
1091+ // Python 3.12 and older, and limited C API 3.10 and newer.
1092+ // Python 3.10 added PyUnicode_AsUTF8AndSize() to the limited C API.
10901093 utf8 = PyUnicode_AsUTF8AndSize (unicode, &len);
10911094 if (utf8 == NULL ) {
10921095 // Memory allocation failure. The API cannot report error,
@@ -1297,10 +1300,11 @@ static inline int PyTime_PerfCounter(PyTime_t *result)
12971300
12981301// gh-111389 added hash constants to Python 3.13.0a5. These constants were
12991302// added first as private macros to Python 3.4.0b1 and PyPy 7.3.8.
1300- #if (!defined(PyHASH_BITS) \
1301- && ((!defined (PYPY_VERSION ) && PY_VERSION_HEX >= 0x030400B1 ) \
1302- || (defined (PYPY_VERSION ) && PY_VERSION_HEX >= 0x03070000 \
1303- && PYPY_VERSION_NUM >= 0x07030800 )))
1303+ #if ((!defined(PyHASH_BITS) \
1304+ && ((!defined (PYPY_VERSION ) && PY_VERSION_HEX >= 0x030400B1 ) \
1305+ || (defined (PYPY_VERSION ) && PY_VERSION_HEX >= 0x03070000 \
1306+ && PYPY_VERSION_NUM >= 0x07030800 ))) \
1307+ && !defined (Py_LIMITED_API))
13041308# define PyHASH_BITS _PyHASH_BITS
13051309# define PyHASH_MODULUS _PyHASH_MODULUS
13061310# define PyHASH_INF _PyHASH_INF
@@ -1443,10 +1447,10 @@ PyDict_SetDefaultRef(PyObject *d, PyObject *key, PyObject *default_value,
14431447#endif
14441448
14451449#if PY_VERSION_HEX < 0x030D00B3
1446- # define Py_BEGIN_CRITICAL_SECTION (op ) {
1447- # define Py_END_CRITICAL_SECTION () }
1448- # define Py_BEGIN_CRITICAL_SECTION2 (a, b ) {
1449- # define Py_END_CRITICAL_SECTION2 () }
1450+ # define Py_BEGIN_CRITICAL_SECTION (op ) {
1451+ # define Py_END_CRITICAL_SECTION () }
1452+ # define Py_BEGIN_CRITICAL_SECTION2 (a, b ) {
1453+ # define Py_END_CRITICAL_SECTION2 () }
14501454#endif
14511455
14521456#if PY_VERSION_HEX < 0x030E0000 && !defined(PYPY_VERSION) && !defined(Py_LIMITED_API)
@@ -1826,7 +1830,8 @@ static inline Py_hash_t Py_HashBuffer(const void *ptr, Py_ssize_t len)
18261830 || (defined (Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030e0000 ))
18271831static inline int PyIter_NextItem (PyObject *iter, PyObject **item)
18281832{
1829- #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03040000
1833+ // Limited API: PyType_GetSlot() only accepts all types since Python 3.10
1834+ #if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
18301835 iternextfunc tp_iternext;
18311836
18321837 assert (iter != NULL );
@@ -1835,7 +1840,6 @@ static inline int PyIter_NextItem(PyObject *iter, PyObject **item)
18351840#ifndef Py_LIMITED_API
18361841 tp_iternext = Py_TYPE (iter)->tp_iternext ;
18371842#else
1838- // PyType_GetSlot() only accepts all types since Python 3.10
18391843 tp_iternext = _Py_CAST (iternextfunc, PyType_GetSlot (Py_TYPE (iter), Py_tp_iternext));
18401844#endif
18411845 if (tp_iternext == NULL ) {
@@ -1856,13 +1860,14 @@ static inline int PyIter_NextItem(PyObject *iter, PyObject **item)
18561860 }
18571861 return -1 ;
18581862#else
1863+ // Implementation for limited C API 3.9 and older
1864+
18591865 assert (iter != NULL );
18601866 assert (item != NULL );
18611867
18621868 // Cannot check if iter is an iterator: PyIter_Check() is only implemented
18631869 // as a function since Python 3.8.
18641870
1865- // Limited C API 3.2 and 3.3
18661871 *item = PyIter_Next (iter);
18671872 if (*item != NULL ) {
18681873 return 1 ;
@@ -2547,6 +2552,7 @@ static inline PyObject*
25472552PySys_GetAttr (PyObject *name)
25482553{
25492554#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000
2555+ // Limited C API 3.9 and older
25502556 PyObject *bytes, *result;
25512557 bytes = PyUnicode_AsUTF8String (name);
25522558 if (bytes == NULL ) {
@@ -2556,6 +2562,7 @@ PySys_GetAttr(PyObject *name)
25562562 Py_DECREF (bytes);
25572563 return result;
25582564#else
2565+ // Python 3.14 and newer, and limited C API 3.10 and newer
25592566#ifndef Py_LIMITED_API
25602567 const char *name_str = PyUnicode_AsUTF8 (name);
25612568#else
@@ -2583,6 +2590,7 @@ static inline int
25832590PySys_GetOptionalAttr (PyObject *name, PyObject **value)
25842591{
25852592#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000
2593+ // Limited C API 3.9 and older
25862594 PyObject *bytes;
25872595 int res;
25882596 bytes = PyUnicode_AsUTF8String (name);
0 commit comments