summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-12-19 18:07:11 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-12-19 18:07:11 (GMT)
commita9406e77fa7bd3618c16edd248c24010af7035c1 (patch)
tree885dac8e53616cebafbb37bc5613040513bd9581 /Objects
parenta254921cd4c1ca22d725872601292c48b7caa20a (diff)
parent5c4064e8bd199d70eefd7ec24766957c22f1b8e8 (diff)
downloadcpython-a9406e77fa7bd3618c16edd248c24010af7035c1.zip
cpython-a9406e77fa7bd3618c16edd248c24010af7035c1.tar.gz
cpython-a9406e77fa7bd3618c16edd248c24010af7035c1.tar.bz2
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.
Diffstat (limited to 'Objects')
-rw-r--r--Objects/bytearrayobject.c2
-rw-r--r--Objects/codeobject.c2
-rw-r--r--Objects/dictobject.c2
-rw-r--r--Objects/listobject.c2
-rw-r--r--Objects/odictobject.c2
-rw-r--r--Objects/setobject.c2
6 files changed, 5 insertions, 7 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index 131e04d..96ab57d 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -2904,7 +2904,7 @@ bytearray_sizeof_impl(PyByteArrayObject *self)
{
Py_ssize_t res;
- res = sizeof(PyByteArrayObject) + self->ob_alloc * sizeof(char);
+ res = _PyObject_SIZE(Py_TYPE(self)) + self->ob_alloc * sizeof(char);
return PyLong_FromSsize_t(res);
}
diff --git a/Objects/codeobject.c b/Objects/codeobject.c
index 353f414..b0e3446 100644
--- a/Objects/codeobject.c
+++ b/Objects/codeobject.c
@@ -384,7 +384,7 @@ code_sizeof(PyCodeObject *co, void *unused)
{
Py_ssize_t res;
- res = sizeof(PyCodeObject);
+ res = _PyObject_SIZE(Py_TYPE(co));
if (co->co_cell2arg != NULL && co->co_cellvars != NULL)
res += PyTuple_GET_SIZE(co->co_cellvars) * sizeof(unsigned char);
return PyLong_FromSsize_t(res);
diff --git a/Objects/dictobject.c b/Objects/dictobject.c
index 4a72c9a..752853f 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2563,7 +2563,7 @@ _PyDict_SizeOf(PyDictObject *mp)
Py_ssize_t size, res;
size = DK_SIZE(mp->ma_keys);
- res = sizeof(PyDictObject);
+ res = _PyObject_SIZE(Py_TYPE(mp));
if (mp->ma_values)
res += size * sizeof(PyObject*);
/* If the dictionary is split, the keys portion is accounted-for
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 45e54ce..eee7c68 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2324,7 +2324,7 @@ list_sizeof(PyListObject *self)
{
Py_ssize_t res;
- res = sizeof(PyListObject) + self->allocated * sizeof(void*);
+ res = _PyObject_SIZE(Py_TYPE(self)) + self->allocated * sizeof(void*);
return PyLong_FromSsize_t(res);
}
diff --git a/Objects/odictobject.c b/Objects/odictobject.c
index 5ad88bc..4e51f4d 100644
--- a/Objects/odictobject.c
+++ b/Objects/odictobject.c
@@ -951,8 +951,6 @@ odict_sizeof(PyODictObject *od)
if (res == -1 && PyErr_Occurred())
return NULL;
- res += sizeof(PyODictObject) - sizeof(PyDictObject);
-
/* instance dict */
pylong = _PyDict_SizeOf((PyDictObject *)od->od_inst_dict);
if (pylong == NULL)
diff --git a/Objects/setobject.c b/Objects/setobject.c
index 45aa200..9468ee6 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -2003,7 +2003,7 @@ set_sizeof(PySetObject *so)
{
Py_ssize_t res;
- res = sizeof(PySetObject);
+ res = _PyObject_SIZE(Py_TYPE(so));
if (so->table != so->smalltable)
res = res + (so->mask + 1) * sizeof(setentry);
return PyLong_FromSsize_t(res);