summaryrefslogtreecommitdiffstats
path: root/Objects/longobject.c
diff options
context:
space:
mode:
authorRobert Schuppenies <okkotonushi@googlemail.com>2008-06-01 16:16:17 (GMT)
committerRobert Schuppenies <okkotonushi@googlemail.com>2008-06-01 16:16:17 (GMT)
commit51df0647672bc758da6d58eecfe45da9dc5913df (patch)
tree3cb568af01a3310eda4e1647901cd5ac3df118fb /Objects/longobject.c
parent6495c8da8f945def4749192b0536c1678f208664 (diff)
downloadcpython-51df0647672bc758da6d58eecfe45da9dc5913df.zip
cpython-51df0647672bc758da6d58eecfe45da9dc5913df.tar.gz
cpython-51df0647672bc758da6d58eecfe45da9dc5913df.tar.bz2
Issue #2898: Added sys.getsizeof() to retrieve size of objects in bytes.
Diffstat (limited to 'Objects/longobject.c')
-rw-r--r--Objects/longobject.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Objects/longobject.c b/Objects/longobject.c
index 82a57ec..5876495 100644
--- a/Objects/longobject.c
+++ b/Objects/longobject.c
@@ -3436,6 +3436,17 @@ long__format__(PyObject *self, PyObject *args)
return NULL;
}
+static PyObject *
+long_sizeof(PyLongObject *v)
+{
+ Py_ssize_t res;
+
+ res = sizeof(PyLongObject) + abs(v->ob_size) * sizeof(digit);
+ if (v->ob_size != 0)
+ res -= sizeof(digit);
+ return PyInt_FromSsize_t(res);
+}
+
#if 0
static PyObject *
long_is_finite(PyObject *v)
@@ -3455,6 +3466,8 @@ static PyMethodDef long_methods[] = {
"Truncating an Integral returns itself."},
{"__getnewargs__", (PyCFunction)long_getnewargs, METH_NOARGS},
{"__format__", (PyCFunction)long__format__, METH_VARARGS},
+ {"__sizeof__", (PyCFunction)long_sizeof, METH_NOARGS,
+ "Returns size in bytes"},
{NULL, NULL} /* sentinel */
};