mirror of
https://github.com/python/cpython.git
synced 2025-10-09 16:34:44 +00:00
Merged revisions 64842,64853,64856,64945 via svnmerge from
svn+ssh://pythondev@svn.python.org/python/trunk ........ r64842 | robert.schuppenies | 2008-07-10 15:43:26 +0200 (Thu, 10 Jul 2008) | 2 lines Fixed Issue3122 and extended sys.getsizeof tests for built-in types. ........ r64853 | robert.schuppenies | 2008-07-10 17:24:04 +0200 (Thu, 10 Jul 2008) | 3 lines Added additional __sizeof__ implementations and addressed comments made in Issue3122. ........ r64856 | robert.schuppenies | 2008-07-10 19:13:55 +0200 (Thu, 10 Jul 2008) | 3 lines Added garbage collector overhead and optional default return value to sys.getsizeof. ........ r64945 | robert.schuppenies | 2008-07-14 10:42:18 +0200 (Mon, 14 Jul 2008) | 2 lines Fixed test failure on Win64 machines. ........
This commit is contained in:
parent
3065b87a07
commit
fbe94c55ca
9 changed files with 342 additions and 103 deletions
|
@ -513,6 +513,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 PyLong_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)
|
||||
|
@ -542,7 +565,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 */
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue