1 #ifndef Py_INTERNAL_LONG_H 2 #define Py_INTERNAL_LONG_H 3 #ifdef __cplusplus 4 extern "C" { 5 #endif 6 7 #ifndef Py_BUILD_CORE 8 # error "this header requires Py_BUILD_CORE define" 9 #endif 10 11 #include "pycore_interp.h" // PyInterpreterState.small_ints 12 #include "pycore_pystate.h" // _PyThreadState_GET() 13 14 // Don't call this function but _PyLong_GetZero() and _PyLong_GetOne() __PyLong_GetSmallInt_internal(int value)15static inline PyObject* __PyLong_GetSmallInt_internal(int value) 16 { 17 PyInterpreterState *interp = _PyInterpreterState_GET(); 18 assert(-_PY_NSMALLNEGINTS <= value && value < _PY_NSMALLPOSINTS); 19 size_t index = _PY_NSMALLNEGINTS + value; 20 PyObject *obj = (PyObject*)interp->small_ints[index]; 21 // _PyLong_GetZero(), _PyLong_GetOne() and get_small_int() must not be 22 // called before _PyLong_Init() nor after _PyLong_Fini(). 23 assert(obj != NULL); 24 return obj; 25 } 26 27 // Return a borrowed reference to the zero singleton. 28 // The function cannot return NULL. _PyLong_GetZero(void)29static inline PyObject* _PyLong_GetZero(void) 30 { return __PyLong_GetSmallInt_internal(0); } 31 32 // Return a borrowed reference to the one singleton. 33 // The function cannot return NULL. _PyLong_GetOne(void)34static inline PyObject* _PyLong_GetOne(void) 35 { return __PyLong_GetSmallInt_internal(1); } 36 37 #ifdef __cplusplus 38 } 39 #endif 40 #endif /* !Py_INTERNAL_LONG_H */ 41