From 1432a354e020f45b3dd23d2a5f8ccd9d374eba1d Mon Sep 17 00:00:00 2001 From: Eric Snow Date: Wed, 8 Dec 2021 14:05:34 -0700 Subject: [PATCH] Move the small ints to _Py_global_objects. --- Include/internal/pycore_global_objects.h | 15 +++++++++++ Include/internal/pycore_long.h | 4 ++- Include/internal/pycore_long_state.h | 33 ------------------------ Include/internal/pycore_runtime.h | 7 +---- Makefile.pre.in | 1 - PCbuild/pythoncore.vcxproj | 1 - PCbuild/pythoncore.vcxproj.filters | 3 --- 7 files changed, 19 insertions(+), 45 deletions(-) delete mode 100644 Include/internal/pycore_long_state.h diff --git a/Include/internal/pycore_global_objects.h b/Include/internal/pycore_global_objects.h index 6cc50080497cd7..0bf84ee26866ee 100644 --- a/Include/internal/pycore_global_objects.h +++ b/Include/internal/pycore_global_objects.h @@ -9,6 +9,15 @@ extern "C" { #endif +#define _PY_NSMALLPOSINTS 257 +#define _PY_NSMALLNEGINTS 5 + +// _PyLong_GetZero() and _PyLong_GetOne() must always be available +#if _PY_NSMALLPOSINTS < 2 +# error "_PY_NSMALLPOSINTS must be greater than 1" +#endif + + // Only immutable objects should be considered runtime-global. // All others must be per-interpreter. @@ -19,6 +28,12 @@ extern "C" { struct _Py_global_objects { struct { + /* Small integers are preallocated in this array so that they + * can be shared. + * The integers that are preallocated are those in the range + *-_PY_NSMALLNEGINTS (inclusive) to _PY_NSMALLPOSINTS (not inclusive). + */ + PyLongObject small_ints[_PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS]; } singletons; }; diff --git a/Include/internal/pycore_long.h b/Include/internal/pycore_long.h index a5639ceb6924a8..36ce0ea45e4991 100644 --- a/Include/internal/pycore_long.h +++ b/Include/internal/pycore_long.h @@ -8,7 +8,7 @@ extern "C" { # error "this header requires Py_BUILD_CORE define" #endif -#include "pycore_long_state.h" // _PyLong_SMALL_INTS +#include "pycore_global_objects.h" // _PY_NSMALLNEGINTS #include "pycore_pystate.h" // _PyThreadState_GET() #include "pycore_runtime.h" // _PyRuntime @@ -21,6 +21,8 @@ extern PyStatus _PyLong_InitTypes(PyInterpreterState *); /* other API */ +#define _PyLong_SMALL_INTS _Py_SINGLETON(small_ints) + // Return a borrowed reference to the zero singleton. // The function cannot return NULL. static inline PyObject* _PyLong_GetZero(void) diff --git a/Include/internal/pycore_long_state.h b/Include/internal/pycore_long_state.h deleted file mode 100644 index 5fe8e623a9effe..00000000000000 --- a/Include/internal/pycore_long_state.h +++ /dev/null @@ -1,33 +0,0 @@ -#ifndef Py_INTERNAL_LONG_STATE_H -#define Py_INTERNAL_LONG_STATE_H -#ifdef __cplusplus -extern "C" { -#endif - -#ifndef Py_BUILD_CORE -# error "this header requires Py_BUILD_CORE define" -#endif - -#define _PY_NSMALLPOSINTS 257 -#define _PY_NSMALLNEGINTS 5 - -// _PyLong_GetZero() and _PyLong_GetOne() must always be available -#if _PY_NSMALLPOSINTS < 2 -# error "_PY_NSMALLPOSINTS must be greater than 1" -#endif - -struct _Py_long_state { - /* Small integers are preallocated in this array so that they - * can be shared. - * The integers that are preallocated are those in the range - *-_PY_NSMALLNEGINTS (inclusive) to _PY_NSMALLPOSINTS (not inclusive). - */ - PyLongObject small_ints[_PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS]; -}; - -#define _PyLong_SMALL_INTS _PyRuntime.int_state.small_ints - -#ifdef __cplusplus -} -#endif -#endif /* !Py_INTERNAL_LONG_STATE_H */ diff --git a/Include/internal/pycore_runtime.h b/Include/internal/pycore_runtime.h index 20fb73ab1c1e4d..cb8b02b7b11891 100644 --- a/Include/internal/pycore_runtime.h +++ b/Include/internal/pycore_runtime.h @@ -11,7 +11,6 @@ extern "C" { #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_long_state.h" // struct _Py_long_state #include "pycore_unicodeobject.h" // struct _Py_unicode_runtime_ids /* ceval state */ @@ -102,10 +101,6 @@ typedef struct pyruntimestate { unsigned long main_thread; - struct _Py_long_state int_state; - - struct _Py_global_objects global_objects; - #define NEXITFUNCS 32 void (*exitfuncs[NEXITFUNCS])(void); int nexitfuncs; @@ -123,7 +118,7 @@ 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; } _PyRuntimeState; #define _PyRuntimeState_INIT \ diff --git a/Makefile.pre.in b/Makefile.pre.in index 1645923f482b0f..e024363592d98b 100644 --- a/Makefile.pre.in +++ b/Makefile.pre.in @@ -1602,7 +1602,6 @@ PYTHON_HEADERS= \ $(srcdir)/Include/internal/pycore_interpreteridobject.h \ $(srcdir)/Include/internal/pycore_list.h \ $(srcdir)/Include/internal/pycore_long.h \ - $(srcdir)/Include/internal/pycore_long_state.h \ $(srcdir)/Include/internal/pycore_moduleobject.h \ $(srcdir)/Include/internal/pycore_namespace.h \ $(srcdir)/Include/internal/pycore_object.h \ diff --git a/PCbuild/pythoncore.vcxproj b/PCbuild/pythoncore.vcxproj index 30d92f51cefad0..97e9bfd21326f4 100644 --- a/PCbuild/pythoncore.vcxproj +++ b/PCbuild/pythoncore.vcxproj @@ -222,7 +222,6 @@ - diff --git a/PCbuild/pythoncore.vcxproj.filters b/PCbuild/pythoncore.vcxproj.filters index 3f29cc704488a8..cc0a2b0f75924d 100644 --- a/PCbuild/pythoncore.vcxproj.filters +++ b/PCbuild/pythoncore.vcxproj.filters @@ -576,9 +576,6 @@ Include\internal - - Include\internal - Include\internal