Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

GH-117195: Avoid assertion error in object.__sizeof__ #117220

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

Merged
merged 5 commits into from
May 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions 2 Lib/test/test_long.py
Original file line number Diff line number Diff line change
Expand Up @@ -1639,6 +1639,8 @@ class MyInt(int):
MyInt.__basicsize__ + MyInt.__itemsize__ * ndigits
)

# GH-117195 -- This shouldn't crash
object.__sizeof__(1)

if __name__ == "__main__":
unittest.main()
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Avoid assertion failure for debug builds when calling
``object.__sizeof__(1)``
7 changes: 5 additions & 2 deletions 7 Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -7144,8 +7144,11 @@ object___sizeof___impl(PyObject *self)

res = 0;
isize = Py_TYPE(self)->tp_itemsize;
if (isize > 0)
res = Py_SIZE(self) * isize;
if (isize > 0) {
/* This assumes that ob_size is valid if tp_itemsize is not 0,
which isn't true for PyLongObject. */
res = _PyVarObject_CAST(self)->ob_size * isize;
}
res += Py_TYPE(self)->tp_basicsize;

return PyLong_FromSsize_t(res);
Expand Down
Loading
Morty Proxy This is a proxified and sanitized view of the page, visit original site.