mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-45953: Statically initialize the small ints. (gh-30092)
The array of small PyLong objects has been statically declared. Here I also statically initialize them. Consequently they are no longer initialized dynamically during runtime init. I've also moved them under a new sub-struct in _PyRuntimeState, in preparation for static allocation and initialization of other global objects. https://bugs.python.org/issue45953
This commit is contained in:
parent
cb589d1b6b
commit
121f1f893a
9 changed files with 360 additions and 81 deletions
|
@ -5832,29 +5832,6 @@ PyLong_GetInfo(void)
|
|||
|
||||
/* runtime lifecycle */
|
||||
|
||||
void
|
||||
_PyLong_InitGlobalObjects(PyInterpreterState *interp)
|
||||
{
|
||||
if (!_Py_IsMainInterpreter(interp)) {
|
||||
return;
|
||||
}
|
||||
|
||||
PyLongObject *small_ints = _PyLong_SMALL_INTS;
|
||||
if (small_ints[0].ob_base.ob_base.ob_refcnt != 0) {
|
||||
// Py_Initialize() must be running a second time.
|
||||
return;
|
||||
}
|
||||
|
||||
for (Py_ssize_t i=0; i < _PY_NSMALLNEGINTS + _PY_NSMALLPOSINTS; i++) {
|
||||
sdigit ival = (sdigit)i - _PY_NSMALLNEGINTS;
|
||||
int size = (ival < 0) ? -1 : ((ival == 0) ? 0 : 1);
|
||||
small_ints[i].ob_base.ob_base.ob_refcnt = 1;
|
||||
small_ints[i].ob_base.ob_base.ob_type = &PyLong_Type;
|
||||
small_ints[i].ob_base.ob_size = size;
|
||||
small_ints[i].ob_digit[0] = (digit)abs(ival);
|
||||
}
|
||||
}
|
||||
|
||||
PyStatus
|
||||
_PyLong_InitTypes(PyInterpreterState *interp)
|
||||
{
|
||||
|
@ -5875,9 +5852,3 @@ _PyLong_InitTypes(PyInterpreterState *interp)
|
|||
|
||||
return _PyStatus_OK();
|
||||
}
|
||||
|
||||
void
|
||||
_PyLong_Fini(PyInterpreterState *interp)
|
||||
{
|
||||
(void)interp;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue