Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 2 additions & 3 deletions Lib/test/test_capi/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -211,9 +211,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()
Expand Down
6 changes: 4 additions & 2 deletions Modules/_testlimitedcapi/long.c
Original file line number Diff line number Diff line change
Expand Up @@ -625,7 +625,8 @@ pylong_aslongandoverflow(PyObject *module, PyObject *arg)
int overflow = UNINITIALIZED_INT;
long value = PyLong_AsLongAndOverflow(arg, &overflow);
if (value == -1 && PyErr_Occurred()) {
assert(overflow == -1);
// overflow can be 0 if a separate exception occurred
assert(overflow == -1 || overflow == 0);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is not it always 0?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Not with OverflowError.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah, OverflowError is -1 and then other exceptions (only SystemError?) are 0.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

only SystemError?

No, TypeError too.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

OverflowError is not raised. In case of an integer overflow, *overflow should be 1 or -1.

Isn't it always 0 here?

return NULL;
}
return Py_BuildValue("li", value, overflow);
Expand Down Expand Up @@ -671,7 +672,8 @@ 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);
// overflow can be 0 if a separate exception occurred
assert(overflow == -1 || overflow == 0);
return NULL;
}
return Py_BuildValue("Li", value, overflow);
Expand Down
Loading