https://github.com/python/cpython/commit/8fe011af3864300df9b312584be449b3eb3e4bf8
commit: 8fe011af3864300df9b312584be449b3eb3e4bf8
branch: 3.12
author: Petr Viktorin <encu...@gmail.com>
committer: serhiy-storchaka <storch...@gmail.com>
date: 2025-03-05T13:52:40+02:00
summary:

[3.12] gh-130824: Add tests for NULL in PyLong_*AndOverflow functions 
(GH-130828) (GH-130876)

(cherry picked from commit 90130807d9c5a55b2a64024f5dfbee4785b9a27c)

Co-authored-by: Peter Bierma <zintensity...@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpic...@gmail.com>

files:
M Lib/test/test_capi/test_long.py
M Modules/_testcapi/long.c

diff --git a/Lib/test/test_capi/test_long.py b/Lib/test/test_capi/test_long.py
index 18507ed7c3bfec..05b3a7ebd63d64 100644
--- a/Lib/test/test_capi/test_long.py
+++ b/Lib/test/test_capi/test_long.py
@@ -208,9 +208,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_aslong(self):
         # Test PyLong_AsLong() and PyLong_FromLong()
diff --git a/Modules/_testcapi/long.c b/Modules/_testcapi/long.c
index 9c5a0e386759e7..16eb437ffea178 100644
--- a/Modules/_testcapi/long.c
+++ b/Modules/_testcapi/long.c
@@ -629,7 +629,7 @@ pylong_aslongandoverflow(PyObject *module, PyObject *arg)
     int overflow = UNINITIALIZED_INT;
     long value = PyLong_AsLongAndOverflow(arg, &overflow);
     if (value == -1 && PyErr_Occurred()) {
-        assert(overflow == -1);
+        assert(overflow == 0);
         return NULL;
     }
     return Py_BuildValue("li", value, overflow);
@@ -675,7 +675,7 @@ 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);
+        assert(overflow == 0);
         return NULL;
     }
     return Py_BuildValue("Li", value, overflow);

_______________________________________________
Python-checkins mailing list -- python-checkins@python.org
To unsubscribe send an email to python-checkins-le...@python.org
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: arch...@mail-archive.com

Reply via email to