diff options
author | Martin v. Löwis <martin@v.loewis.de> | 2008-06-04 14:18:43 (GMT) |
---|---|---|
committer | Martin v. Löwis <martin@v.loewis.de> | 2008-06-04 14:18:43 (GMT) |
commit | 00709aaa3dc7da374e94a3ede8e05603e8a95066 (patch) | |
tree | 50acc73f0d94cd4294b8a6a0f2efdb03cb43f409 /Objects/listobject.c | |
parent | 01a7d82432edbf297c32289737a40d7103a03527 (diff) | |
download | cpython-00709aaa3dc7da374e94a3ede8e05603e8a95066.zip cpython-00709aaa3dc7da374e94a3ede8e05603e8a95066.tar.gz cpython-00709aaa3dc7da374e94a3ede8e05603e8a95066.tar.bz2 |
Merged revisions 63856-63857,63859-63860 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk
........
r63856 | robert.schuppenies | 2008-06-01 18:16:17 +0200 (So, 01 Jun 2008) | 2 lines
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
........
r63859 | georg.brandl | 2008-06-01 18:42:16 +0200 (So, 01 Jun 2008) | 2 lines
Some style nits. Also clarify in the docstrings what __sizeof__ does.
........
r63860 | georg.brandl | 2008-06-01 19:05:56 +0200 (So, 01 Jun 2008) | 2 lines
Fix test_descrtut.
........
Diffstat (limited to 'Objects/listobject.c')
-rw-r--r-- | Objects/listobject.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Objects/listobject.c b/Objects/listobject.c index c84cce5..d5f3a19 100644 --- a/Objects/listobject.c +++ b/Objects/listobject.c @@ -2247,6 +2247,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 PyLong_FromSsize_t(res); +} + static PyObject *list_iter(PyObject *seq); static PyObject *list_reversed(PyListObject* seq, PyObject* unused); @@ -2254,6 +2263,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 memory, in bytes"); PyDoc_STRVAR(append_doc, "L.append(object) -- append object to end"); PyDoc_STRVAR(extend_doc, @@ -2279,6 +2290,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}, |