Skip to content

Commit 0837699

Browse files
committed
keep check in stable ABI build
1 parent fe0076c commit 0837699

File tree

1 file changed

+13
-12
lines changed

1 file changed

+13
-12
lines changed

Objects/longobject.c

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -3611,28 +3611,29 @@ long_richcompare(PyObject *self, PyObject *other, int op)
36113611
Py_RETURN_RICHCOMPARE(result, 0, op);
36123612
}
36133613

3614-
#ifndef NDEBUG
3615-
static int _is_python_smallint(PyObject *op)
3614+
long_dealloc(PyObject *self)
36163615
{
3617-
PyLongObject *pylong = (PyLongObject*)op;
3616+
#ifdef Py_LIMITED_API
3617+
#ifndef Py_GIL_DISABLED
3618+
/* This should never get called, but we also don't want to SEGV if
3619+
* we accidentally decref small Ints out of existence. Instead,
3620+
* since small Ints are immortal, re-set the reference count.
3621+
*
3622+
* See PEP 683, section Accidental De-Immortalizing for details
3623+
*/
3624+
PyLongObject *pylong = (PyLongObject*)self;
36183625
if (pylong && _PyLong_IsCompact(pylong)) {
36193626
stwodigits ival = medium_value(pylong);
36203627
if (IS_SMALL_INT(ival)) {
36213628
PyLongObject *small_pylong = (PyLongObject *)get_small_int((sdigit)ival);
36223629
if (pylong == small_pylong) {
3623-
return 1;
3630+
_Py_SetImmortal(self);
3631+
return;
36243632
}
36253633
}
36263634
}
3627-
return 0;
3628-
}
36293635
#endif
3630-
3631-
static void
3632-
long_dealloc(PyObject *self)
3633-
{
3634-
// assert the small ints are not deallocated
3635-
assert(!_is_python_smallint(self));
3636+
#endif
36363637
Py_TYPE(self)->tp_free(self);
36373638
}
36383639

0 commit comments

Comments
 (0)