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:
Serhiy Storchaka 2015-12-19 20:07:11 +02:00
commit a9406e77fa
19 changed files with 54 additions and 22 deletions

View file

@ -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);

View file

@ -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);