Skip to content

Commit

Permalink
Remove check on small ints in long_dealloc
Browse files Browse the repository at this point in the history
  • Loading branch information
eendebakpt committed Nov 21, 2024
1 parent 9dabace commit 19d64f0
Showing 1 changed file with 3 additions and 13 deletions.
16 changes: 3 additions & 13 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3614,20 +3614,10 @@ long_richcompare(PyObject *self, PyObject *other, int op)
static void
long_dealloc(PyObject *self)
{
/* This should never get called, but we also don't want to SEGV if
* we accidentally decref small Ints out of existence. Instead,
* since small Ints are immortal, re-set the reference count.
*/
PyLongObject *pylong = (PyLongObject*)self;
if (pylong && _PyLong_IsCompact(pylong)) {
stwodigits ival = medium_value(pylong);
if (IS_SMALL_INT(ival)) {
PyLongObject *small_pylong = (PyLongObject *)get_small_int((sdigit)ival);
if (pylong == small_pylong) {
_Py_SetImmortal(self);
return;
}
}
if (_PyLong_IsCompact(pylong)) {
// assert the small ints are not deallocated
assert (!(PyLong_CheckExact(self) && IS_SMALL_INT(medium_value(pylong))));
}
Py_TYPE(self)->tp_free(self);
}
Expand Down

0 comments on commit 19d64f0

Please sign in to comment.