summaryrefslogtreecommitdiffstats
path: root/Objects/bytesobject.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/bytesobject.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/bytesobject.c')
-rw-r--r--Objects/bytesobject.c13
1 files changed, 13 insertions, 0 deletions
diff --git a/Objects/bytesobject.c b/Objects/bytesobject.c
index 79c1e4f..0de24f8 100644
--- a/Objects/bytesobject.c
+++ b/Objects/bytesobject.c
@@ -3917,6 +3917,17 @@ string_splitlines(PyBytesObject *self, PyObject *args)
return NULL;
}
+PyDoc_STRVAR(sizeof__doc__,
+"S.__sizeof__() -> size of S in bytes");
+
+static PyObject *
+string_sizeof(PyBytesObject *v)
+{
+ Py_ssize_t res;
+ res = sizeof(PyBytesObject) + v->ob_size * v->ob_type->tp_itemsize;
+ return PyInt_FromSsize_t(res);
+}
+
#undef SPLIT_APPEND
#undef SPLIT_ADD
#undef MAX_PREALLOC
@@ -4024,6 +4035,8 @@ string_methods[] = {
expandtabs__doc__},
{"splitlines", (PyCFunction)string_splitlines, METH_VARARGS,
splitlines__doc__},
+ {"__sizeof__", (PyCFunction)string_sizeof, METH_NOARGS,
+ sizeof__doc__},
{"__getnewargs__", (PyCFunction)string_getnewargs, METH_NOARGS},
{NULL, NULL} /* sentinel */
};