-
-
Notifications
You must be signed in to change notification settings - Fork 30.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-121153: Fix some errors with use of _PyLong_CompactValue() #121154
gh-121153: Fix some errors with use of _PyLong_CompactValue() #121154
Conversation
serhiy-storchaka
commented
Jun 29, 2024
•
edited
Loading
edited
- The result has type Py_ssize_t, not intptr_t.
- Type cast between unsigned and signed integer types should be explicit.
- Downcasting should be explicit.
- Fix integer overflow check in sum().
- Issue: Incorrect use of _PyLong_CompactValue() #121153
0c05044
to
0bc15a8
Compare
* The result has type Py_ssize_t, not intptr_t. * Type cast between unsigned and signdet integer types should be explicit. * Downcasting should be explicit.
0bc15a8
to
5a6872f
Compare
…e-type-cast' into _PyLong_CompactValue-type-cast
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.
Can _PyLong_CompactValue() really be outside [LONG_MIN; LONG_MAX] range? It should be a single digit in the range [-PyLong_BASE; PyLong_BASE] and should even fit into a C int.
Why not changing _PyLong_CompactValue() return type to long? It would make this code way simpler.
(I'm not sure, correct me if I'm wrong.) |
I do not know. But currently it is defined as returning It perhaps does not make difference for most or all currently supported platforms, but it is easier to write the code that handles all theoretically possible cases than hope that the simpler code which works on your platform will work the same way on different platforms with different compilers. |
@markshannon: Is there a reason for _PyLong_CompactValue() return type to be |
Returning |
I created PR gh-121536 to only do that (don't try to simply code using _PyLong_CompactValue()). |
Yes. And please don't use |
Changing the returning type to |
…lue() (pythonGH-121154) * The result has type Py_ssize_t, not intptr_t. * Type cast between unsigned and signdet integer types should be explicit. * Downcasting should be explicit. * Fix integer overflow check in sum(). (cherry picked from commit 1801545) Co-authored-by: Serhiy Storchaka <[email protected]>
…lue() (pythonGH-121154) * The result has type Py_ssize_t, not intptr_t. * Type cast between unsigned and signdet integer types should be explicit. * Downcasting should be explicit. * Fix integer overflow check in sum(). (cherry picked from commit 1801545) Co-authored-by: Serhiy Storchaka <[email protected]>
GH-121900 is a backport of this pull request to the 3.13 branch. |
GH-121901 is a backport of this pull request to the 3.12 branch. |
…ythonGH-121154) * The result has type Py_ssize_t, not intptr_t. * Type cast between unsigned and signdet integer types should be explicit. * Downcasting should be explicit. * Fix integer overflow check in sum().