Skip to content

gh-127119: Remove check on accidental deallocation of immortal objects for free-threaded build #127120

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 17 commits into from
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
Remove check on small ints in long_dealloc
  • Loading branch information
eendebakpt committed Nov 21, 2024
commit 19d64f005c46b67716424546ffb9dee21c08eeea
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
Loading