diff options
author | Victor Stinner <vstinner@python.org> | 2019-12-17 12:02:18 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2019-12-17 12:02:18 (GMT) |
commit | 630c8df5cf126594f8c1c4579c1888ca80a29d59 (patch) | |
tree | 7114d3190806b8b23b23211c0fdc8e0c507ff0c1 /Include/internal | |
parent | f501db2b93a9d3d840b6fb38d6bdda8bcc400d4a (diff) | |
download | cpython-630c8df5cf126594f8c1c4579c1888ca80a29d59.zip cpython-630c8df5cf126594f8c1c4579c1888ca80a29d59.tar.gz cpython-630c8df5cf126594f8c1c4579c1888ca80a29d59.tar.bz2 |
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.
Diffstat (limited to 'Include/internal')
-rw-r--r-- | Include/internal/pycore_pylifecycle.h | 4 | ||||
-rw-r--r-- | Include/internal/pycore_pystate.h | 12 |
2 files changed, 14 insertions, 2 deletions
diff --git a/Include/internal/pycore_pylifecycle.h b/Include/internal/pycore_pylifecycle.h index 4e4bbc2..7292349 100644 --- a/Include/internal/pycore_pylifecycle.h +++ b/Include/internal/pycore_pylifecycle.h @@ -33,7 +33,7 @@ PyAPI_FUNC(int) _Py_IsLocaleCoercionTarget(const char *ctype_loc); extern PyStatus _PyUnicode_Init(void); extern int _PyStructSequence_Init(void); -extern int _PyLong_Init(void); +extern int _PyLong_Init(PyThreadState *tstate); extern PyStatus _PyFaulthandler_Init(int enable); extern int _PyTraceMalloc_Init(int enable); extern PyObject * _PyBuiltin_Init(PyThreadState *tstate); @@ -76,7 +76,7 @@ extern void _PyGC_Fini(PyThreadState *tstate); extern void _PyType_Fini(void); extern void _Py_HashRandomization_Fini(void); extern void _PyUnicode_Fini(PyThreadState *tstate); -extern void _PyLong_Fini(void); +extern void _PyLong_Fini(PyThreadState *tstate); extern void _PyFaulthandler_Fini(void); extern void _PyHash_Fini(void); extern void _PyTraceMalloc_Fini(void); diff --git a/Include/internal/pycore_pystate.h b/Include/internal/pycore_pystate.h index aa2103f..b78ed69 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); |