summaryrefslogtreecommitdiffstats
path: root/Objects/frameobject.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/frameobject.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/frameobject.c')
-rw-r--r--Objects/frameobject.c25
1 files changed, 24 insertions, 1 deletions
diff --git a/Objects/frameobject.c b/Objects/frameobject.c
index 025431e..d89d72d 100644
--- a/Objects/frameobject.c
+++ b/Objects/frameobject.c
@@ -508,6 +508,29 @@ frame_clear(PyFrameObject *f)
}
}
+static PyObject *
+frame_sizeof(PyFrameObject *f)
+{
+ Py_ssize_t res, extras, ncells, nfrees;
+
+ ncells = PyTuple_GET_SIZE(f->f_code->co_cellvars);
+ nfrees = PyTuple_GET_SIZE(f->f_code->co_freevars);
+ extras = f->f_code->co_stacksize + f->f_code->co_nlocals +
+ ncells + nfrees;
+ // subtract one as it is already included in PyFrameObject
+ res = sizeof(PyFrameObject) + (extras-1) * sizeof(PyObject *);
+
+ return PyInt_FromSsize_t(res);
+}
+
+PyDoc_STRVAR(sizeof__doc__,
+"F.__sizeof__() -> size of F in memory, in bytes");
+
+static PyMethodDef frame_methods[] = {
+ {"__sizeof__", (PyCFunction)frame_sizeof, METH_NOARGS,
+ sizeof__doc__},
+ {NULL, NULL} /* sentinel */
+};
PyTypeObject PyFrame_Type = {
PyVarObject_HEAD_INIT(&PyType_Type, 0)
@@ -537,7 +560,7 @@ PyTypeObject PyFrame_Type = {
0, /* tp_weaklistoffset */
0, /* tp_iter */
0, /* tp_iternext */
- 0, /* tp_methods */
+ frame_methods, /* tp_methods */
frame_memberlist, /* tp_members */
frame_getsetlist, /* tp_getset */
0, /* tp_base */