Skip to content

gh-126986: Drop _PyInterpreterState_FailIfNotRunning() #126988

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/internal/pycore_pystate.h
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ PyAPI_FUNC(PyObject *) _PyInterpreterState_GetIDObject(PyInterpreterState *);
PyAPI_FUNC(int) _PyInterpreterState_SetRunningMain(PyInterpreterState *);
PyAPI_FUNC(void) _PyInterpreterState_SetNotRunningMain(PyInterpreterState *);
PyAPI_FUNC(int) _PyInterpreterState_IsRunningMain(PyInterpreterState *);
PyAPI_FUNC(int) _PyInterpreterState_FailIfRunningMain(PyInterpreterState *);
PyAPI_FUNC(void) _PyErr_SetInterpreterAlreadyRunning(void);

extern int _PyThreadState_IsRunningMain(PyThreadState *);
extern void _PyInterpreterState_ReinitRunningMain(PyThreadState *);
Expand Down
3 changes: 1 addition & 2 deletions Python/crossinterp.c
Original file line number Diff line number Diff line change
Expand Up @@ -983,8 +983,7 @@ _PyXI_ApplyErrorCode(_PyXI_errcode code, PyInterpreterState *interp)
break;
case _PyXI_ERR_ALREADY_RUNNING:
assert(interp != NULL);
assert(_PyInterpreterState_IsRunningMain(interp));
_PyInterpreterState_FailIfRunningMain(interp);
_PyErr_SetInterpreterAlreadyRunning();
break;
case _PyXI_ERR_MAIN_NS_FAILURE:
PyErr_SetString(PyExc_InterpreterError,
Expand Down
20 changes: 8 additions & 12 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -1047,10 +1047,17 @@ get_main_thread(PyInterpreterState *interp)
return _Py_atomic_load_ptr_relaxed(&interp->threads.main);
}

void
_PyErr_SetInterpreterAlreadyRunning(void)
{
PyErr_SetString(PyExc_InterpreterError, "interpreter already running");
}

int
_PyInterpreterState_SetRunningMain(PyInterpreterState *interp)
{
if (_PyInterpreterState_FailIfRunningMain(interp) < 0) {
if (get_main_thread(interp) != NULL) {
_PyErr_SetInterpreterAlreadyRunning();
return -1;
}
PyThreadState *tstate = current_fast_get();
Expand Down Expand Up @@ -1096,17 +1103,6 @@ _PyThreadState_IsRunningMain(PyThreadState *tstate)
return get_main_thread(interp) == tstate;
}

int
_PyInterpreterState_FailIfRunningMain(PyInterpreterState *interp)
{
if (get_main_thread(interp) != NULL) {
PyErr_SetString(PyExc_InterpreterError,
"interpreter already running");
return -1;
}
return 0;
}

void
_PyInterpreterState_ReinitRunningMain(PyThreadState *tstate)
{
Expand Down
Loading