Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
Next Next commit
Avoid assertion error in object.__sizeof__
  • Loading branch information
markshannon committed Mar 25, 2024
commit 34233882cbec4026dac84c7fec4a3bda2779f86e
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 Objects/typeobject.c
Original file line number Diff line number Diff line change
Expand Up @@ -6810,8 +6810,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