Skip to content

Commit 27728e9

Browse files
committed
Try to fix PyInterpreterState_Get() again
1 parent 39d9986 commit 27728e9

3 files changed

Lines changed: 10 additions & 20 deletions

File tree

‎docs/api.rst‎

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -820,7 +820,9 @@ PyInterpreterState
820820

821821
See `PyInterpreterState_Get() documentation <https://docs.python.org/dev/c-api/init.html#c.PyInterpreterState_Get>`__.
822822

823-
Not available on limited C API 3.8 and older.
823+
Not available on limited C API 3.8 and older on Unix.
824+
825+
Not available in stable ABI 3.9 and older on Windows.
824826

825827

826828
GC protocol

‎pythoncapi_compat.h‎

Lines changed: 3 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -355,11 +355,9 @@ _PyThreadState_GetFrameBorrow(PyThreadState *tstate)
355355
// PyPy added PyInterpreterState_Get() to PyPy3.12 v8.0.0
356356
// On Windows, PyInterpreterState_Get() was added to limited C API 3.10.
357357
#if ((PY_VERSION_HEX < 0x030900A5 \
358-
|| (defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030C0000)) \
359-
&& !(defined(Py_LIMITED_API) && PY_VERSION_HEX < 0x030A0000))
360-
361-
static inline PyInterpreterState*
362-
PythonCAPICompat_PyInterpreterState_Get(void)
358+
|| (defined(PYPY_VERSION) && PY_VERSION_HEX < 0x030C0000)) \
359+
&& !defined(Py_LIMITED_API))
360+
static inline PyInterpreterState* PyInterpreterState_Get(void)
363361
{
364362
PyThreadState *tstate;
365363
PyInterpreterState *interp;
@@ -374,19 +372,6 @@ PythonCAPICompat_PyInterpreterState_Get(void)
374372
}
375373
return interp;
376374
}
377-
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();
382-
}
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()
388-
#endif
389-
390375
#endif
391376

392377

‎tests/test_pythoncapi_compat_cext.c‎

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -336,7 +336,10 @@ test_thread_state(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
336336
static PyObject *
337337
test_interpreter(PyObject *Py_UNUSED(module), PyObject* Py_UNUSED(ignored))
338338
{
339-
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x03090000
339+
// On Windows,PyInterpreterState_Get() is not available in stable ABI 3.9,
340+
// only in stable ABI 3.10. Don't test it in limited C API 3.9 on Unix to
341+
// make the test simpler.
342+
#if !defined(Py_LIMITED_API) || Py_LIMITED_API+0 >= 0x030A0000
340343
// test PyInterpreterState_Get()
341344
PyInterpreterState *interp = PyInterpreterState_Get();
342345
assert(interp != _Py_NULL);

0 commit comments

Comments
 (0)