diff options
author | Meador Inge <meadori@gmail.com> | 2012-08-10 22:35:45 -0500 |
---|---|---|
committer | Meador Inge <meadori@gmail.com> | 2012-08-10 22:35:45 -0500 |
commit | 8afa6e3eec9d03b73b1af6b28b3edf768059bb0c (patch) | |
tree | f8f1d7f58c9ed8b65881dd263fec99fec968e448 /Modules/arraymodule.c | |
parent | d33e1a2a7957c7bb2800c64e3d72bde102573e39 (diff) | |
download | cpython-8afa6e3eec9d03b73b1af6b28b3edf768059bb0c.tar.gz |
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.c | 15 |
1 files changed, 15 insertions, 0 deletions
diff --git a/Modules/arraymodule.c b/Modules/arraymodule.c index 641e283ed1..2d4ee72709 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 */ }; |