summaryrefslogtreecommitdiffstats
path: root/Objects/listobject.c
diff options
context:
space:
mode:
authorRobert Schuppenies <okkotonushi@googlemail.com>2008-06-01 16:16:17 (GMT)
committerRobert Schuppenies <okkotonushi@googlemail.com>2008-06-01 16:16:17 (GMT)
commit51df0647672bc758da6d58eecfe45da9dc5913df (patch)
tree3cb568af01a3310eda4e1647901cd5ac3df118fb /Objects/listobject.c
parent6495c8da8f945def4749192b0536c1678f208664 (diff)
downloadcpython-51df0647672bc758da6d58eecfe45da9dc5913df.zip
cpython-51df0647672bc758da6d58eecfe45da9dc5913df.tar.gz
cpython-51df0647672bc758da6d58eecfe45da9dc5913df.tar.bz2
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r--Objects/listobject.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c
index 9d742d8..0216a85 100644
--- a/Objects/listobject.c
+++ b/Objects/listobject.c
@@ -2420,6 +2420,15 @@ list_init(PyListObject *self, PyObject *args, PyObject *kw)
return 0;
}
+static PyObject *
+list_sizeof(PyListObject *self)
+{
+ Py_ssize_t res;
+
+ res = sizeof(PyListObject) + self->allocated * sizeof(void*);
+ return PyInt_FromSsize_t(res);
+}
+
static PyObject *list_iter(PyObject *seq);
static PyObject *list_reversed(PyListObject* seq, PyObject* unused);
@@ -2427,6 +2436,8 @@ PyDoc_STRVAR(getitem_doc,
"x.__getitem__(y) <==> x[y]");
PyDoc_STRVAR(reversed_doc,
"L.__reversed__() -- return a reverse iterator over the list");
+PyDoc_STRVAR(sizeof_doc,
+"L.__sizeof__() -- size of L in bytes");
PyDoc_STRVAR(append_doc,
"L.append(object) -- append object to end");
PyDoc_STRVAR(extend_doc,
@@ -2452,6 +2463,7 @@ static PyObject *list_subscript(PyListObject*, PyObject*);
static PyMethodDef list_methods[] = {
{"__getitem__", (PyCFunction)list_subscript, METH_O|METH_COEXIST, getitem_doc},
{"__reversed__",(PyCFunction)list_reversed, METH_NOARGS, reversed_doc},
+ {"__sizeof__", (PyCFunction)list_sizeof, METH_NOARGS, sizeof_doc},
{"append", (PyCFunction)listappend, METH_O, append_doc},
{"insert", (PyCFunction)listinsert, METH_VARARGS, insert_doc},
{"extend", (PyCFunction)listextend, METH_O, extend_doc},