-
-
Notifications
You must be signed in to change notification settings - Fork 32.2k
gh-100637: Fix int and bool __sizeof__ calculation to include the 1 element ob_digit array for 0 and False #100663
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
Fixes behavior where int (and subtypes like bool) __sizeof__ under-reports true size as it did not take into account the size 1 `ob_digit` array for empty ints.
Most changes to Python require a NEWS entry. Please add it using the blurb_it web app or the blurb command-line tool. |
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 looks good to me, and works as advertised in manual testing - thank you!
I've made one nitpick level suggestion for a stylistic change.
(Actually, thinking about style, I'm not sure why the body of this function doesn't simply consist of a single return
- the res
temporary seems unnecessary.)
Co-authored-by: Mark Dickinson <[email protected]>
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.
LGTM!
I'll leave this open for a bit in case anyone else has comments (especially because it's New Year's Day and some potential commenters may be AFK), but I think this is ready to merge.
Thanks for the review and line split suggestion! I'm not really sure about the |
Would this be something that needs backport to 3.10/3.11? Not sure what the policy is for that. |
Thanks @ionite34 for the PR, and @mdickinson for merging it 🌮🎉.. I'm working now to backport this PR to: 3.11. |
…he 1 element ob_digit array for 0 and False (pythonGH-100663) Fixes behaviour where int (and subtypes like bool) __sizeof__ under-reports true size as it did not take into account the size 1 `ob_digit` array for the zero int. (cherry picked from commit d7e7f79) Co-authored-by: Ionite <[email protected]> Co-authored-by: Mark Dickinson <[email protected]>
GH-100717 is a backport of this pull request to the 3.11 branch. |
It's a judgement call, I think: it's arguably a bugfix, but an almost entirely inconsequential one - I can't imagine much real world code that would benefit, even though it's nice to have the fix going forward. I'll backport to 3.11: Python 3.11 was the version that deliberately started always allocating at least one digit (the relevant commit was 15d50d7). That isn't true in Python 3.10. (3.10 code: Lines 138 to 139 in a639493
(3.11 code: Lines 155 to 162 in b99ac1d
|
…the 1 element ob_digit array for 0 and False (GH-100663) (#100717) gh-100637: Fix int and bool __sizeof__ calculation to include the 1 element ob_digit array for 0 and False (GH-100663) Fixes behaviour where int (and subtypes like bool) __sizeof__ under-reports true size as it did not take into account the size 1 `ob_digit` array for the zero int. (cherry picked from commit d7e7f79) Co-authored-by: Ionite <[email protected]> Co-authored-by: Mark Dickinson <[email protected]>
Fixes behavior where
int
andbool
__sizeof__
under-reports true size by 4 bytes as it did not take into account the size 1ob_digit
array for0
andFalse
.Changes
Py_MAX
to use the maximum of 1 or the absoluteob_size
size.Testing
__sizeof__
incorrectly ignores the size 1 array in PyVarObjects (bool, int, tuple) when ob_size is 0 #100637