Skip to content

Commit d6b3e78

Browse files
gh-126986: Drop _PyInterpreterState_FailIfNotRunning() (gh-126988)
We replace it with _PyErr_SetInterpreterAlreadyRunning().
1 parent 0063f5f commit d6b3e78

File tree

3 files changed

+10
-15
lines changed

3 files changed

+10
-15
lines changed

Include/internal/pycore_pystate.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
8282
PyAPI_FUNC(int) _PyInterpreterState_SetRunningMain(PyInterpreterState *);
8383
PyAPI_FUNC(void) _PyInterpreterState_SetNotRunningMain(PyInterpreterState *);
8484
PyAPI_FUNC(int) _PyInterpreterState_IsRunningMain(PyInterpreterState *);
85-
PyAPI_FUNC(int) _PyInterpreterState_FailIfRunningMain(PyInterpreterState *);
85+
PyAPI_FUNC(void) _PyErr_SetInterpreterAlreadyRunning(void);
8686

8787
extern int _PyThreadState_IsRunningMain(PyThreadState *);
8888
extern void _PyInterpreterState_ReinitRunningMain(PyThreadState *);

Python/crossinterp.c

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -983,8 +983,7 @@ _PyXI_ApplyErrorCode(_PyXI_errcode code, PyInterpreterState *interp)
983983
break;
984984
case _PyXI_ERR_ALREADY_RUNNING:
985985
assert(interp != NULL);
986-
assert(_PyInterpreterState_IsRunningMain(interp));
987-
_PyInterpreterState_FailIfRunningMain(interp);
986+
_PyErr_SetInterpreterAlreadyRunning();
988987
break;
989988
case _PyXI_ERR_MAIN_NS_FAILURE:
990989
PyErr_SetString(PyExc_InterpreterError,

Python/pystate.c

Lines changed: 8 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1047,10 +1047,17 @@ get_main_thread(PyInterpreterState *interp)
10471047
return _Py_atomic_load_ptr_relaxed(&interp->threads.main);
10481048
}
10491049

1050+
void
1051+
_PyErr_SetInterpreterAlreadyRunning(void)
1052+
{
1053+
PyErr_SetString(PyExc_InterpreterError, "interpreter already running");
1054+
}
1055+
10501056
int
10511057
_PyInterpreterState_SetRunningMain(PyInterpreterState *interp)
10521058
{
1053-
if (_PyInterpreterState_FailIfRunningMain(interp) < 0) {
1059+
if (get_main_thread(interp) != NULL) {
1060+
_PyErr_SetInterpreterAlreadyRunning();
10541061
return -1;
10551062
}
10561063
PyThreadState *tstate = current_fast_get();
@@ -1096,17 +1103,6 @@ _PyThreadState_IsRunningMain(PyThreadState *tstate)
10961103
return get_main_thread(interp) == tstate;
10971104
}
10981105

1099-
int
1100-
_PyInterpreterState_FailIfRunningMain(PyInterpreterState *interp)
1101-
{
1102-
if (get_main_thread(interp) != NULL) {
1103-
PyErr_SetString(PyExc_InterpreterError,
1104-
"interpreter already running");
1105-
return -1;
1106-
}
1107-
return 0;
1108-
}
1109-
11101106
void
11111107
_PyInterpreterState_ReinitRunningMain(PyThreadState *tstate)
11121108
{

0 commit comments

Comments
 (0)