Skip to content
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
Prev Previous commit
Next Next commit
keep check in stable ABI build
  • Loading branch information
eendebakpt committed Nov 24, 2024
commit 08376995b468ecaa8c85965cef0af11c9f82828b
25 changes: 13 additions & 12 deletions Objects/longobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -3611,28 +3611,29 @@ long_richcompare(PyObject *self, PyObject *other, int op)
Py_RETURN_RICHCOMPARE(result, 0, op);
}

#ifndef NDEBUG
static int _is_python_smallint(PyObject *op)
long_dealloc(PyObject *self)
{
PyLongObject *pylong = (PyLongObject*)op;
#ifdef Py_LIMITED_API
#ifndef Py_GIL_DISABLED
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm not sure it's possible for us to know when we're using the limited API. Py_LIMITED_API is something that affects Python.h at the compile-time of an extension module, but this happens during the compilation of CPython, so it will never be true.

/* 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)) {
stwodigits ival = medium_value(pylong);
if (IS_SMALL_INT(ival)) {
PyLongObject *small_pylong = (PyLongObject *)get_small_int((sdigit)ival);
if (pylong == small_pylong) {
return 1;
_Py_SetImmortal(self);
return;
}
}
}
return 0;
}
#endif

static void
long_dealloc(PyObject *self)
{
// assert the small ints are not deallocated
assert(!_is_python_smallint(self));
#endif
Py_TYPE(self)->tp_free(self);
}

Expand Down