Skip to content

Commit b8ddf7e

Browse files
Statically initialize _PyRuntimeState fields. (gh-30588)
https://bugs.python.org/issue45953
1 parent bc02eac commit b8ddf7e

File tree

2 files changed

+11
-10
lines changed

2 files changed

+11
-10
lines changed

Include/internal/pycore_runtime_init.h

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,17 @@ extern "C" {
1717

1818
#define _PyRuntimeState_INIT \
1919
{ \
20+
.gilstate = { \
21+
.check_enabled = 1, \
22+
/* A TSS key must be initialized with Py_tss_NEEDS_INIT \
23+
in accordance with the specification. */ \
24+
.autoTSSkey = Py_tss_NEEDS_INIT, \
25+
}, \
26+
.interpreters = { \
27+
/* This prevents interpreters from getting created \
28+
until _PyInterpreterState_Enable() is called. */ \
29+
.next_id = -1, \
30+
}, \
2031
.global_objects = _Py_global_objects_INIT, \
2132
._main_interpreter = _PyInterpreterState_INIT, \
2233
}

Python/pystate.c

Lines changed: 0 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -111,17 +111,7 @@ init_runtime(_PyRuntimeState *runtime,
111111

112112
PyPreConfig_InitPythonConfig(&runtime->preconfig);
113113

114-
runtime->gilstate.check_enabled = 1;
115-
116-
/* A TSS key must be initialized with Py_tss_NEEDS_INIT
117-
in accordance with the specification. */
118-
Py_tss_t initial = Py_tss_NEEDS_INIT;
119-
runtime->gilstate.autoTSSkey = initial;
120-
121114
runtime->interpreters.mutex = interpreters_mutex;
122-
// This prevents interpreters from getting created
123-
// until _PyInterpreterState_Enable() is called.
124-
runtime->interpreters.next_id = -1;
125115

126116
runtime->xidregistry.mutex = xidregistry_mutex;
127117

0 commit comments

Comments
 (0)