mirror of
https://github.com/python/cpython
synced 2026-09-29 11:30:29 +03:00
Issue #25421: __sizeof__ methods of builtin types now use dynamic basic size.
This allows sys.getsize() to work correctly with their subclasses with __slots__ defined.
This commit is contained in:
parent
efd7b34d7c
commit
5c4064e8bd
19 changed files with 54 additions and 22 deletions
|
|
@ -1443,7 +1443,7 @@ deque_sizeof(dequeobject *deque, void *unused)
|
|||
Py_ssize_t res;
|
||||
Py_ssize_t blocks;
|
||||
|
||||
res = sizeof(dequeobject);
|
||||
res = _PyObject_SIZE(Py_TYPE(deque));
|
||||
blocks = (deque->leftindex + Py_SIZE(deque) + BLOCKLEN - 1) / BLOCKLEN;
|
||||
assert(deque->leftindex + Py_SIZE(deque) - 1 ==
|
||||
(blocks - 1) * BLOCKLEN + deque->rightindex);
|
||||
|
|
|
|||
|
|
@ -4529,7 +4529,7 @@ dec_sizeof(PyObject *v, PyObject *dummy UNUSED)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(PyDecObject);
|
||||
res = _PyObject_SIZE(Py_TYPE(v));
|
||||
if (mpd_isdynamic_data(MPD(v))) {
|
||||
res += MPD(v)->alloc * sizeof(mpd_uint_t);
|
||||
}
|
||||
|
|
|
|||
|
|
@ -847,7 +847,7 @@ static Py_ssize_t
|
|||
_elementtree_Element___sizeof___impl(ElementObject *self)
|
||||
/*[clinic end generated code: output=bf73867721008000 input=70f4b323d55a17c1]*/
|
||||
{
|
||||
Py_ssize_t result = sizeof(ElementObject);
|
||||
Py_ssize_t result = _PyObject_SIZE(Py_TYPE(self));
|
||||
if (self->extra) {
|
||||
result += sizeof(ElementObjectExtra);
|
||||
if (self->extra->children != self->extra->_children)
|
||||
|
|
|
|||
|
|
@ -423,7 +423,7 @@ buffered_sizeof(buffered *self, void *unused)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(buffered);
|
||||
res = _PyObject_SIZE(Py_TYPE(self));
|
||||
if (self->buffer)
|
||||
res += self->buffer_size;
|
||||
return PyLong_FromSsize_t(res);
|
||||
|
|
|
|||
|
|
@ -991,7 +991,7 @@ bytesio_sizeof(bytesio *self, void *unused)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(bytesio);
|
||||
res = _PyObject_SIZE(Py_TYPE(self));
|
||||
if (self->buf && !SHARED_BUF(self))
|
||||
res += _PySys_GetSizeOf(self->buf);
|
||||
return PyLong_FromSsize_t(res);
|
||||
|
|
|
|||
|
|
@ -4015,7 +4015,7 @@ _pickle_Pickler___sizeof___impl(PicklerObject *self)
|
|||
{
|
||||
Py_ssize_t res, s;
|
||||
|
||||
res = sizeof(PicklerObject);
|
||||
res = _PyObject_SIZE(Py_TYPE(self));
|
||||
if (self->memo != NULL) {
|
||||
res += sizeof(PyMemoTable);
|
||||
res += self->memo->mt_allocated * sizeof(PyMemoEntry);
|
||||
|
|
@ -6418,7 +6418,7 @@ _pickle_Unpickler___sizeof___impl(UnpicklerObject *self)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(UnpicklerObject);
|
||||
res = _PyObject_SIZE(Py_TYPE(self));
|
||||
if (self->memo != NULL)
|
||||
res += self->memo_size * sizeof(PyObject *);
|
||||
if (self->marks != NULL)
|
||||
|
|
|
|||
|
|
@ -1924,7 +1924,7 @@ s_sizeof(PyStructObject *self, void *unused)
|
|||
Py_ssize_t size;
|
||||
formatcode *code;
|
||||
|
||||
size = sizeof(PyStructObject) + sizeof(formatcode);
|
||||
size = _PyObject_SIZE(Py_TYPE(self)) + sizeof(formatcode);
|
||||
for (code = self->s_codes; code->fmtdef != NULL; code++)
|
||||
size += sizeof(formatcode);
|
||||
return PyLong_FromSsize_t(size);
|
||||
|
|
|
|||
|
|
@ -1743,7 +1743,7 @@ array_array___sizeof___impl(arrayobject *self)
|
|||
/*[clinic end generated code: output=d8e1c61ebbe3eaed input=805586565bf2b3c6]*/
|
||||
{
|
||||
Py_ssize_t res;
|
||||
res = sizeof(arrayobject) + self->allocated * self->ob_descr->itemsize;
|
||||
res = _PyObject_SIZE(Py_TYPE(self)) + self->allocated * self->ob_descr->itemsize;
|
||||
return PyLong_FromSsize_t(res);
|
||||
}
|
||||
|
||||
|
|
|
|||
|
|
@ -2089,7 +2089,7 @@ product_sizeof(productobject *lz, void *unused)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(productobject);
|
||||
res = _PyObject_SIZE(Py_TYPE(lz));
|
||||
res += PyTuple_GET_SIZE(lz->pools) * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSsize_t(res);
|
||||
}
|
||||
|
|
@ -2420,7 +2420,7 @@ combinations_sizeof(combinationsobject *co, void *unused)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(combinationsobject);
|
||||
res = _PyObject_SIZE(Py_TYPE(co));
|
||||
res += co->r * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSsize_t(res);
|
||||
}
|
||||
|
|
@ -2761,7 +2761,7 @@ cwr_sizeof(cwrobject *co, void *unused)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(cwrobject);
|
||||
res = _PyObject_SIZE(Py_TYPE(co));
|
||||
res += co->r * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSsize_t(res);
|
||||
}
|
||||
|
|
@ -3110,7 +3110,7 @@ permutations_sizeof(permutationsobject *po, void *unused)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(permutationsobject);
|
||||
res = _PyObject_SIZE(Py_TYPE(po));
|
||||
res += PyTuple_GET_SIZE(po->pool) * sizeof(Py_ssize_t);
|
||||
res += po->r * sizeof(Py_ssize_t);
|
||||
return PyLong_FromSsize_t(res);
|
||||
|
|
|
|||
|
|
@ -719,7 +719,7 @@ mmap__sizeof__method(mmap_object *self, void *unused)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(mmap_object);
|
||||
res = _PyObject_SIZE(Py_TYPE(self));
|
||||
if (self->tagname)
|
||||
res += strlen(self->tagname) + 1;
|
||||
return PyLong_FromSsize_t(res);
|
||||
|
|
|
|||
|
|
@ -397,7 +397,7 @@ parser_sizeof(PyST_Object *st, void *unused)
|
|||
{
|
||||
Py_ssize_t res;
|
||||
|
||||
res = sizeof(PyST_Object) + _PyNode_SizeOf(st->st_node);
|
||||
res = _PyObject_SIZE(Py_TYPE(st)) + _PyNode_SizeOf(st->st_node);
|
||||
return PyLong_FromSsize_t(res);
|
||||
}
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue