Skip to content
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

Merged
merged 4 commits into from
Mar 5, 2025

Conversation

ZeroIntensity
Copy link
Member

@ZeroIntensity ZeroIntensity commented Mar 4, 2025

It crashed before because the assertion didn't realize that overflow would be 0 and not -1 in SystemError cases.

Copy link
Member

@serhiy-storchaka serhiy-storchaka left a comment

Choose a reason for hiding this comment

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

LGTM. 👍

Copy link
Member

@skirpichev skirpichev left a 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>
@@ -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)
Copy link
Member

Choose a reason for hiding this comment

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

Does it really crash?

Copy link
Member

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);
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
Member

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
Member

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?

@serhiy-storchaka serhiy-storchaka self-requested a review March 4, 2025 15:50
@skirpichev skirpichev self-requested a review March 5, 2025 00:26
Copy link
Member

@skirpichev skirpichev left a 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>
@encukou encukou merged commit 9013080 into python:main Mar 5, 2025
41 checks passed
@encukou encukou added needs backport to 3.12 bug and security fixes needs backport to 3.13 bugs and security fixes labels Mar 5, 2025
@miss-islington-app
Copy link

Thanks @ZeroIntensity for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.12.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Thanks @ZeroIntensity for the PR, and @encukou for merging it 🌮🎉.. I'm working now to backport this PR to: 3.13.
🐍🍒⛏🤖

@miss-islington-app
Copy link

Sorry, @ZeroIntensity and @encukou, I could not cleanly backport this to 3.12 due to a conflict.
Please backport using cherry_picker on command line.

cherry_picker 90130807d9c5a55b2a64024f5dfbee4785b9a27c 3.12

miss-islington pushed a commit to miss-islington/cpython that referenced this pull request Mar 5, 2025
…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>
@bedevere-app
Copy link

bedevere-app bot commented Mar 5, 2025

GH-130869 is a backport of this pull request to the 3.13 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.13 bugs and security fixes label Mar 5, 2025
@ZeroIntensity ZeroIntensity deleted the add-pylong-null-checks branch March 5, 2025 10:24
@ZeroIntensity
Copy link
Member Author

@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.

@serhiy-storchaka
Copy link
Member

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.

encukou pushed a commit to encukou/cpython that referenced this pull request Mar 5, 2025
… 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>
@bedevere-app
Copy link

bedevere-app bot commented Mar 5, 2025

GH-130876 is a backport of this pull request to the 3.12 branch.

@bedevere-app bedevere-app bot removed the needs backport to 3.12 bug and security fixes label Mar 5, 2025
@encukou
Copy link
Member

encukou commented Mar 5, 2025

Should I make the manual backport to 3.12?

Sorry, I did it before I saw your message

ZeroIntensity added a commit to ZeroIntensity/cpython that referenced this pull request Mar 5, 2025
… 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>
serhiy-storchaka pushed a commit that referenced this pull request Mar 5, 2025
…ions (GH-130828) (GH-130869)

(cherry picked from commit 9013080)

Co-authored-by: Peter Bierma <zintensitydev@gmail.com>
Co-authored-by: Sergey B Kirpichev <skirpichev@gmail.com>
serhiy-storchaka pushed a commit that referenced this pull request Mar 5, 2025
…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>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
skip news tests Tests in the Lib/test dir
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants