summaryrefslogtreecommitdiffstats
path: root/Modules/_io
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-07-29 17:02:46 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-07-29 17:02:46 (GMT)
commitbff5df0d1ca6c37a3454dd5dff5d587af27ab8be (patch)
treeca1a3ab5703fd2e2813499d02a573c1f9a96c0fa /Modules/_io
parentc02e1e65c45753dafc7ae1b6c0b120323b2a10b7 (diff)
downloadcpython-bff5df0d1ca6c37a3454dd5dff5d587af27ab8be.zip
cpython-bff5df0d1ca6c37a3454dd5dff5d587af27ab8be.tar.gz
cpython-bff5df0d1ca6c37a3454dd5dff5d587af27ab8be.tar.bz2
Issue #15487: Add a __sizeof__ implementation for buffered I/O objects.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Modules/_io')
-rw-r--r--Modules/_io/bufferedio.c14
1 files changed, 14 insertions, 0 deletions
diff --git a/Modules/_io/bufferedio.c b/Modules/_io/bufferedio.c
index 9b403d9..dc5c9b5 100644
--- a/Modules/_io/bufferedio.c
+++ b/Modules/_io/bufferedio.c
@@ -386,6 +386,17 @@ buffered_dealloc(buffered *self)
Py_TYPE(self)->tp_free((PyObject *)self);
}
+static PyObject *
+buffered_sizeof(buffered *self, void *unused)
+{
+ Py_ssize_t res;
+
+ res = sizeof(buffered);
+ if (self->buffer)
+ res += self->buffer_size;
+ return PyLong_FromSsize_t(res);
+}
+
static int
buffered_traverse(buffered *self, visitproc visit, void *arg)
{
@@ -1560,6 +1571,7 @@ static PyMethodDef bufferedreader_methods[] = {
{"seek", (PyCFunction)buffered_seek, METH_VARARGS},
{"tell", (PyCFunction)buffered_tell, METH_NOARGS},
{"truncate", (PyCFunction)buffered_truncate, METH_VARARGS},
+ {"__sizeof__", (PyCFunction)buffered_sizeof, METH_NOARGS},
{NULL, NULL}
};
@@ -1952,6 +1964,7 @@ static PyMethodDef bufferedwriter_methods[] = {
{"flush", (PyCFunction)buffered_flush, METH_NOARGS},
{"seek", (PyCFunction)buffered_seek, METH_VARARGS},
{"tell", (PyCFunction)buffered_tell, METH_NOARGS},
+ {"__sizeof__", (PyCFunction)buffered_sizeof, METH_NOARGS},
{NULL, NULL}
};
@@ -2347,6 +2360,7 @@ static PyMethodDef bufferedrandom_methods[] = {
{"readline", (PyCFunction)buffered_readline, METH_VARARGS},
{"peek", (PyCFunction)buffered_peek, METH_VARARGS},
{"write", (PyCFunction)bufferedwriter_write, METH_VARARGS},
+ {"__sizeof__", (PyCFunction)buffered_sizeof, METH_NOARGS},
{NULL, NULL}
};