Skip to content
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

gh-127119: Remove check on small ints in long_dealloc #127120

Open
wants to merge 16 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 4 commits
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
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove redundant check on small ints in ``long_dealloc``
eendebakpt marked this conversation as resolved.
Show resolved Hide resolved
20 changes: 11 additions & 9 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3611,24 +3611,26 @@
Py_RETURN_RICHCOMPARE(result, 0, op);
}

static void
ZeroIntensity marked this conversation as resolved.
Show resolved Hide resolved
long_dealloc(PyObject *self)
static int _is_python_smallint(PyObject *op)

Check warning on line 3614 in Objects/longobject.c

View workflow job for this annotation

GitHub Actions / Address sanitizer (ubuntu-24.04)

‘_is_python_smallint’ defined but not used [-Wunused-function]
{
/* 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;
PyLongObject *pylong = (PyLongObject*)op;
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;
return 1;
}
}
}
return 0;
}

static void
long_dealloc(PyObject *self)
{
// assert the small ints are not deallocated
assert(!_is_python_smallint(self));
ZeroIntensity marked this conversation as resolved.
Show resolved Hide resolved
Py_TYPE(self)->tp_free(self);
}

Expand Down
Loading