]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Statically initialize _PyRuntimeState fields. (gh-30588)
authorEric Snow <ericsnowcurrently@gmail.com>
Thu, 13 Jan 2022 23:33:40 +0000 (16:33 -0700)
committerGitHub <noreply@github.com>
Thu, 13 Jan 2022 23:33:40 +0000 (16:33 -0700)
https://bugs.python.org/issue45953

Include/internal/pycore_runtime_init.h
Python/pystate.c

index e35c696610b94fe96f58fe758c2f6b14cdfa48c5..fc768ff5d053f74d949a0f919b159763ceba8861 100644 (file)
@@ -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, \
     }
index e6175852c461c8667db223f670644c2ba17765fa..50b36218960284f227a50e154cd15f78fd2ab66d 100644 (file)
@@ -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;