summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorPeter Bierma <zintensitydev@gmail.com>2025-03-05 08:58:39 (GMT)
committerGitHub <noreply@github.com>2025-03-05 08:58:39 (GMT)
commit90130807d9c5a55b2a64024f5dfbee4785b9a27c (patch)
treeb6ae16265c8ac8f1c09433b74d096d64fb888b9f
parente53d105872fafa77507ea33b7ecf0faddd4c3b60 (diff)
downloadcpython-90130807d9c5a55b2a64024f5dfbee4785b9a27c.zip
cpython-90130807d9c5a55b2a64024f5dfbee4785b9a27c.tar.gz
cpython-90130807d9c5a55b2a64024f5dfbee4785b9a27c.tar.bz2
gh-130824: Add tests for `NULL` in `PyLong_*AndOverflow` functions (GH-130828)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
-rw-r--r--Lib/test/test_capi/test_long.py5
-rw-r--r--Modules/_testlimitedcapi/long.c6
2 files changed, 6 insertions, 5 deletions
diff --git a/Lib/test/test_capi/test_long.py b/Lib/test/test_capi/test_long.py
index d45ac75..a371f63 100644
--- a/Lib/test/test_capi/test_long.py
+++ b/Lib/test/test_capi/test_long.py
@@ -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()
diff --git a/Modules/_testlimitedcapi/long.c b/Modules/_testlimitedcapi/long.c
index b9c3580..d896435 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);