Skip to content

bpo-38631: _PyGILState_Init() returns PyStatus #18908

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Mar 10, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion Include/internal/pycore_pylifecycle.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 4 additions & 1 deletion Python/pylifecycle.c
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
5 changes: 3 additions & 2 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand All @@ -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 *
Expand Down