Skip to content

Commit 6321e1a

Browse files
miss-islingtonZeroIntensityskirpichev
authored
[3.13] gh-130824: Add tests for NULL in PyLong_*AndOverflow functions (GH-130828) (GH-130869)
(cherry picked from commit 9013080) Co-authored-by: Peter Bierma <[email protected]> Co-authored-by: Sergey B Kirpichev <[email protected]>
1 parent ffef9b0 commit 6321e1a

File tree

2 files changed

+4
-5
lines changed

2 files changed

+4
-5
lines changed

Lib/test/test_capi/test_long.py

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -210,9 +210,8 @@ def check_long_asintandoverflow(self, func, min_val, max_val):
210210

211211
self.assertEqual(func(min_val - 1), (-1, -1))
212212
self.assertEqual(func(max_val + 1), (-1, +1))
213-
214-
# CRASHES func(1.0)
215-
# CRASHES func(NULL)
213+
self.assertRaises(SystemError, func, None)
214+
self.assertRaises(TypeError, func, 1.0)
216215

217216
def test_long_asint(self):
218217
# Test PyLong_AsInt()

Modules/_testlimitedcapi/long.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -625,7 +625,7 @@ pylong_aslongandoverflow(PyObject *module, PyObject *arg)
625625
int overflow = UNINITIALIZED_INT;
626626
long value = PyLong_AsLongAndOverflow(arg, &overflow);
627627
if (value == -1 && PyErr_Occurred()) {
628-
assert(overflow == -1);
628+
assert(overflow == 0);
629629
return NULL;
630630
}
631631
return Py_BuildValue("li", value, overflow);
@@ -671,7 +671,7 @@ pylong_aslonglongandoverflow(PyObject *module, PyObject *arg)
671671
int overflow = UNINITIALIZED_INT;
672672
long long value = PyLong_AsLongLongAndOverflow(arg, &overflow);
673673
if (value == -1 && PyErr_Occurred()) {
674-
assert(overflow == -1);
674+
assert(overflow == 0);
675675
return NULL;
676676
}
677677
return Py_BuildValue("Li", value, overflow);

0 commit comments

Comments
 (0)