[3.13] GH-117195: Avoid assertion error in object.__sizeof__ (GH-117220) (GH-119456)

This commit is contained in:
Miss Islington (bot) 2024-05-23 17:58:34 +02:00 committed by GitHub
parent dbe4f8a2e8
commit 251ef2e36f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 9 additions and 2 deletions

View file

@ -7037,8 +7037,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);