summaryrefslogtreecommitdiffstats
path: root/Modules/_collectionsmodule.c
diff options
context:
space:
mode:
authorJesus Cea <jcea@jcea.es>2012-08-03 12:52:12 (GMT)
committerJesus Cea <jcea@jcea.es>2012-08-03 12:52:12 (GMT)
commit1659b75189d366ed05e7e43d394513ee5c5dc790 (patch)
treefe90b20bc24bb4876a8e7cda2ac68373237b0ad5 /Modules/_collectionsmodule.c
parent88ca04e6a8d1e5b31da69717e0e0cde2c069d7eb (diff)
parent16e2fca47e44e6244d7aaa285fde5ae162c4baab (diff)
downloadcpython-1659b75189d366ed05e7e43d394513ee5c5dc790.zip
cpython-1659b75189d366ed05e7e43d394513ee5c5dc790.tar.gz
cpython-1659b75189d366ed05e7e43d394513ee5c5dc790.tar.bz2
MERGE: Closes #15469: Correct __sizeof__ support for deque
Diffstat (limited to 'Modules/_collectionsmodule.c')
-rw-r--r--Modules/_collectionsmodule.c21
1 files changed, 20 insertions, 1 deletions
diff --git a/Modules/_collectionsmodule.c b/Modules/_collectionsmodule.c
index 302f4e3..d6899c2 100644
--- a/Modules/_collectionsmodule.c
+++ b/Modules/_collectionsmodule.c
@@ -933,6 +933,23 @@ deque_init(dequeobject *deque, PyObject *args, PyObject *kwdargs)
}
static PyObject *
+deque_sizeof(dequeobject *deque, void *unused)
+{
+ Py_ssize_t res;
+ Py_ssize_t blocks;
+
+ res = sizeof(dequeobject);
+ blocks = (deque->leftindex + deque->len + BLOCKLEN - 1) / BLOCKLEN;
+ assert(deque->leftindex + deque->len - 1 ==
+ (blocks - 1) * BLOCKLEN + deque->rightindex);
+ res += blocks * sizeof(block);
+ return PyLong_FromSsize_t(res);
+}
+
+PyDoc_STRVAR(sizeof_doc,
+"D.__sizeof__() -- size of D in memory, in bytes");
+
+static PyObject *
deque_get_maxlen(dequeobject *deque)
{
if (deque->maxlen == -1)
@@ -995,7 +1012,9 @@ static PyMethodDef deque_methods[] = {
{"reverse", (PyCFunction)deque_reverse,
METH_NOARGS, reverse_doc},
{"rotate", (PyCFunction)deque_rotate,
- METH_VARARGS, rotate_doc},
+ METH_VARARGS, rotate_doc},
+ {"__sizeof__", (PyCFunction)deque_sizeof,
+ METH_NOARGS, sizeof_doc},
{NULL, NULL} /* sentinel */
};