-
-
Notifications
You must be signed in to change notification settings - Fork 31.9k
gh-101266: Fix __sizeof__ for subclasses of int #101394
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
gh-101266: Fix __sizeof__ for subclasses of int #101394
Conversation
Darnit; this fails for |
That's because we had somewhat bogus numbers for I'm going to remove the "backport to 3.10" label: the bug does technically still exist in 3.10, but it's messier to fix - it looks like we would need to add a dedicated |
Thanks I will take a look |
@mdickinson We have to resolve the conflict before reviewing this PR. |
Thanks! Updated. |
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,
Just one more thing,
Would you like to change the PyBool_Type initialization with C99 style through this chance?
PyTypeObject PyBool_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
"bool",
.tp_basicsize = offsetof(struct _longobject, long_value.ob_digit),
.tp_itemsize = sizeof(digit),
.tp_dealloc = bool_dealloc,
...
.tp_vectorcall = bool_vectorcall
Good idea! It may make sense to do that in a separate PR, though: I was hoping to backport this bugfix PR to 3.11, and the C99 style change sounds like a cosmetic update that shouldn't be backported. |
Great! Feel free to merge anytime you want :) |
Thanks @mdickinson for the PR 🌮🎉.. I'm working now to backport this PR to: 3.11. |
Sorry, @mdickinson, I could not cleanly backport this to |
Hmm. Looks like I'll need to do a manual cherry-pick backport to 3.11, excluding the last few commits. I'll do that later today. |
GH-101579 is a backport of this pull request to the 3.11 branch. |
See #101579 for a manual backport to 3.11 (cherry-picking the commits up to but excluding the |
…101579) Fix the behaviour of the `__sizeof__` method (and hence the results returned by `sys.getsizeof`) for subclasses of `int`. Previously, `int` subclasses gave identical results to the `int` base class, ignoring the presence of the instance dictionary. (Manual backport of #101394 to the Python 3.11 branch.)
…ythonGH-101394) (python#101579)" This reverts commit cf89c16.
This PR was the first one to fail refleak bot ( See #101766 |
Hmm. We could try reverting it in a PR, and then running the refleak buildbots on that PR to see what happens. It seems rather implausible that it was this particular PR that introduced the refleak, though. |
Yes, seems suspicious. I will investigate! |
This PR fixes the behaviour of the
__sizeof__
method (and hence the results returned bysys.getsizeof
) for subclasses ofint
.int
andset
subclass__sizeof__
under-reports the instance dictionary pointer #101266