gh-121153: Fix some errors with use of _PyLong_CompactValue()#121154
gh-121153: Fix some errors with use of _PyLong_CompactValue()#121154serhiy-storchaka merged 6 commits into
Conversation
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
vstinner
left a comment
There was a problem hiding this comment.
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 <storchaka@gmail.com>
…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 <storchaka@gmail.com>
|
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().
Uh oh!
There was an error while loading. Please reload this page.