https://github.com/python/cpython/commit/6321e1ab4bd4cf6cbd610bc196fc5ff8761faa7d commit: 6321e1ab4bd4cf6cbd610bc196fc5ff8761faa7d branch: 3.13 author: Miss Islington (bot) <31488909+miss-isling...@users.noreply.github.com> committer: serhiy-storchaka <storch...@gmail.com> date: 2025-03-05T13:51:52+02:00 summary:
[3.13] gh-130824: Add tests for `NULL` in `PyLong_*AndOverflow` functions (GH-130828) (GH-130869) (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/_testlimitedcapi/long.c diff --git a/Lib/test/test_capi/test_long.py b/Lib/test/test_capi/test_long.py index b33edc0d0429f1..841de107a02821 100644 --- a/Lib/test/test_capi/test_long.py +++ b/Lib/test/test_capi/test_long.py @@ -210,9 +210,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 5953009b6ef9b7..e2af09d0840bba 100644 --- a/Modules/_testlimitedcapi/long.c +++ b/Modules/_testlimitedcapi/long.c @@ -625,7 +625,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); @@ -671,7 +671,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