Skip to content

Commit

Permalink
Statically initialize _PyRuntimeState fields. (gh-30588)
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently authored Jan 13, 2022
1 parent bc02eac commit b8ddf7e
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 10 deletions.
11 changes: 11 additions & 0 deletions Include/internal/pycore_runtime_init.h
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,17 @@ extern "C" {

#define _PyRuntimeState_INIT \
{ \
.gilstate = { \
.check_enabled = 1, \
/* A TSS key must be initialized with Py_tss_NEEDS_INIT \
in accordance with the specification. */ \
.autoTSSkey = Py_tss_NEEDS_INIT, \
}, \
.interpreters = { \
/* This prevents interpreters from getting created \
until _PyInterpreterState_Enable() is called. */ \
.next_id = -1, \
}, \
.global_objects = _Py_global_objects_INIT, \
._main_interpreter = _PyInterpreterState_INIT, \
}
Expand Down
10 changes: 0 additions & 10 deletions Python/pystate.c
Original file line number Diff line number Diff line change
Expand Up @@ -111,17 +111,7 @@ init_runtime(_PyRuntimeState *runtime,

PyPreConfig_InitPythonConfig(&runtime->preconfig);

runtime->gilstate.check_enabled = 1;

/* A TSS key must be initialized with Py_tss_NEEDS_INIT
in accordance with the specification. */
Py_tss_t initial = Py_tss_NEEDS_INIT;
runtime->gilstate.autoTSSkey = initial;

runtime->interpreters.mutex = interpreters_mutex;
// This prevents interpreters from getting created
// until _PyInterpreterState_Enable() is called.
runtime->interpreters.next_id = -1;

runtime->xidregistry.mutex = xidregistry_mutex;

Expand Down

0 comments on commit b8ddf7e

Please sign in to comment.