]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-38631: _PyGILState_Init() returns PyStatus (GH-18908)
authorVictor Stinner <vstinner@python.org>
Tue, 10 Mar 2020 22:49:16 +0000 (23:49 +0100)
committerGitHub <noreply@github.com>
Tue, 10 Mar 2020 22:49:16 +0000 (23:49 +0100)
_PyGILState_Init() now returns PyStatus rather than calling
Py_FatalError() on failure.

Include/internal/pycore_pylifecycle.h
Python/pylifecycle.c
Python/pystate.c

index 2dd6149a6b3d35848a5657b6745db93bb3edee24..cf228033a72496d8f3db5fb0c16233c205e6d962 100644 (file)
@@ -83,7 +83,7 @@ extern void _PyHash_Fini(void);
 extern void _PyTraceMalloc_Fini(void);
 extern void _PyWarnings_Fini(PyInterpreterState *interp);
 
-extern void _PyGILState_Init(PyThreadState *tstate);
+extern PyStatus _PyGILState_Init(PyThreadState *tstate);
 extern void _PyGILState_Fini(PyThreadState *tstate);
 
 PyAPI_FUNC(void) _PyGC_DumpShutdownStats(PyThreadState *tstate);
index d00bf821c570a4a84793c7dcadd7f80f36805f67..bc32eff436e68bb66463f8b5884846f19ab61cf4 100644 (file)
@@ -551,7 +551,10 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
     _PyEval_FiniThreads(&runtime->ceval);
 
     /* Auto-thread-state API */
-    _PyGILState_Init(tstate);
+    status = _PyGILState_Init(tstate);
+    if (_PyStatus_EXCEPTION(status)) {
+        return status;
+    }
 
     /* Create the GIL */
     status = _PyEval_InitThreads(tstate);
index a926e9753cb491f3c76b16a65bb217d8ee365d9b..504f5f456dd2a5e01ab61b63551f04cbbb100639 100644 (file)
@@ -1147,7 +1147,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
 /* Internal initialization/finalization functions called by
    Py_Initialize/Py_FinalizeEx
 */
-void
+PyStatus
 _PyGILState_Init(PyThreadState *tstate)
 {
     /* must init with valid states */
@@ -1157,13 +1157,14 @@ _PyGILState_Init(PyThreadState *tstate)
     struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
 
     if (PyThread_tss_create(&gilstate->autoTSSkey) != 0) {
-        Py_FatalError("Could not allocate TSS entry");
+        return _PyStatus_NO_MEMORY();
     }
     gilstate->autoInterpreterState = tstate->interp;
     assert(PyThread_tss_get(&gilstate->autoTSSkey) == NULL);
     assert(tstate->gilstate_counter == 0);
 
     _PyGILState_NoteThreadState(gilstate, tstate);
+    return _PyStatus_OK();
 }
 
 PyInterpreterState *