-
-
Notifications
You must be signed in to change notification settings - Fork 32k
gh-121153: Change _PyLong_CompactValue() return type to int #121536
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
Conversation
vstinner
commented
Jul 9, 2024
•
edited by bedevere-app
bot
Loading
edited by bedevere-app
bot
- Issue: Incorrect use of _PyLong_CompactValue() #121153
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.
This is incomplete change. You need also to change the code that calls _PyLong_CompactValue()
(and simplify it).
When you're done making the requested changes, leave the comment: |
Ok, I updated _PyLong_CompactValue() usage as well. |
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.
@serhiy-storchaka: It would be nice if you could review this change since I'm not sure if it's correct.
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.
You need to update also other code. Take #121154 and replace Py_ssize_t
with int
. Then remove dead code.
Python/bltinmodule.c
Outdated
@@ -2644,8 +2644,7 @@ builtin_sum_impl(PyObject *module, PyObject *iterable, PyObject *start) | |||
b = PyLong_AsLongAndOverflow(item, &overflow); | |||
} | |||
if (overflow == 0 && | |||
(i_result >= 0 ? (b <= LONG_MAX - i_result) | |||
: (b >= LONG_MIN - i_result))) | |||
(i_result >= 0 ? (1 - i_result) : (1 - i_result))) |
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.
This code does not make sense.
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.
I don't understand this code.
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.
This is an overflow check for i_result += b
.
I'm not sure that I'm not the right person to implement this change. Maybe you should create your own PR and I abandon this PR. |
This PR changes PyUnstable_Long_CompactValue() return type. I documented that change. If it's an issue, we can leave PyUnstable_Long_CompactValue() return type unchanged. |
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.
Yes, it needs also changing PyUnstable_Long_CompactValue
which may be defined as an alias of _PyLong_CompactValue
.
Technically, it now LGTM. But we should ask @markshannon what he thinks about changing the return type. Why it was Py_ssize_t
at first place?
#121154 was merged instead. |