Skip to content

Commit 4117c54

Browse files
committed
rewrite assert
1 parent 19d64f0 commit 4117c54

File tree

1 file changed

+17
-5
lines changed

1 file changed

+17
-5
lines changed

Objects/longobject.c

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

3614+
static int _is_python_smallint(PyObject *op)
3615+
{
3616+
PyLongObject *pylong = (PyLongObject*)op;
3617+
if (pylong && _PyLong_IsCompact(pylong)) {
3618+
stwodigits ival = medium_value(pylong);
3619+
if (IS_SMALL_INT(ival)) {
3620+
PyLongObject *small_pylong = (PyLongObject *)get_small_int((sdigit)ival);
3621+
if (pylong == small_pylong) {
3622+
return 1;
3623+
}
3624+
}
3625+
}
3626+
return 0;
3627+
}
3628+
36143629
static void
36153630
long_dealloc(PyObject *self)
36163631
{
3617-
PyLongObject *pylong = (PyLongObject*)self;
3618-
if (_PyLong_IsCompact(pylong)) {
3619-
// assert the small ints are not deallocated
3620-
assert (!(PyLong_CheckExact(self) && IS_SMALL_INT(medium_value(pylong))));
3621-
}
3632+
// assert the small ints are not deallocated
3633+
assert(!_is_python_smallint(self));
36223634
Py_TYPE(self)->tp_free(self);
36233635
}
36243636

0 commit comments

Comments
 (0)