mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #15487: Add a __sizeof__ implementation for buffered I/O objects.
Patch by Serhiy Storchaka.
This commit is contained in:
parent
33f799725c
commit
10f0c50a0b
3 changed files with 34 additions and 3 deletions
|
@ -383,6 +383,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)
|
||||
{
|
||||
|
@ -1591,6 +1602,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}
|
||||
};
|
||||
|
||||
|
@ -1985,6 +1997,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}
|
||||
};
|
||||
|
||||
|
@ -2384,6 +2397,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}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue