From 40d82fc10d5fa044ed5d6781fe3768ba0443ee43 Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Thu, 16 Dec 2021 16:24:39 -0700 Subject: [PATCH] Statically initialize _PyRuntimeState fields. --- Include/internal/pycore_runtime_init.h | 11 +++++++++++ Python/pystate.c | 10 ---------- 2 files changed, 11 insertions(+), 10 deletions(-) diff --git a/Include/internal/pycore_runtime_init.h b/Include/internal/pycore_runtime_init.h index e35c696610b94f..fc768ff5d053f7 100644 --- a/Include/internal/pycore_runtime_init.h +++ b/Include/internal/pycore_runtime_init.h @@ -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, \ } diff --git a/Python/pystate.c b/Python/pystate.c index e6175852c461c8..50b36218960284 100644 --- a/Python/pystate.c +++ b/Python/pystate.c @@ -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;