]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-126986: Drop _PyInterpreterState_FailIfNotRunning() (gh-126988)
authorEric Snow <ericsnowcurrently@gmail.com>
Tue, 19 Nov 2024 00:11:12 +0000 (17:11 -0700)
committerGitHub <noreply@github.com>
Tue, 19 Nov 2024 00:11:12 +0000 (00:11 +0000)
We replace it with _PyErr_SetInterpreterAlreadyRunning().

Include/internal/pycore_pystate.h
Python/crossinterp.c
Python/pystate.c

index edcd75a55b686b79fdd89ea00e57927cd3ce27b7..f4fbf3734e2d4472d6145e84cade6f50e1d919f1 100644 (file)
@@ -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 *);
index fe7d75f6b72f68af6f754e1fb399402880074dd7..7aaa045f375cf0902adf655ad0e42f06e98018ac 100644 (file)
@@ -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,
index 24ee73c145cbccd2040fe2a8c1b5d7c14254387e..a209a26f16f84098d55cc7844c5ae0ee043c1b89 100644 (file)
@@ -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();
@@ -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)
 {