@@ -358,8 +358,8 @@ _PyThreadState_GetFrameBorrow(PyThreadState *tstate)
358358 || (defined (PYPY_VERSION ) && PY_VERSION_HEX < 0x030C0000 )) \
359359 && !(defined (Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000 ))
360360
361- # if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000 && defined(MS_WINDOWS))
362- static inline PyInterpreterState* PyInterpreterState_Get (void )
361+ static inline PyInterpreterState*
362+ PythonCAPICompat_PyInterpreterState_Get (void )
363363{
364364 PyThreadState *tstate;
365365 PyInterpreterState *interp;
@@ -374,27 +374,17 @@ static inline PyInterpreterState* PyInterpreterState_Get(void)
374374 }
375375 return interp;
376376}
377- #else
378- // PyInterpreterState_Get() is in the limited C API 3.9, but not in the 3.9
379- // stable ABI on Windows. It was added to stable ABI on Windows in Python 3.10.
380- // Use a macro to override C API function.
381- static inline PyInterpreterState*
382- PythonCAPI_Compat_PyInterpreterState_Get (void )
383- {
384- PyThreadState *tstate;
385- PyInterpreterState *interp;
386377
387- tstate = PyThreadState_GET ();
388- if (tstate == _Py_NULL) {
389- Py_FatalError (" GIL released (tstate is NULL)" );
390- }
391- interp = tstate->interp ;
392- if (interp == _Py_NULL) {
393- Py_FatalError (" no current interpreter" );
394- }
395- return interp;
378+ #if !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000 && defined(MS_WINDOWS))
379+ static inline PyInterpreterState* PyInterpreterState_Get (void )
380+ {
381+ return PythonCAPICompat_PyInterpreterState_Get ();
396382}
397- #define PyInterpreterState_Get () PythonCAPI_Compat_PyInterpreterState_Get()
383+ #else
384+ // PyInterpreterState_Get() is in the limited C API 3.9, but not in
385+ // the 3.9 stable ABI on Windows. It was added to stable ABI on Windows
386+ // in Python 3.10. Use a macro to override C API function.
387+ # define PyInterpreterState_Get () PythonCAPICompat_PyInterpreterState_Get()
398388#endif
399389
400390#endif
@@ -1099,7 +1089,6 @@ PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *str, Py_ssize_t str_
10991089 else
11001090#endif
11011091 {
1102- // Python 3.3.0a1 added PyUnicode_AsUTF8AndSize()
11031092#if defined(Py_LIMITED_API) && Py_LIMITED_API+0 < 0x030a0000
11041093 bytes = PyUnicode_AsUTF8String (unicode);
11051094 if (bytes == NULL ) {
@@ -1111,6 +1100,7 @@ PyUnicode_EqualToUTF8AndSize(PyObject *unicode, const char *str, Py_ssize_t str_
11111100 utf8 = PyBytes_AsString (bytes);
11121101 len = PyBytes_Size (bytes);
11131102#else
1103+ // Python 3.10 added PyUnicode_AsUTF8AndSize() to the limited C API
11141104 utf8 = PyUnicode_AsUTF8AndSize (unicode, &len);
11151105 if (utf8 == NULL ) {
11161106 // Memory allocation failure. The API cannot report error,
0 commit comments