[3.11] gh-100637: Fix int and bool __sizeof__ calculation to include 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 d7e7f79ca7)

Co-authored-by: Ionite <dev@ionite.io>
Co-authored-by: Mark Dickinson <dickinsm@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-01-03 09:59:40 -08:00 committed by GitHub
parent 861cdefc1b
commit 50409a2968
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 7 additions and 2 deletions

View file

@ -1322,6 +1322,7 @@ class SizeofTest(unittest.TestCase):
check = self.check_sizeof
# bool
check(True, vsize('') + self.longdigit)
check(False, vsize('') + self.longdigit)
# buffer
# XXX
# builtin_function_or_method
@ -1459,7 +1460,7 @@ class SizeofTest(unittest.TestCase):
# listreverseiterator (list)
check(reversed([]), size('nP'))
# int
check(0, vsize(''))
check(0, vsize('') + self.longdigit)
check(1, vsize('') + self.longdigit)
check(-1, vsize('') + self.longdigit)
PyLong_BASE = 2**sys.int_info.bits_per_digit