Issue #15402: Simplify Struct.__sizeof__ and make tests more precise.

This commit is contained in:
Meador Inge 2012-07-28 22:32:50 -05:00
commit bb9b1c165d
2 changed files with 43 additions and 16 deletions

View file

@ -1756,15 +1756,11 @@ PyDoc_STRVAR(s_sizeof__doc__,
"S.__sizeof__() -> size of S in memory, in bytes");
static PyObject *
s_sizeof(PyStructObject *self)
s_sizeof(PyStructObject *self, void *unused)
{
Py_ssize_t size;
formatcode *code;
size = sizeof(PyStructObject) + sizeof(formatcode);
for (code = self->s_codes; code->fmtdef != NULL; code++) {
size += sizeof(formatcode);
}
size = sizeof(PyStructObject) + sizeof(formatcode) * (self->s_len + 1);
return PyLong_FromSsize_t(size);
}