]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
gh-130824: Add tests for `NULL` in `PyLong_*AndOverflow` functions (GH-130828)
authorPeter Bierma <zintensitydev@gmail.com>
Wed, 5 Mar 2025 08:58:39 +0000 (03:58 -0500)
committerGitHub <noreply@github.com>
Wed, 5 Mar 2025 08:58:39 +0000 (09:58 +0100)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Lib/test/test_capi/test_long.py
Modules/_testlimitedcapi/long.c

index d45ac75c822ea9bb725dd78f2c8c49486f4a4141..a371f634432b6d9e26b810162bca51ae771a1da1 100644 (file)
@@ -211,9 +211,8 @@ class LongTests(unittest.TestCase):
 
         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()
index b9c35803b423c22cfa040ac4f3b8c1c0ca678e25..d896435c99a169c5cb1d8b721db40fd47e0e3f85 100644 (file)
@@ -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);