summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2012-08-11 04:21:39 (GMT)
committerMeador Inge <meadori@gmail.com>2012-08-11 04:21:39 (GMT)
commit80dd1af4e0ee07b2f65833835754f0a27bf48975 (patch)
tree1d7f04a3c9fd2268459b864ea89abdb83ed7e8ea /Modules
parent688a551ca075ed28126e11b5935ed0649d1e3b83 (diff)
parent03b4d5072aa044d8c6827e387b647dcc6c9d0ff6 (diff)
downloadcpython-80dd1af4e0ee07b2f65833835754f0a27bf48975.zip
cpython-80dd1af4e0ee07b2f65833835754f0a27bf48975.tar.gz
cpython-80dd1af4e0ee07b2f65833835754f0a27bf48975.tar.bz2
Issue #15424: Add a __sizeof__ implementation for array objects.
Patch by Ludwig Hähne.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/arraymodule.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index f0615c9..04eb67c 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1567,6 +1567,19 @@ array.tobytes().decode() to obtain a unicode string from\n\
an array of some other type.");
+static PyObject *
+array_sizeof(arrayobject *self, PyObject *unused)
+{
+ Py_ssize_t res;
+ res = sizeof(arrayobject) + self->allocated * self->ob_descr->itemsize;
+ return PyLong_FromSsize_t(res);
+}
+
+PyDoc_STRVAR(sizeof_doc,
+"__sizeof__() -> int\n\
+\n\
+Size of the array in memory, in bytes.");
+
/*********************** Pickling support ************************/
@@ -2143,6 +2156,8 @@ static PyMethodDef array_methods[] = {
tobytes_doc},
{"tounicode", (PyCFunction)array_tounicode, METH_NOARGS,
tounicode_doc},
+ {"__sizeof__", (PyCFunction)array_sizeof, METH_NOARGS,
+ sizeof_doc},
{NULL, NULL} /* sentinel */
};