[Python-checkins] r64230 - in python/trunk: Lib/test/test_sys.py Objects/tupleobject.c
robert.schuppenies
python-checkins at python.org
Fri Jun 13 15:29:37 CEST 2008
Author: robert.schuppenies
Date: Fri Jun 13 15:29:37 2008
New Revision: 64230
Log:
Fixed: sys.getsizeof does not take the actual length of the tuples into account.
Modified:
python/trunk/Lib/test/test_sys.py
python/trunk/Objects/tupleobject.c
Modified: python/trunk/Lib/test/test_sys.py
==============================================================================
--- python/trunk/Lib/test/test_sys.py (original)
+++ python/trunk/Lib/test/test_sys.py Fri Jun 13 15:29:37 2008
@@ -567,6 +567,9 @@
# string
self.check_sizeof('', h + l + self.align(i + 1))
self.check_sizeof('abc', h + l + self.align(i + 1) + 3)
+ # tuple
+ self.check_sizeof((), h)
+ self.check_sizeof((1,2,3), h + 3*p)
def test_main():
Modified: python/trunk/Objects/tupleobject.c
==============================================================================
--- python/trunk/Objects/tupleobject.c (original)
+++ python/trunk/Objects/tupleobject.c Fri Jun 13 15:29:37 2008
@@ -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 */
More information about the Python-checkins
mailing list