diff --git a/Objects/longobject.c b/Objects/longobject.c index dc19d488530de0..3d16a5d1e53d9a 100644 --- a/Objects/longobject.c +++ b/Objects/longobject.c @@ -43,7 +43,7 @@ static inline void _Py_DECREF_INT(PyLongObject *op) { assert(PyLong_CheckExact(op)); - _Py_DECREF_SPECIALIZED((PyObject *)op, (destructor)PyObject_Free); // needs to be converted to freelist? + _Py_DECREF_SPECIALIZED((PyObject *)op, (destructor) _PyLong_ExactDealloc); } static inline int @@ -222,7 +222,9 @@ _PyLong_FromMedium(sdigit x) assert(!IS_SMALL_INT(x)); assert(is_medium_int(x)); - PyLongObject *v = _Py_FREELIST_POP(PyLongObject, ints); + // The small int cache is incompatible with _Py_NewReference which is called + // by _Py_FREELIST_POP. + PyLongObject *v = (PyLongObject *)_Py_FREELIST_POP_MEM(ints); if (v == NULL) { v = PyObject_Malloc(sizeof(PyLongObject)); if (v == NULL) { @@ -3618,13 +3620,13 @@ long_richcompare(PyObject *self, PyObject *other, int op) void _PyLong_ExactDealloc(PyObject *self) { - assert(PyLong_CheckExact(self)); - - if (_PyLong_IsCompact((PyLongObject *)self)) { - _Py_FREELIST_FREE(ints, self, PyObject_Free); - return; + if (PyLong_CheckExact(self)) { + if (_PyLong_IsCompact((PyLongObject *)self)) { + _Py_FREELIST_FREE(ints, self, PyObject_Free); + return; + } } - PyObject_Free(self); + Py_TYPE(self)->tp_free(self); } static void diff --git a/Python/bytecodes.c b/Python/bytecodes.c index f24ca0f62755d9..7d61fc48e21ea4 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -516,7 +516,7 @@ dummy_func( STAT_INC(BINARY_OP, hit); PyObject *res_o = _PyLong_Multiply((PyLongObject *)left_o, (PyLongObject *)right_o); PyStackRef_CLOSE_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc); - PyStackRef_CLOSE_SPECIALIZED(left, (destructor)PyObject_Free); // needs to be converted to freelist + PyStackRef_CLOSE_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc); INPUTS_DEAD(); ERROR_IF(res_o == NULL, error); res = PyStackRef_FromPyObjectSteal(res_o); @@ -529,7 +529,7 @@ dummy_func( STAT_INC(BINARY_OP, hit); PyObject *res_o = _PyLong_Add((PyLongObject *)left_o, (PyLongObject *)right_o); PyStackRef_CLOSE_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc); - PyStackRef_CLOSE_SPECIALIZED(left, (destructor)PyObject_Free); // needs to be converted to freelist + PyStackRef_CLOSE_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc); INPUTS_DEAD(); ERROR_IF(res_o == NULL, error); res = PyStackRef_FromPyObjectSteal(res_o); @@ -542,7 +542,7 @@ dummy_func( STAT_INC(BINARY_OP, hit); PyObject *res_o = _PyLong_Subtract((PyLongObject *)left_o, (PyLongObject *)right_o); PyStackRef_CLOSE_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc); - PyStackRef_CLOSE_SPECIALIZED(left, (destructor)PyObject_Free); // needs to be converted to freelist + PyStackRef_CLOSE_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc); INPUTS_DEAD(); ERROR_IF(res_o == NULL, error); res = PyStackRef_FromPyObjectSteal(res_o); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 2a0e07fb1e8c2b..73be53d5a2ce46 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -627,7 +627,7 @@ STAT_INC(BINARY_OP, hit); PyObject *res_o = _PyLong_Multiply((PyLongObject *)left_o, (PyLongObject *)right_o); PyStackRef_CLOSE_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc); - PyStackRef_CLOSE_SPECIALIZED(left, (destructor)PyObject_Free); // needs to be converted to freelist + PyStackRef_CLOSE_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc); if (res_o == NULL) JUMP_TO_ERROR(); res = PyStackRef_FromPyObjectSteal(res_o); stack_pointer[-2] = res; @@ -647,7 +647,7 @@ STAT_INC(BINARY_OP, hit); PyObject *res_o = _PyLong_Add((PyLongObject *)left_o, (PyLongObject *)right_o); PyStackRef_CLOSE_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc); - PyStackRef_CLOSE_SPECIALIZED(left, (destructor)PyObject_Free); // needs to be converted to freelist + PyStackRef_CLOSE_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc); if (res_o == NULL) JUMP_TO_ERROR(); res = PyStackRef_FromPyObjectSteal(res_o); stack_pointer[-2] = res; @@ -667,7 +667,7 @@ STAT_INC(BINARY_OP, hit); PyObject *res_o = _PyLong_Subtract((PyLongObject *)left_o, (PyLongObject *)right_o); PyStackRef_CLOSE_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc); - PyStackRef_CLOSE_SPECIALIZED(left, (destructor)PyObject_Free); // needs to be converted to freelist + PyStackRef_CLOSE_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc); if (res_o == NULL) JUMP_TO_ERROR(); res = PyStackRef_FromPyObjectSteal(res_o); stack_pointer[-2] = res; diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index e25d8b4785125c..1fb36cdde1a1c2 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -119,7 +119,7 @@ STAT_INC(BINARY_OP, hit); PyObject *res_o = _PyLong_Add((PyLongObject *)left_o, (PyLongObject *)right_o); PyStackRef_CLOSE_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc); - PyStackRef_CLOSE_SPECIALIZED(left, (destructor)PyObject_Free); // needs to be converted to freelist + PyStackRef_CLOSE_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc); if (res_o == NULL) goto pop_2_error; res = PyStackRef_FromPyObjectSteal(res_o); } @@ -288,7 +288,7 @@ STAT_INC(BINARY_OP, hit); PyObject *res_o = _PyLong_Multiply((PyLongObject *)left_o, (PyLongObject *)right_o); PyStackRef_CLOSE_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc); - PyStackRef_CLOSE_SPECIALIZED(left, (destructor)PyObject_Free); // needs to be converted to freelist + PyStackRef_CLOSE_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc); if (res_o == NULL) goto pop_2_error; res = PyStackRef_FromPyObjectSteal(res_o); } @@ -359,7 +359,7 @@ STAT_INC(BINARY_OP, hit); PyObject *res_o = _PyLong_Subtract((PyLongObject *)left_o, (PyLongObject *)right_o); PyStackRef_CLOSE_SPECIALIZED(right, (destructor)_PyLong_ExactDealloc); - PyStackRef_CLOSE_SPECIALIZED(left, (destructor)PyObject_Free); // needs to be converted to freelist + PyStackRef_CLOSE_SPECIALIZED(left, (destructor)_PyLong_ExactDealloc); if (res_o == NULL) goto pop_2_error; res = PyStackRef_FromPyObjectSteal(res_o); }