diff --git a/Lib/test/test_capi/test_long.py b/Lib/test/test_capi/test_long.py index d45ac75c822ea9..a371f634432b6d 100644 --- a/Lib/test/test_capi/test_long.py +++ b/Lib/test/test_capi/test_long.py @@ -211,9 +211,8 @@ def check_long_asintandoverflow(self, func, min_val, max_val): self.assertEqual(func(min_val - 1), (-1, -1)) self.assertEqual(func(max_val + 1), (-1, +1)) - - # CRASHES func(1.0) - # CRASHES func(NULL) + self.assertRaises(SystemError, func, None) + self.assertRaises(TypeError, func, 1.0) def test_long_asint(self): # Test PyLong_AsInt() diff --git a/Modules/_testlimitedcapi/long.c b/Modules/_testlimitedcapi/long.c index b9c35803b423c2..d896435c99a169 100644 --- a/Modules/_testlimitedcapi/long.c +++ b/Modules/_testlimitedcapi/long.c @@ -625,7 +625,8 @@ pylong_aslongandoverflow(PyObject *module, PyObject *arg) int overflow = UNINITIALIZED_INT; long value = PyLong_AsLongAndOverflow(arg, &overflow); if (value == -1 && PyErr_Occurred()) { - assert(overflow == -1); + // overflow can be 0 if a separate exception occurred + assert(overflow == -1 || overflow == 0); return NULL; } return Py_BuildValue("li", value, overflow); @@ -671,7 +672,8 @@ pylong_aslonglongandoverflow(PyObject *module, PyObject *arg) int overflow = UNINITIALIZED_INT; long long value = PyLong_AsLongLongAndOverflow(arg, &overflow); if (value == -1 && PyErr_Occurred()) { - assert(overflow == -1); + // overflow can be 0 if a separate exception occurred + assert(overflow == -1 || overflow == 0); return NULL; } return Py_BuildValue("Li", value, overflow);