File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -18,7 +18,7 @@ extern "C" {
1818# define Py_floats_MAXFREELIST 100
1919# define Py_complexes_MAXFREELIST 100
2020# define Py_ints_MAXFREELIST 100
21- # define PyLong_MAXSAVESIZE 8 // Keep freelists for all ints with less than this number of digits
21+ # define PyLong_MAXSAVESIZE 6 // Keep freelists for all ints with less than this number of digits
2222# define Py_slices_MAXFREELIST 1
2323# define Py_ranges_MAXFREELIST 6
2424# define Py_range_iters_MAXFREELIST 6
Original file line number Diff line number Diff line change @@ -163,6 +163,14 @@ maybe_freelist_push(PyObject *self)
163163 PyLongObject * op = (PyLongObject * )self ;
164164 Py_ssize_t ndigits = _PyLong_DigitCount (op );
165165
166+ /* A value that normalized to zero still owns a buffer of at least one
167+ * digit (long_alloc always allocates max(size, 1) digits), so it can be
168+ * reused as a 1-digit int. Bucketing it at index 0 would strand it:
169+ * long_alloc never requests bucket 0 (it clamps ndigits to >= 1). */
170+ if (ndigits == 0 ) {
171+ ndigits = 1 ;
172+ }
173+
166174 if (ndigits < PyLong_MAXSAVESIZE ) {
167175 return _Py_FREELIST_PUSH (ints [ndigits ], self , Py_ints_MAXFREELIST );
168176 }
@@ -349,7 +357,7 @@ medium_from_stwodigits(stwodigits x)
349357 if (!is_medium_int (x )) {
350358 return PyStackRef_NULL ;
351359 }
352- PyLongObject * v = (PyLongObject * )_Py_FREELIST_POP (PyLongObject , ints );
360+ PyLongObject * v = (PyLongObject * )_Py_FREELIST_POP (PyLongObject , ints [ 1 ] );
353361 if (v == NULL ) {
354362 v = PyObject_Malloc (sizeof (PyLongObject ));
355363 if (v == NULL ) {
You can’t perform that action at this time.
0 commit comments