Rev 5322: (spiv) Implement __sizeof__ in StaticTuple. (Andrew Bennetts) in file:///home/pqm/archives/thelove/bzr/%2Btrunk/

Canonical.com Patch Queue Manager pqm at pqm.ubuntu.com
Mon Jun 28 02:45:13 BST 2010


At file:///home/pqm/archives/thelove/bzr/%2Btrunk/

------------------------------------------------------------
revno: 5322 [merge]
revision-id: pqm at pqm.ubuntu.com-20100628014512-l4w7dmgpmt1pj5c4
parent: pqm at pqm.ubuntu.com-20100625095607-7bpodm8gbt160big
parent: andrew.bennetts at canonical.com-20100627052503-rat7ch559a215swk
committer: Canonical.com Patch Queue Manager <pqm at pqm.ubuntu.com>
branch nick: +trunk
timestamp: Mon 2010-06-28 02:45:12 +0100
message:
  (spiv) Implement __sizeof__ in StaticTuple. (Andrew Bennetts)
modified:
  NEWS                           NEWS-20050323055033-4e00b5db738777ff
  bzrlib/_static_tuple_c.c       _keys_type_c.c-20090908204220-aa346ccw4l37jzt7-1
=== modified file 'NEWS'
--- a/NEWS	2010-06-25 04:24:10 +0000
+++ b/NEWS	2010-06-27 05:25:03 +0000
@@ -179,6 +179,10 @@
 
 * Improved ``bzrlib.urlutils`` to handle lp:foo/bar URLs. (Gordon Tyler)
 
+* ``bzrlib._c_static_tuple.StaticTuple`` now implements ``__sizeof__``, so
+  that ``sys.getsizeof`` and other memory analysis tools will report more
+  accurate results. (Andrew Bennetts)
+
 Testing
 *******
 

=== modified file 'bzrlib/_static_tuple_c.c'
--- a/bzrlib/_static_tuple_c.c	2010-02-23 07:43:11 +0000
+++ b/bzrlib/_static_tuple_c.c	2010-06-27 05:25:03 +0000
@@ -703,6 +703,18 @@
     return 0;
 }
 
+
+static PyObject *
+StaticTuple_sizeof(StaticTuple *self)
+{
+	Py_ssize_t res;
+
+	res = _PyObject_SIZE(&StaticTuple_Type) + (int)self->size * sizeof(void*);
+	return PyInt_FromSsize_t(res);
+}
+
+
+
 static char StaticTuple_doc[] =
     "C implementation of a StaticTuple structure."
     "\n This is used as StaticTuple(item1, item2, item3)"
@@ -722,6 +734,7 @@
      "Create a StaticTuple from a given sequence. This functions"
      " the same as the tuple() constructor."},
     {"__reduce__", (PyCFunction)StaticTuple_reduce, METH_NOARGS, StaticTuple_reduce_doc},
+    {"__sizeof__",  (PyCFunction)StaticTuple_sizeof, METH_NOARGS}, 
     {NULL, NULL} /* sentinel */
 };
 




More information about the bazaar-commits mailing list