summaryrefslogtreecommitdiffstats
path: root/Objects
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-12-19 18:05:25 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-12-19 18:05:25 (GMT)
commit5c4064e8bd199d70eefd7ec24766957c22f1b8e8 (patch)
treea38d9933d5ee0d72fbebba31f046686e678a2c3c /Objects
parentefd7b34d7c4e401bbecb343da7c9506137a3b2fe (diff)
downloadcpython-5c4064e8bd199d70eefd7ec24766957c22f1b8e8.zip
cpython-5c4064e8bd199d70eefd7ec24766957c22f1b8e8.tar.gz
cpython-5c4064e8bd199d70eefd7ec24766957c22f1b8e8.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 5647b57..c59ad24 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -2974,7 +2974,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 624ae9b..3e6e112 100644
--- a/Objects/dictobject.c
+++ b/Objects/dictobject.c
@@ -2560,7 +2560,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 704d7e2..2faaf12 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1940,7 +1940,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);