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 all 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 @@
Slightly optimize the :class:`int` deallocator by removing a redundant check.
6 changes: 6 additions & 0 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3614,9 +3614,13 @@ long_richcompare(PyObject *self, PyObject *other, int op)
static void
ZeroIntensity marked this conversation as resolved.
Show resolved Hide resolved
long_dealloc(PyObject *self)
{
#if SIZEOF_VOID_P <= 4 /* same condition as in refcount.h */
#ifndef Py_GIL_DISABLED
/* 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.
*
* See PEP 683, section Accidental De-Immortalizing for details
*/
PyLongObject *pylong = (PyLongObject*)self;
if (pylong && _PyLong_IsCompact(pylong)) {
Expand All @@ -3629,6 +3633,8 @@ long_dealloc(PyObject *self)
}
}
}
#endif
#endif
Py_TYPE(self)->tp_free(self);
}

Expand Down
Loading