From 630c8df5cf126594f8c1c4579c1888ca80a29d59 Mon Sep 17 00:00:00 2001 From: Victor Stinner Date: Tue, 17 Dec 2019 13:02:18 +0100 Subject: bpo-38858: Small integer per interpreter (GH-17315) Each Python subinterpreter now has its own "small integer singletons": numbers in [-5; 257] range. It is no longer possible to change the number of small integers at build time by overriding NSMALLNEGINTS and NSMALLPOSINTS macros: macros should now be modified manually in pycore_pystate.h header file. For now, continue to share _PyLong_Zero and _PyLong_One singletons between all subinterpreters. --- Include/internal/pycore_pystate.h | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'Include/internal/pycore_pystate.h') diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index aa2103f07c..b78ed69042 100644 --- a/Include/internal/pycore_pystate.h +++ b/Include/internal/pycore_pystate.h @@ -56,6 +56,9 @@ struct _ceval_runtime_state { typedef PyObject* (*_PyFrameEvalFunction)(struct _frame *, int); +#define _PY_NSMALLPOSINTS 257 +#define _PY_NSMALLNEGINTS 5 + // The PyInterpreterState typedef is in Include/pystate.h. struct _is { @@ -139,6 +142,15 @@ struct _is { int atbol; } listnode; } parser; + +#if _PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS > 0 + /* 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]; +#endif }; PyAPI_FUNC(struct _is*) _PyInterpreterState_LookUpID(PY_INT64_T); -- cgit v1.2.1