mirror of
https://github.com/python/cpython.git
synced 2025-08-16 14:50:43 +00:00
gh-130824: Add tests for NULL
in PyLong_*AndOverflow
functions (GH-130828)
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
This commit is contained in:
parent
e53d105872
commit
90130807d9
2 changed files with 6 additions and 5 deletions
|
@ -211,9 +211,8 @@ class LongTests(unittest.TestCase):
|
||||||
|
|
||||||
self.assertEqual(func(min_val - 1), (-1, -1))
|
self.assertEqual(func(min_val - 1), (-1, -1))
|
||||||
self.assertEqual(func(max_val + 1), (-1, +1))
|
self.assertEqual(func(max_val + 1), (-1, +1))
|
||||||
|
self.assertRaises(SystemError, func, None)
|
||||||
# CRASHES func(1.0)
|
self.assertRaises(TypeError, func, 1.0)
|
||||||
# CRASHES func(NULL)
|
|
||||||
|
|
||||||
def test_long_asint(self):
|
def test_long_asint(self):
|
||||||
# Test PyLong_AsInt()
|
# Test PyLong_AsInt()
|
||||||
|
|
|
@ -625,7 +625,8 @@ pylong_aslongandoverflow(PyObject *module, PyObject *arg)
|
||||||
int overflow = UNINITIALIZED_INT;
|
int overflow = UNINITIALIZED_INT;
|
||||||
long value = PyLong_AsLongAndOverflow(arg, &overflow);
|
long value = PyLong_AsLongAndOverflow(arg, &overflow);
|
||||||
if (value == -1 && PyErr_Occurred()) {
|
if (value == -1 && PyErr_Occurred()) {
|
||||||
assert(overflow == -1);
|
// overflow can be 0 if a separate exception occurred
|
||||||
|
assert(overflow == -1 || overflow == 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return Py_BuildValue("li", value, overflow);
|
return Py_BuildValue("li", value, overflow);
|
||||||
|
@ -671,7 +672,8 @@ pylong_aslonglongandoverflow(PyObject *module, PyObject *arg)
|
||||||
int overflow = UNINITIALIZED_INT;
|
int overflow = UNINITIALIZED_INT;
|
||||||
long long value = PyLong_AsLongLongAndOverflow(arg, &overflow);
|
long long value = PyLong_AsLongLongAndOverflow(arg, &overflow);
|
||||||
if (value == -1 && PyErr_Occurred()) {
|
if (value == -1 && PyErr_Occurred()) {
|
||||||
assert(overflow == -1);
|
// overflow can be 0 if a separate exception occurred
|
||||||
|
assert(overflow == -1 || overflow == 0);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
return Py_BuildValue("Li", value, overflow);
|
return Py_BuildValue("Li", value, overflow);
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue