summaryrefslogtreecommitdiffstats
path: root/Objects/setobject.c
diff options
context:
space:
mode:
authorRobert Schuppenies <okkotonushi@googlemail.com>2008-07-10 15:24:04 (GMT)
committerRobert Schuppenies <okkotonushi@googlemail.com>2008-07-10 15:24:04 (GMT)
commit9be2ec109bcec499c1a6971fb4c40d9a8e7886fe (patch)
tree04942da45d0452f8555758be18bfa3effda1dedb /Objects/setobject.c
parentcc3f2b1d1677b4464f223c2fbff77f1b8bd6df0a (diff)
downloadcpython-9be2ec109bcec499c1a6971fb4c40d9a8e7886fe.zip
cpython-9be2ec109bcec499c1a6971fb4c40d9a8e7886fe.tar.gz
cpython-9be2ec109bcec499c1a6971fb4c40d9a8e7886fe.tar.bz2
Added additional __sizeof__ implementations and addressed comments made in
Issue3122.
Diffstat (limited to 'Objects/setobject.c')
-rw-r--r--Objects/setobject.c16
1 files changed, 16 insertions, 0 deletions
diff --git a/Objects/setobject.c b/Objects/setobject.c
index f3eea21..39465f3 100644
--- a/Objects/setobject.c
+++ b/Objects/setobject.c
@@ -1956,6 +1956,18 @@ done:
PyDoc_STRVAR(reduce_doc, "Return state information for pickling.");
+static PyObject *
+set_sizeof(PySetObject *so)
+{
+ Py_ssize_t res;
+
+ res = sizeof(PySetObject);
+ if (so->table != so->smalltable)
+ res = res + (so->mask + 1) * sizeof(setentry);
+ return PyInt_FromSsize_t(res);
+}
+
+PyDoc_STRVAR(sizeof_doc, "S.__sizeof__() -> size of S in memory, in bytes");
static int
set_init(PySetObject *self, PyObject *args, PyObject *kwds)
{
@@ -2023,6 +2035,8 @@ static PyMethodDef set_methods[] = {
reduce_doc},
{"remove", (PyCFunction)set_remove, METH_O,
remove_doc},
+ {"__sizeof__", (PyCFunction)set_sizeof, METH_NOARGS,
+ sizeof_doc},
{"symmetric_difference",(PyCFunction)set_symmetric_difference, METH_O,
symmetric_difference_doc},
{"symmetric_difference_update",(PyCFunction)set_symmetric_difference_update, METH_O,
@@ -2144,6 +2158,8 @@ static PyMethodDef frozenset_methods[] = {
issuperset_doc},
{"__reduce__", (PyCFunction)set_reduce, METH_NOARGS,
reduce_doc},
+ {"__sizeof__", (PyCFunction)set_sizeof, METH_NOARGS,
+ sizeof_doc},
{"symmetric_difference",(PyCFunction)set_symmetric_difference, METH_O,
symmetric_difference_doc},
{"union", (PyCFunction)set_union, METH_VARARGS,