-
-
Notifications
You must be signed in to change notification settings - Fork 31.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
gh-130824: Add tests for NULL
in PyLong_*AndOverflow
functions
#130828
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM. 👍
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Few nitpicks, feel free to ignore.
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Lib/test/test_capi/test_long.py
Outdated
@@ -211,9 +211,9 @@ 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)) | |||
self.assertRaises(SystemError, func, None) | |||
|
|||
# CRASHES func(1.0) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does it really crash?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, it doesn't: "If any other exception occurs set *overflow to 0 and return -1 as usual." TypeError will be here.
@@ -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 seperate exception occurred | |||
assert(overflow == -1 || overflow == 0); |
There was a problem hiding this comment.
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
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not with OverflowError.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
one grammar nitpick
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
Thanks @ZeroIntensity for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12. |
Thanks @ZeroIntensity for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13. |
Sorry, @ZeroIntensity and @encukou, I could not cleanly backport this to
|
…ons (pythonGH-130828) (cherry picked from commit 9013080) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
GH-130869 is a backport of this pull request to the 3.13 branch. |
@encukou Should I make the manual backport to 3.12? I'm not sure it's worth backporting to prevent conflicts if there's already a conflict. |
It will help to backport future tests. It will help to ensure that no regressions be introduced in old versions. See also #130871. You can include that change in the backports. |
… functions (pythonGH-130828) (cherry picked from commit 9013080) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
GH-130876 is a backport of this pull request to the 3.12 branch. |
Sorry, I did it before I saw your message |
… functions (pythonGH-130828) (cherry picked from commit 9013080) Co-authored-by: Peter Bierma <zintensitydev@gmail.com> Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
…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>
It crashed before because the assertion didn't realize that
overflow
would be 0 and not -1 inSystemError
cases.