]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-46008: Return void from _PyEval_InitState(). (gh-29970)
authorEric Snow <ericsnowcurrently@gmail.com>
Tue, 7 Dec 2021 21:02:17 +0000 (14:02 -0700)
committerGitHub <noreply@github.com>
Tue, 7 Dec 2021 21:02:17 +0000 (14:02 -0700)
This falls into the category of keep-allocation-and-initialization separate. It also allows us to use _PyEval_InitState() safely in functions that return void.

https://bugs.python.org/issue46008

Include/internal/pycore_ceval.h
Python/ceval.c
Python/pystate.c

index 26d5677b1283772e257c9c871b00265ed001261f..20508d4a687475c0ea1bbedcd919c261b5ea7986 100644 (file)
@@ -17,7 +17,7 @@ struct _ceval_runtime_state;
 
 extern void _Py_FinishPendingCalls(PyThreadState *tstate);
 extern void _PyEval_InitRuntimeState(struct _ceval_runtime_state *);
-extern int _PyEval_InitState(struct _ceval_state *ceval);
+extern void _PyEval_InitState(struct _ceval_state *, PyThread_type_lock);
 extern void _PyEval_FiniState(struct _ceval_state *ceval);
 PyAPI_FUNC(void) _PyEval_SignalReceived(PyInterpreterState *interp);
 PyAPI_FUNC(int) _PyEval_AddPendingCall(
index c22af02330b924f6ad7c3e0a7f96aceddb7614a7..36d1360015ceb55785194817729b1b28ea846695 100644 (file)
@@ -747,24 +747,19 @@ _PyEval_InitRuntimeState(struct _ceval_runtime_state *ceval)
 #endif
 }
 
-int
-_PyEval_InitState(struct _ceval_state *ceval)
+void
+_PyEval_InitState(struct _ceval_state *ceval, PyThread_type_lock pending_lock)
 {
     ceval->recursion_limit = Py_DEFAULT_RECURSION_LIMIT;
 
     struct _pending_calls *pending = &ceval->pending;
     assert(pending->lock == NULL);
 
-    pending->lock = PyThread_allocate_lock();
-    if (pending->lock == NULL) {
-        return -1;
-    }
+    pending->lock = pending_lock;
 
 #ifdef EXPERIMENTAL_ISOLATED_SUBINTERPRETERS
     _gil_initialize(&ceval->gil);
 #endif
-
-    return 0;
 }
 
 void
index ba14c9d8af9fb707156ca50ff0cc462b8fd98a40..a0bd05077ee15fde21228b79737a445eba5703f3 100644 (file)
@@ -225,10 +225,12 @@ PyInterpreterState_New(void)
     _PyRuntimeState *runtime = &_PyRuntime;
     interp->runtime = runtime;
 
-    if (_PyEval_InitState(&interp->ceval) < 0) {
+    PyThread_type_lock pending_lock = PyThread_allocate_lock();
+    if (pending_lock == NULL) {
         goto out_of_memory;
     }
 
+    _PyEval_InitState(&interp->ceval, pending_lock);
     _PyGC_InitState(&interp->gc);
     PyConfig_InitPythonConfig(&interp->config);
     _PyType_InitCache(interp);