]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
[3.13] gh-126986: Stop Using _PyInterpreterState_FailIfNotRunning() (gh-127112)
authorEric Snow <ericsnowcurrently@gmail.com>
Thu, 21 Nov 2024 17:33:15 +0000 (10:33 -0700)
committerGitHub <noreply@github.com>
Thu, 21 Nov 2024 17:33:15 +0000 (10:33 -0700)
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.

Python/crossinterp.c
Python/pystate.c

index 2af0dd6191aa4e99d8ae6bf7b487fdfbd41b4c7b..01bb45d23bac1bb4f6f96cc644d5371c52185c13 100644 (file)
@@ -985,8 +985,8 @@ _PyXI_ApplyErrorCode(_PyXI_errcode code, PyInterpreterState *interp)
         break;
     case _PyXI_ERR_ALREADY_RUNNING:
         assert(interp != NULL);
-        assert(_PyInterpreterState_IsRunningMain(interp));
-        _PyInterpreterState_FailIfRunningMain(interp);
+        // In 3.14+ we use _PyErr_SetInterpreterAlreadyRunning().
+        PyErr_SetString(PyExc_InterpreterError, "interpreter already running");
         break;
     case _PyXI_ERR_MAIN_NS_FAILURE:
         PyErr_SetString(PyExc_InterpreterError,
index ad3fdce69bf1d535f2a5ca636b11b2eaa25c9663..960895e5badc274ac1bba2734f747ebe34373009 100644 (file)
@@ -1053,7 +1053,9 @@ get_main_thread(PyInterpreterState *interp)
 int
 _PyInterpreterState_SetRunningMain(PyInterpreterState *interp)
 {
-    if (_PyInterpreterState_FailIfRunningMain(interp) < 0) {
+    if (get_main_thread(interp) != NULL) {
+        // In 3.14+ we use _PyErr_SetInterpreterAlreadyRunning().
+        PyErr_SetString(PyExc_InterpreterError, "interpreter already running");
         return -1;
     }
     PyThreadState *tstate = current_fast_get();
@@ -1099,6 +1101,7 @@ _PyThreadState_IsRunningMain(PyThreadState *tstate)
     return get_main_thread(interp) == tstate;
 }
 
+// This has been removed in 3.14.
 int
 _PyInterpreterState_FailIfRunningMain(PyInterpreterState *interp)
 {