Skip to content

Commit

Permalink
Move the small ints to _Py_global_objects.
Browse files Browse the repository at this point in the history
  • Loading branch information
ericsnowcurrently committed Dec 13, 2021
1 parent c5e5702 commit 1432a35
Show file tree
Hide file tree
Showing 7 changed files with 19 additions and 45 deletions.
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
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
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 comments on commit 1432a35

Please sign in to comment.