GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — gh-143050: correct PyLong_FromString() to use _PyLong_Negate() by skirpichev · Pull Request #145901 · python/cpython Conversation
|
|
Shouldn't affect users, so - no news. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| with support.adjust_int_max_str_digits(0): | ||
| a = int('-' + '0' * 7000, 10) | ||
| del a | ||
| _testcapi.test_immortal_small_ints() |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That's okay as long as it catches the regression in a debug build.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
_testcapi is always built with assertions, even in release mode.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I built Python in release mode without PyLong_FromString() fix. _PyLong_FlipSign() assertion didn't catch the bug since Python was built without assertions. But at least, test_immortal_small_ints() was able to detect that small integers were corrupted:
test_bug_143050 (test.test_capi.test_long.LongTests.test_bug_143050) ...
python: ./Modules/_testcapi/immortal.c:35: test_immortal_small_ints: Assertion `has_int_immortal_bit' failed.
Fatal Python error: Aborted
Current thread 0x00007f617b91b780 [python] (most recent call first):
File "/home/vstinner/python/main/Lib/test/test_capi/test_long.py", line 811 in test_bug_143050
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Minor comment on the naming. But the PR fixes a bug, adds a test and cleans up along the way, so good enough for me!
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me. Small comment about the function name below.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| with support.adjust_int_max_str_digits(0): | ||
| a = int('-' + '0' * 7000, 10) | ||
| del a | ||
| _testcapi.test_immortal_small_ints() |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
That's okay as long as it catches the regression in a debug build.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Let me know if you change the function name or keep it as is.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
e28e94c to
78c5b4b
Compare
There was an error while loading. Please reload this page.
|
@colesbury, I did renaming.
|
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
|
||
| /* Return true if the argument is a small int */ | ||
| static inline bool | ||
| _PyLong_HasImmortalTag(const PyLongObject *op) |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
IMO the intent here is to check if an integer is a small integer, rather than checking for a tag. So I would prefer to rename the function to _PyLong_IsSmallInt().
I wanted to suggest referring to _PY_IS_SMALL_INT() but I noticed the macro is wrong. I wrote #146631 to fix the macro.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
There are two notions for "small int"'s. One - by value and other is - this. If @colesbury is ok - I'm fine with renaming..
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
_PyLong_HasImmortalTag() and _PY_IS_SMALL_INT() should be true or false for the same values.
For example, you can add the following check for _PyLong_HasImmortalTag():
+ assert((_PyLong_IsCompact(op) && _PY_IS_SMALL_INT(_PyLong_CompactValue(op)))
+ || (!is_small_int));
(You need to update your branch to retrieve my _PY_IS_SMALL_INT() change.)
For me, testing IMMORTALITY_BIT_MASK is just an implementation detail to check if an integer is "a small int".
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've added an assert. BTW, what do you think on #145901 (comment)?
I don't think we should mention _PY_IS_SMALL_INT in the description of the function, assert is readable enough.
For me, testing IMMORTALITY_BIT_MASK is just an implementation detail to check if an integer is "a small int".
For now, we use _PY_IS_SMALL_INT() to check this. But eventually this could be just testing a flag.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I would prefer to rename the function to _PyLong_IsSmallInt().
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
I've added suggestions.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Co-authored-by: Sergey B Kirpichev <[email protected]>
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
LGTM
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
It looks unrelated to this change. I just re-ran the CI. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
To backport this change to 3.14, |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
Why we need a backport? |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
This change uses |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
|
Thanks @skirpichev for the PR, and @vstinner for merging it 🌮🎉.. I'm working now to backport this PR to: 3.14. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
|
GH-147331 is a backport of this pull request to the 3.14 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…ythonGH-145901) The long_from_string_base() might return a small integer, when the _pylong.py is used to do conversion. Hence, we must be careful here to not smash it "small int" bit by using the _PyLong_FlipSign(). (cherry picked from commit db5936c) Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
|
GH-147437 is a backport of this pull request to the 3.13 branch. |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
…GH-145901) (#147331) gh-143050: Correct PyLong_FromString() to use _PyLong_Negate() (GH-145901) The long_from_string_base() might return a small integer, when the _pylong.py is used to do conversion. Hence, we must be careful here to not smash it "small int" bit by using the _PyLong_FlipSign(). (cherry picked from commit db5936c) Co-authored-by: Sergey B Kirpichev <[email protected]> Co-authored-by: Victor Stinner <[email protected]>
…#145901) (#147437) The long_from_string_base() might return a small integer, when the _pylong.py is used to do conversion. Hence, we must be careful here to not smash it "small int" bit by using the _PyLong_FlipSign(). Co-authored-by: Victor Stinner <[email protected]> (cherry picked from commit db5936c) Co-authored-by: Sergey B Kirpichev <[email protected]>
…ython#145901) The long_from_string_base() might return a small integer, when the _pylong.py is used to do conversion. Hence, we must be careful here to not smash it "small int" bit by using the _PyLong_FlipSign(). Co-authored-by: Victor Stinner <[email protected]>
…ython#145901) The long_from_string_base() might return a small integer, when the _pylong.py is used to do conversion. Hence, we must be careful here to not smash it "small int" bit by using the _PyLong_FlipSign(). Co-authored-by: Victor Stinner <[email protected]>
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.