Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork 35.2k
gh-143050: correct PyLong_FromString() to use _PyLong_Negate()#145901
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
Uh oh!
There was an error while loading. Please reload this page.
Changes from all commits
fbcec5ab8333ba20e79c6413e56db89221678c5b4b69d35bd2f927e053523de1f363f441961ed0b29e2845b3b04File filter
Filter by extension
Conversations
Uh oh!
There was an error while loading. Please reload this page.
Jump to
Uh oh!
There was an error while loading. Please reload this page.
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -803,6 +803,16 @@ def to_digits(num): | ||
| self.assertEqual(pylongwriter_create(negative, digits), num, | ||
| (negative, digits)) | ||
| def test_bug_143050(self): | ||
| with support.adjust_int_max_str_digits(0): | ||
| # Bug coming from using _pylong.int_from_string(), that | ||
| # currently requires > 6000 decimal digits. | ||
| int('-' + '0' * 7000, 10) | ||
skirpichev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| _testcapi.test_immortal_small_ints() | ||
| # Test also nonzero small int | ||
| int('-' + '0' * 7000 + '123', 10) | ||
skirpichev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| _testcapi.test_immortal_small_ints() | ||
MemberAuthor There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Contributor There was a problem hiding this comment. Choose a reason for hiding this commentThe 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. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. _testcapi is always built with assertions, even in release mode. Member There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I built Python in release mode without | ||
| if __name__ == "__main__": | ||
| unittest.main() | ||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -3119,11 +3119,11 @@ PyLong_FromString(const char *str, char **pend, int base) | ||
| } | ||
| /* Set sign and normalize */ | ||
| if (sign < 0) { | ||
| _PyLong_FlipSign(z); | ||
skirpichev marked this conversation as resolved.
Uh oh!There was an error while loading. Please reload this page. | ||
| } | ||
| long_normalize(z); | ||
| z = maybe_small_long(z); | ||
| if (sign < 0) { | ||
| _PyLong_Negate(&z); | ||
| } | ||
| if (pend != NULL) { | ||
| *pend = (char *)str; | ||
| @@ -3623,21 +3623,11 @@ long_richcompare(PyObject *self, PyObject *other, int op) | ||
| Py_RETURN_RICHCOMPARE(result, 0, op); | ||
| } | ||
| static inline int | ||
| /// Return 1 if the object is one of the immortal small ints | ||
| _long_is_small_int(PyObject *op) | ||
| { | ||
| PyLongObject *long_object = (PyLongObject *)op; | ||
| int is_small_int = (long_object->long_value.lv_tag & IMMORTALITY_BIT_MASK) != 0; | ||
| assert((!is_small_int) || PyLong_CheckExact(op)); | ||
| return is_small_int; | ||
| } | ||
| void | ||
| _PyLong_ExactDealloc(PyObject *self) | ||
| { | ||
| assert(PyLong_CheckExact(self)); | ||
| if (_long_is_small_int(self)) { | ||
| if (_PyLong_IsSmallInt((PyLongObject *)self)) { | ||
| // See PEP 683, section Accidental De-Immortalizing for details | ||
| _Py_SetImmortal(self); | ||
| return; | ||
| @@ -3652,7 +3642,7 @@ _PyLong_ExactDealloc(PyObject *self) | ||
| static void | ||
| long_dealloc(PyObject *self) | ||
| { | ||
| if (_long_is_small_int(self)) { | ||
| if (_PyLong_IsSmallInt((PyLongObject *)self)) { | ||
| /* This should never get called, but we also don't want to SEGV if | ||
| * we accidentally decref small Ints out of existence. Instead, | ||
| * since small Ints are immortal, re-set the reference count. | ||
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.