Skip to content

Commit 8fe011a

Browse files
encukouZeroIntensityskirpichev
authored
[3.12] gh-130824: Add tests for NULL in PyLong_*AndOverflow functions (GH-130828) (GH-130876)
(cherry picked from commit 9013080) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
1 parent 919300e commit 8fe011a

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
@@ -208,9 +208,8 @@ def check_long_asintandoverflow(self, func, min_val, max_val):
208208

209209
self.assertEqual(func(min_val - 1), (-1, -1))
210210
self.assertEqual(func(max_val + 1), (-1, +1))
211-
212-
# CRASHES func(1.0)
213-
# CRASHES func(NULL)
211+
self.assertRaises(SystemError, func, None)
212+
self.assertRaises(TypeError, func, 1.0)
214213

215214
def test_long_aslong(self):
216215
# Test PyLong_AsLong() and PyLong_FromLong()

Modules/_testcapi/long.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -629,7 +629,7 @@ pylong_aslongandoverflow(PyObject *module, PyObject *arg)
629629
int overflow = UNINITIALIZED_INT;
630630
long value = PyLong_AsLongAndOverflow(arg, &overflow);
631631
if (value == -1 && PyErr_Occurred()) {
632-
assert(overflow == -1);
632+
assert(overflow == 0);
633633
return NULL;
634634
}
635635
return Py_BuildValue("li", value, overflow);
@@ -675,7 +675,7 @@ pylong_aslonglongandoverflow(PyObject *module, PyObject *arg)
675675
int overflow = UNINITIALIZED_INT;
676676
long long value = PyLong_AsLongLongAndOverflow(arg, &overflow);
677677
if (value == -1 && PyErr_Occurred()) {
678-
assert(overflow == -1);
678+
assert(overflow == 0);
679679
return NULL;
680680
}
681681
return Py_BuildValue("Li", value, overflow);

0 commit comments

Comments
 (0)