44
55#include "Python.h"
66#include "pycore_bitutils.h" // _Py_popcount32()
7- #include "pycore_interp .h" // _PY_NSMALLPOSINTS
8- #include "pycore_long.h" // __PyLong_GetSmallInt_internal()
7+ #include "pycore_runtime .h" // _PY_NSMALLPOSINTS
8+ #include "pycore_long.h" // _Py_SmallInts
99#include "pycore_object.h" // _PyObject_InitVar()
1010#include "pycore_pystate.h" // _Py_IsMainInterpreter()
1111
@@ -20,9 +20,6 @@ class int "PyObject *" "&PyLong_Type"
2020[clinic start generated code]*/
2121/*[clinic end generated code: output=da39a3ee5e6b4b0d input=ec0275e3422a36e3]*/
2222
23- #define NSMALLNEGINTS _PY_NSMALLNEGINTS
24- #define NSMALLPOSINTS _PY_NSMALLPOSINTS
25-
2623_Py_IDENTIFIER (little );
2724_Py_IDENTIFIER (big );
2825
@@ -37,8 +34,8 @@ medium_value(PyLongObject *x)
3734 return ((stwodigits )Py_SIZE (x )) * x -> ob_digit [0 ];
3835}
3936
40- #define IS_SMALL_INT (ival ) (-NSMALLNEGINTS <= (ival) && (ival) < NSMALLPOSINTS )
41- #define IS_SMALL_UINT (ival ) ((ival) < NSMALLPOSINTS )
37+ #define IS_SMALL_INT (ival ) (-_PY_NSMALLNEGINTS <= (ival) && (ival) < _PY_NSMALLPOSINTS )
38+ #define IS_SMALL_UINT (ival ) ((ival) < _PY_NSMALLPOSINTS )
4239
4340static inline int is_medium_int (stwodigits x )
4441{
@@ -51,7 +48,7 @@ static PyObject *
5148get_small_int (sdigit ival )
5249{
5350 assert (IS_SMALL_INT (ival ));
54- PyObject * v = __PyLong_GetSmallInt_internal ( ival ) ;
51+ PyObject * v = ( PyObject * ) & _PyRuntime . small_ints [ _PY_NSMALLNEGINTS + ival ] ;
5552 Py_INCREF (v );
5653 return v ;
5754}
@@ -5830,17 +5827,18 @@ PyLong_GetInfo(void)
58305827void
58315828_PyLong_Init (PyInterpreterState * interp )
58325829{
5833- for (Py_ssize_t i = 0 ; i < NSMALLNEGINTS + NSMALLPOSINTS ; i ++ ) {
5834- sdigit ival = (sdigit )i - NSMALLNEGINTS ;
5835- int size = (ival < 0 ) ? -1 : ((ival == 0 ) ? 0 : 1 );
5836- interp -> small_ints [i ].ob_base .ob_base .ob_refcnt = 1 ;
5837- interp -> small_ints [i ].ob_base .ob_base .ob_type = & PyLong_Type ;
5838- interp -> small_ints [i ].ob_base .ob_size = size ;
5839- interp -> small_ints [i ].ob_digit [0 ] = (digit )abs (ival );
5830+ if (_PyRuntime .small_ints [0 ].ob_base .ob_base .ob_refcnt == 0 ) {
5831+ for (Py_ssize_t i = 0 ; i < _PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS ; i ++ ) {
5832+ sdigit ival = (sdigit )i - _PY_NSMALLNEGINTS ;
5833+ int size = (ival < 0 ) ? -1 : ((ival == 0 ) ? 0 : 1 );
5834+ _PyRuntime .small_ints [i ].ob_base .ob_base .ob_refcnt = 1 ;
5835+ _PyRuntime .small_ints [i ].ob_base .ob_base .ob_type = & PyLong_Type ;
5836+ _PyRuntime .small_ints [i ].ob_base .ob_size = size ;
5837+ _PyRuntime .small_ints [i ].ob_digit [0 ] = (digit )abs (ival );
5838+ }
58405839 }
58415840}
58425841
5843-
58445842int
58455843_PyLong_InitTypes (void )
58465844{
0 commit comments