summaryrefslogtreecommitdiffstats
path: root/Objects/bytearrayobject.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/bytearrayobject.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/bytearrayobject.c')
-rw-r--r--Objects/bytearrayobject.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Objects/bytearrayobject.c b/Objects/bytearrayobject.c
index b2ddf6b..91a1ed9 100644
--- a/Objects/bytearrayobject.c
+++ b/Objects/bytearrayobject.c
@@ -3106,6 +3106,19 @@ bytes_reduce(PyByteArrayObject *self)
return Py_BuildValue("(O(Ns)N)", Py_TYPE(self), latin1, "latin-1", dict);
}
+PyDoc_STRVAR(sizeof_doc,
+"B.__sizeof__() -> int\n\
+ \n\
+Returns the size of B in memory, in bytes");
+static PyObject *
+bytes_sizeof(PyByteArrayObject *self)
+{
+ Py_ssize_t res;
+
+ res = sizeof(PyByteArrayObject) + self->ob_alloc * sizeof(char);
+ return PyInt_FromSsize_t(res);
+}
+
static PySequenceMethods bytes_as_sequence = {
(lenfunc)bytes_length, /* sq_length */
(binaryfunc)PyByteArray_Concat, /* sq_concat */
@@ -3138,6 +3151,7 @@ static PyMethodDef
bytes_methods[] = {
{"__alloc__", (PyCFunction)bytes_alloc, METH_NOARGS, alloc_doc},
{"__reduce__", (PyCFunction)bytes_reduce, METH_NOARGS, reduce_doc},
+ {"__sizeof__", (PyCFunction)bytes_sizeof, METH_NOARGS, sizeof_doc},
{"append", (PyCFunction)bytes_append, METH_O, append__doc__},
{"capitalize", (PyCFunction)stringlib_capitalize, METH_NOARGS,
_Py_capitalize__doc__},