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

(cherry picked from commit 90130807d9)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
This commit is contained in:
Miss Islington (bot) 2025-03-05 12:51:52 +01:00 committed by GitHub
parent ffef9b0440
commit 6321e1ab4b
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 4 additions and 5 deletions

View file

@ -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()

View file

@ -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);