mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #15402: Simplify Struct.__sizeof__ and make tests more precise.
This commit is contained in:
parent
4887b1c0e7
commit
90bc2dbcce
2 changed files with 43 additions and 16 deletions
|
@ -1669,15 +1669,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);
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue