Skip to content

Commit 8cdd636

Browse files
[3.13] gh-126986: Stop Using _PyInterpreterState_FailIfNotRunning() (gh-127112)
This is a pseudo-backport of d6b3e78 (gh-126988). In that change for 3.14+, we dropped _PyInterpreterState_FailIfNotRunning() and added _PyErr_SetInterpreterAlreadyRunning(). Here, we replace usage of _PyInterpreterState_FailIfNotRunning() with the inlined equivalent of _PyErr_SetInterpreterAlreadyRunning(), without adding that function. That way we avoid changing the 3.13 ABI.
1 parent c743314 commit 8cdd636

File tree

2 files changed

+6
-3
lines changed

2 files changed

+6
-3
lines changed

Python/crossinterp.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -985,8 +985,8 @@ _PyXI_ApplyErrorCode(_PyXI_errcode code, PyInterpreterState *interp)
985985
break;
986986
case _PyXI_ERR_ALREADY_RUNNING:
987987
assert(interp != NULL);
988-
assert(_PyInterpreterState_IsRunningMain(interp));
989-
_PyInterpreterState_FailIfRunningMain(interp);
988+
// In 3.14+ we use _PyErr_SetInterpreterAlreadyRunning().
989+
PyErr_SetString(PyExc_InterpreterError, "interpreter already running");
990990
break;
991991
case _PyXI_ERR_MAIN_NS_FAILURE:
992992
PyErr_SetString(PyExc_InterpreterError,

Python/pystate.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1053,7 +1053,9 @@ get_main_thread(PyInterpreterState *interp)
10531053
int
10541054
_PyInterpreterState_SetRunningMain(PyInterpreterState *interp)
10551055
{
1056-
if (_PyInterpreterState_FailIfRunningMain(interp) < 0) {
1056+
if (get_main_thread(interp) != NULL) {
1057+
// In 3.14+ we use _PyErr_SetInterpreterAlreadyRunning().
1058+
PyErr_SetString(PyExc_InterpreterError, "interpreter already running");
10571059
return -1;
10581060
}
10591061
PyThreadState *tstate = current_fast_get();
@@ -1099,6 +1101,7 @@ _PyThreadState_IsRunningMain(PyThreadState *tstate)
10991101
return get_main_thread(interp) == tstate;
11001102
}
11011103

1104+
// This has been removed in 3.14.
11021105
int
11031106
_PyInterpreterState_FailIfRunningMain(PyInterpreterState *interp)
11041107
{

0 commit comments

Comments
 (0)