8000 bpo-45953: Statically initialize the small ints. by ericsnowcurrently · Pull Request #30092 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

bpo-45953: Statically initialize the small ints. #30092

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Move the small ints to _Py_global_objects.
  • Loading branch information
ericsnowcurrently committed Dec 13, 2021
commit 1432a354e020f45b3dd23d2a5f8ccd9d374eba1d
15 changes: 15 additions & 0 deletions Include/internal/pycore_global_objects.h
Original file line number Diff line number Diff line change
Expand Up @@ -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.

Expand All @@ -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;
};

Expand Down
4 changes: 3 additions & 1 deletion Include/internal/pycore_long.h
8000
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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)
Expand Down
33 changes: 0 additions & 33 deletions Include/internal/pycore_long_state.h

This file was deleted.

7 changes: 1 addition & 6 deletions Include/internal/pycore_runtime.h
Original file line number Diff line number Diff line change
Expand Up @@ -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 */
Expand Down Expand Up @@ -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;
Expand All @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion Makefile.pre.in
8000
Original file line number Diff line number Diff line change
Expand Up @@ -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 \
Expand Down
1 change: 0 additions & 1 deletion PCbuild/pythoncore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,6 @@
<ClInclude Include="..\Include\internal\pycore_interpreteridobject.h" />
<ClInclude Include="..\Include\internal\pycore_list.h" />
<ClInclude Include="..\Include\internal\pycore_long.h" />
<ClInclude Include="..\Include\internal\pycore_long_state.h" />
<ClInclude Include="..\Include\internal\pycore_moduleobject.h" />
<ClInclude Include="..\Include\internal\pycore_namespace.h" />
<ClInclude Include="..\Include\internal\pycore_object.h" />
Expand Down
3 changes: 0 additions & 3 deletions PCbuild/pythoncore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -576,9 +576,6 @@
<ClInclude Include="..\Include\internal\pycore_long.h">
<Filter>Include\internal</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_long_state.h">
<Filter>Include\internal</Filter>
</ClInclude>
<ClInclude Include="..\Include\internal\pycore_moduleobject.h">
<Filter>Include\internal</Filter>
</ClInclude>
Expand Down
0