diff options
author | Mark Shannon <mark@hotpy.org> | 2021-10-28 16:35:43 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-10-28 16:35:43 (GMT) |
commit | 4fc68560ea0d506c152a82c48c162bfe002f34a8 (patch) | |
tree | 025efe26309526cdb86521c1f8f95ad106ff939f /Objects/longobject.c | |
parent | 13d9205f4057eeeef80a25d410ad123876dc60cd (diff) | |
download | cpython-4fc68560ea0d506c152a82c48c162bfe002f34a8.zip cpython-4fc68560ea0d506c152a82c48c162bfe002f34a8.tar.gz cpython-4fc68560ea0d506c152a82c48c162bfe002f34a8.tar.bz2 |
Store actual ints, not pointers to them in the interpreter state. (GH-29274)
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r-- | Objects/longobject.c | 21 |
1 files changed, 6 insertions, 15 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c index 5325d18..b7392e5 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -5827,24 +5827,17 @@ PyLong_GetInfo(void) return int_info; } -int +void _PyLong_Init(PyInterpreterState *interp) { for (Py_ssize_t i=0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) { sdigit ival = (sdigit)i - NSMALLNEGINTS; int size = (ival < 0) ? -1 : ((ival == 0) ? 0 : 1); - - PyLongObject *v = _PyLong_New(1); - if (!v) { - return -1; - } - - Py_SET_SIZE(v, size); - v->ob_digit[0] = (digit)abs(ival); - - interp->small_ints[i] = v; + interp->small_ints[i].ob_base.ob_base.ob_refcnt = 1; + interp->small_ints[i].ob_base.ob_base.ob_type = &PyLong_Type; + interp->small_ints[i].ob_base.ob_size = size; + interp->small_ints[i].ob_digit[0] = (digit)abs(ival); } - return 0; } @@ -5863,7 +5856,5 @@ _PyLong_InitTypes(void) void _PyLong_Fini(PyInterpreterState *interp) { - for (Py_ssize_t i = 0; i < NSMALLNEGINTS + NSMALLPOSINTS; i++) { - Py_CLEAR(interp->small_ints[i]); - } + (void)interp; } |