summaryrefslogtreecommitdiffstats
path: root/Modules/arraymodule.c
diff options
context:
space:
mode:
authorMeador Inge <meadori@gmail.com>2012-08-11 03:35:45 (GMT)
committerMeador Inge <meadori@gmail.com>2012-08-11 03:35:45 (GMT)
commit03b4d5072aa044d8c6827e387b647dcc6c9d0ff6 (patch)
tree3921b2fba6e6e96ecf6a848296cc2e15190f669b /Modules/arraymodule.c
parent7dbee38564cb4112da59a4b8aa2e1759f09bb1f8 (diff)
downloadcpython-03b4d5072aa044d8c6827e387b647dcc6c9d0ff6.zip
cpython-03b4d5072aa044d8c6827e387b647dcc6c9d0ff6.tar.gz
cpython-03b4d5072aa044d8c6827e387b647dcc6c9d0ff6.tar.bz2
Issue #15424: Add a __sizeof__ implementation for array objects.
Patch by Ludwig Hähne.
Diffstat (limited to 'Modules/arraymodule.c')
-rw-r--r--Modules/arraymodule.c15
1 files changed, 15 insertions, 0 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c
index 641e283..2d4ee72 100644
--- a/Modules/arraymodule.c
+++ b/Modules/arraymodule.c
@@ -1510,6 +1510,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 ************************/
@@ -2077,6 +2090,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 */
};