summaryrefslogtreecommitdiffstats
path: root/Include/internal/pycore_runtime.h
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2021-12-14 01:04:05 (GMT)
committerGitHub <noreply@github.com>2021-12-14 01:04:05 (GMT)
commit121f1f893a39d0b58d3d2b5597505c154ecaac2a (patch)
tree2efda2489f892c98015cf80763369ea4f3505666 /Include/internal/pycore_runtime.h
parentcb589d1b6bad4b75852c2e2a471a3800d5efdca7 (diff)
downloadcpython-121f1f893a39d0b58d3d2b5597505c154ecaac2a.zip
cpython-121f1f893a39d0b58d3d2b5597505c154ecaac2a.tar.gz
cpython-121f1f893a39d0b58d3d2b5597505c154ecaac2a.tar.bz2
bpo-45953: Statically initialize the small ints. (gh-30092)
The array of small PyLong objects has been statically declared. Here I also statically initialize them. Consequently they are no longer initialized dynamically during runtime init. I've also moved them under a new sub-struct in _PyRuntimeState, in preparation for static allocation and initialization of other global objects. https://bugs.python.org/issue45953
Diffstat (limited to 'Include/internal/pycore_runtime.h')
-rw-r--r--Include/internal/pycore_runtime.h19
1 files changed, 10 insertions, 9 deletions
diff --git a/Include/internal/pycore_runtime.h b/Include/internal/pycore_runtime.h
index bd88510..725c859 100644
--- a/Include/internal/pycore_runtime.h
+++ b/Include/internal/pycore_runtime.h
@@ -8,10 +8,10 @@ extern "C" {
# error "this header requires Py_BUILD_CORE define"
#endif
-#include "pycore_atomic.h" /* _Py_atomic_address */
-#include "pycore_gil.h" // struct _gil_runtime_state
-#include "pycore_long_state.h" // struct _Py_long_state
-#include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids
+#include "pycore_atomic.h" /* _Py_atomic_address */
+#include "pycore_gil.h" // struct _gil_runtime_state
+#include "pycore_global_objects.h" // struct _Py_global_objects
+#include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids
/* ceval state */
@@ -101,8 +101,6 @@ typedef struct pyruntimestate {
unsigned long main_thread;
- struct _Py_long_state int_state;
-
#define NEXITFUNCS 32
void (*exitfuncs[NEXITFUNCS])(void);
int nexitfuncs;
@@ -120,12 +118,14 @@ typedef struct pyruntimestate {
struct _Py_unicode_runtime_ids unicode_ids;
- // XXX Consolidate globals found via the check-c-globals script.
+ struct _Py_global_objects global_objects;
+ // If anything gets added after global_objects then
+ // _PyRuntimeState_reset() needs to get updated to clear it.
} _PyRuntimeState;
#define _PyRuntimeState_INIT \
{ \
- ._initialized = 0, \
+ .global_objects = _Py_global_objects_INIT, \
}
/* Note: _PyRuntimeState_INIT sets other fields to 0/NULL */
@@ -133,7 +133,8 @@ static inline void
_PyRuntimeState_reset(_PyRuntimeState *runtime)
{
/* Make it match _PyRuntimeState_INIT. */
- memset(runtime, 0, sizeof(*runtime));
+ memset(runtime, 0, (size_t)&runtime->global_objects - (size_t)runtime);
+ _Py_global_objects_reset(&runtime->global_objects);
}