-
-
Notifications
You must be signed in to change notification settings - Fork 31k
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
__sizeof__
underreports size of 0
by 4 bytes
#98159
Comments
I'm not entirely sure if this behaviour is incorrect, but my understanding is that Compiler explorer link: https://godbolt.org/z/rx7PbEYxd |
This behavior looks like have a long history, @mdickinson |
Definitely not: And yes, it's true that |
Thanks, Mark, I will close the issue. |
Thanks Mark! That rationale definitely cleared it up for me. |
Bug report
sys.getsizeof
andint#__sizeof__()
both underreport the size of the0
singleton by 4 bytes, due to_PyLong_DIGIT_INIT
settingob_size
to0
when initializing the0
singleton, the correct value should be1
, since there is a singleob_digit
stored, as I understand it.Examples:
Details
_PyLong_DIGIT_INIT(val)
is used to initialize an immortalPyVarObject
.val
passed it sets the theob_size
field of the immortal using the expression:((val) == 0 ? 0 : ((val) > 0 ? 1 : -1))
2.1. When
val
is0
, this creates an_PyVarObject_IMMORTAL_INIT(&PyLong_Type, 0)
, which sets the underlyingPyVarObject
'sob_size
to0
.int___sizeof___impl
usesob_size
(throughPy_SIZE
) to calculate the sizeob_size
should be1
becauseob_digit
has onedigit
stored.4.1. However,
ob_size
is set to0
, and this contributes to under-reporting the size of0
by thesizeof(digit)
which is4
Your environment
3.8.14
,3.10.7
Darwin 21.6.0 Darwin Kernel Version 21.6.0: Wed Aug 10 14:25:27 PDT 2022; root:xnu-8020.141.5~2/RELEASE_X86_6
The text was updated successfully, but these errors were encountered: