summaryrefslogtreecommitdiffstats
path: root/Modules
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 /Modules
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 '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 214872b..4fffe01 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 169914c..112b44f 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 915a0be..c69998c 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 29e000b..6bb2200 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 31cc1f7..eef3b3d 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 41f1cd1..56bbd58 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 068c5d1..b61f9f6 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 a3ccf93..6af75a4 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 dfafeab..9c210ea 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 daab52b..bb98a99 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 8023558..6471b8e 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);
}