Mercurial > cpython-lru_cache-weakref
diff Objects/tupleobject.c @ 47682:2dfaa0683be8 legacy-trunk
Fixed: sys.getsizeof does not take the actual length of the tuples into account.
| author | Robert Schuppenies <okkotonushi@googlemail.com> |
|---|---|
| date | Fri, 13 Jun 2008 13:29:37 +0000 |
| parents | 52294af4b663 |
| children | c4d24fc8ba8a |
line wrap: on
line diff
--- a/Objects/tupleobject.c Fri Jun 13 13:26:54 2008 +0000 +++ b/Objects/tupleobject.c Fri Jun 13 13:29:37 2008 +0000 @@ -708,13 +708,25 @@ } +static PyObject * +tuple_sizeof(PyTupleObject *self) +{ + Py_ssize_t res; + + res = PyTuple_Type.tp_basicsize + Py_SIZE(self) * sizeof(PyObject *); + return PyInt_FromSsize_t(res); +} + PyDoc_STRVAR(index_doc, "T.index(value, [start, [stop]]) -> integer -- return first index of value"); PyDoc_STRVAR(count_doc, "T.count(value) -> integer -- return number of occurrences of value"); +PyDoc_STRVAR(sizeof_doc, +"T.__sizeof__() -- size of T in memory, in bytes"); static PyMethodDef tuple_methods[] = { {"__getnewargs__", (PyCFunction)tuple_getnewargs, METH_NOARGS}, + {"__sizeof__", (PyCFunction)tuple_sizeof, METH_NOARGS, sizeof_doc}, {"index", (PyCFunction)tupleindex, METH_VARARGS, index_doc}, {"count", (PyCFunction)tuplecount, METH_O, count_doc}, {NULL, NULL} /* sentinel */
