summaryrefslogtreecommitdiff
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-12-19 20:05:25 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-12-19 20:05:25 +0200
commite7fe1d033e834d6b4deb61eb6fe5984e11fb5fc0 (patch)
tree700e38886aa7e072961d17f00a76460487f97e1a /Modules
parent30434d7ad8841a0354bd84d808dba7e2fe9a6988 (diff)
downloadcpython-e7fe1d033e834d6b4deb61eb6fe5984e11fb5fc0.tar.gz
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 'Modules')
-rw-r--r--Modules/_collectionsmodule.c2
-rw-r--r--Modules/_decimal/_decimal.c2
-rw-r--r--Modules/_elementtree.c2
-rw-r--r--Modules/_io/bufferedio.c2
-rw-r--r--Modules/_io/bytesio.c2
-rw-r--r--Modules/_pickle.c4
-rw-r--r--Modules/_struct.c2
-rw-r--r--Modules/arraymodule.c2
-rw-r--r--Modules/itertoolsmodule.c8
-rw-r--r--Modules/mmapmodule.c2
-rw-r--r--Modules/parsermodule.c2
11 files changed, 15 insertions, 15 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 214872b393..4fffe01a84 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -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);
diff --git a/Modules/_decimal/_decimal.c b/Modules/_decimal/_decimal.c
index 169914c2f7..112b44fda7 100644
--- a/Modules/_decimal/_decimal.c
+++ b/Modules/_decimal/_decimal.c
@@ -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);
}
diff --git a/Modules/_elementtree.c b/Modules/_elementtree.c
index 915a0be4d4..c69998cd17 100644
--- a/Modules/_elementtree.c
+++ b/Modules/_elementtree.c
@@ -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)
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 29e000bde4..6bb2200e20 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -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);
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c
index 31cc1f79a1..eef3b3de72 100644
--- a/Modules/_io/bytesio.c
+++ b/Modules/_io/bytesio.c
@@ -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);
diff --git a/Modules/_pickle.c b/Modules/_pickle.c
index 41f1cd1975..56bbd587b5 100644
--- a/Modules/_pickle.c
+++ b/Modules/_pickle.c
@@ -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)
diff --git a/Modules/_struct.c b/Modules/_struct.c
index 068c5d1e1d..b61f9f6fa9 100644
--- a/Modules/_struct.c
+++ b/Modules/_struct.c
@@ -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);
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index a3ccf9344f..6af75a4357 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -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);
}
diff --git a/Modules/itertoolsmodule.c b/Modules/itertoolsmodule.c
index dfafeab520..9c210ea871 100644
--- a/Modules/itertoolsmodule.c
+++ b/Modules/itertoolsmodule.c
@@ -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);
diff --git a/Modules/mmapmodule.c b/Modules/mmapmodule.c
index daab52b388..bb98a99427 100644
--- a/Modules/mmapmodule.c
+++ b/Modules/mmapmodule.c
@@ -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);
diff --git a/Modules/parsermodule.c b/Modules/parsermodule.c
index 8023558fd1..6471b8ee99 100644
--- a/Modules/parsermodule.c
+++ b/Modules/parsermodule.c
@@ -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);
}