Skip to content

Commit 4e53abb

Browse files
authored
bpo-38631: _PyGILState_Init() returns PyStatus (GH-18908)
_PyGILState_Init() now returns PyStatus rather than calling Py_FatalError() on failure.
1 parent 88f82b2 commit 4e53abb

File tree

3 files changed

+8
-4
lines changed

3 files changed

+8
-4
lines changed

Include/internal/pycore_pylifecycle.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,7 +83,7 @@ extern void _PyHash_Fini(void);
8383
extern void _PyTraceMalloc_Fini(void);
8484
extern void _PyWarnings_Fini(PyInterpreterState *interp);
8585

86-
extern void _PyGILState_Init(PyThreadState *tstate);
86+
extern PyStatus _PyGILState_Init(PyThreadState *tstate);
8787
extern void _PyGILState_Fini(PyThreadState *tstate);
8888

8989
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(PyThreadState *tstate);

Python/pylifecycle.c

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -551,7 +551,10 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
551551
_PyEval_FiniThreads(&runtime->ceval);
552552

553553
/* Auto-thread-state API */
554-
_PyGILState_Init(tstate);
554+
status = _PyGILState_Init(tstate);
555+
if (_PyStatus_EXCEPTION(status)) {
556+
return status;
557+
}
555558

556559
/* Create the GIL */
557560
status = _PyEval_InitThreads(tstate);

Python/pystate.c

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1147,7 +1147,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
11471147
/* Internal initialization/finalization functions called by
11481148
Py_Initialize/Py_FinalizeEx
11491149
*/
1150-
void
1150+
PyStatus
11511151
_PyGILState_Init(PyThreadState *tstate)
11521152
{
11531153
/* must init with valid states */
@@ -1157,13 +1157,14 @@ _PyGILState_Init(PyThreadState *tstate)
11571157
struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
11581158

11591159
if (PyThread_tss_create(&gilstate->autoTSSkey) != 0) {
1160-
Py_FatalError("Could not allocate TSS entry");
1160+
return _PyStatus_NO_MEMORY();
11611161
}
11621162
gilstate->autoInterpreterState = tstate->interp;
11631163
assert(PyThread_tss_get(&gilstate->autoTSSkey) == NULL);
11641164
assert(tstate->gilstate_counter == 0);
11651165

11661166
_PyGILState_NoteThreadState(gilstate, tstate);
1167+
return _PyStatus_OK();
11671168
}
11681169

11691170
PyInterpreterState *

0 commit comments

Comments
 (0)