https://github.com/python/cpython/commit/d6b3e78504b3168c432b20002dbcf8ec9a435e61
commit: d6b3e78504b3168c432b20002dbcf8ec9a435e61
branch: main
author: Eric Snow <[email protected]>
committer: ericsnowcurrently <[email protected]>
date: 2024-11-19T00:11:12Z
summary:

gh-126986: Drop _PyInterpreterState_FailIfNotRunning() (gh-126988)

We replace it with _PyErr_SetInterpreterAlreadyRunning().

files:
M Include/internal/pycore_pystate.h
M Python/crossinterp.c
M Python/pystate.c

diff --git a/Include/internal/pycore_pystate.h 
b/Include/internal/pycore_pystate.h
index edcd75a55b686b..f4fbf3734e2d44 100644
--- a/Include/internal/pycore_pystate.h
+++ b/Include/internal/pycore_pystate.h
@@ -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 *);
diff --git a/Python/crossinterp.c b/Python/crossinterp.c
index fe7d75f6b72f68..7aaa045f375cf0 100644
--- a/Python/crossinterp.c
+++ b/Python/crossinterp.c
@@ -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,
diff --git a/Python/pystate.c b/Python/pystate.c
index 24ee73c145cbcc..a209a26f16f840 100644
--- a/Python/pystate.c
+++ b/Python/pystate.c
@@ -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)
 {

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to