bpo-38631: _PyGILState_Init() returns PyStatus (GH-18908)

_PyGILState_Init() now returns PyStatus rather than calling
Py_FatalError() on failure.
This commit is contained in:
Victor Stinner 2020-03-10 23:49:16 +01:00 committed by GitHub
parent 88f82b2b9e
commit 4e53abb0f4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 8 additions and 4 deletions

View File

@ -83,7 +83,7 @@ extern void _PyHash_Fini(void);
extern void _PyTraceMalloc_Fini(void); extern void _PyTraceMalloc_Fini(void);
extern void _PyWarnings_Fini(PyInterpreterState *interp); extern void _PyWarnings_Fini(PyInterpreterState *interp);
extern void _PyGILState_Init(PyThreadState *tstate); extern PyStatus _PyGILState_Init(PyThreadState *tstate);
extern void _PyGILState_Fini(PyThreadState *tstate); extern void _PyGILState_Fini(PyThreadState *tstate);
PyAPI_FUNC(void) _PyGC_DumpShutdownStats(PyThreadState *tstate); PyAPI_FUNC(void) _PyGC_DumpShutdownStats(PyThreadState *tstate);

View File

@ -551,7 +551,10 @@ pycore_create_interpreter(_PyRuntimeState *runtime,
_PyEval_FiniThreads(&runtime->ceval); _PyEval_FiniThreads(&runtime->ceval);
/* Auto-thread-state API */ /* Auto-thread-state API */
_PyGILState_Init(tstate); status = _PyGILState_Init(tstate);
if (_PyStatus_EXCEPTION(status)) {
return status;
}
/* Create the GIL */ /* Create the GIL */
status = _PyEval_InitThreads(tstate); status = _PyEval_InitThreads(tstate);

View File

@ -1147,7 +1147,7 @@ PyThreadState_IsCurrent(PyThreadState *tstate)
/* Internal initialization/finalization functions called by /* Internal initialization/finalization functions called by
Py_Initialize/Py_FinalizeEx Py_Initialize/Py_FinalizeEx
*/ */
void PyStatus
_PyGILState_Init(PyThreadState *tstate) _PyGILState_Init(PyThreadState *tstate)
{ {
/* must init with valid states */ /* must init with valid states */
@ -1157,13 +1157,14 @@ _PyGILState_Init(PyThreadState *tstate)
struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate; struct _gilstate_runtime_state *gilstate = &tstate->interp->runtime->gilstate;
if (PyThread_tss_create(&gilstate->autoTSSkey) != 0) { if (PyThread_tss_create(&gilstate->autoTSSkey) != 0) {
Py_FatalError("Could not allocate TSS entry"); return _PyStatus_NO_MEMORY();
} }
gilstate->autoInterpreterState = tstate->interp; gilstate->autoInterpreterState = tstate->interp;
assert(PyThread_tss_get(&gilstate->autoTSSkey) == NULL); assert(PyThread_tss_get(&gilstate->autoTSSkey) == NULL);
assert(tstate->gilstate_counter == 0); assert(tstate->gilstate_counter == 0);
_PyGILState_NoteThreadState(gilstate, tstate); _PyGILState_NoteThreadState(gilstate, tstate);
return _PyStatus_OK();
} }
PyInterpreterState * PyInterpreterState *