diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-07-29 22:01:06 (GMT) |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-07-29 22:01:06 (GMT) |
commit | baee34c3442592785171abce5560ae2b618c5645 (patch) | |
tree | 1b42115bf6527a5c077b9ef23a25c98b03b4c585 /Modules | |
parent | bff5df0d1ca6c37a3454dd5dff5d587af27ab8be (diff) | |
download | cpython-baee34c3442592785171abce5560ae2b618c5645.zip cpython-baee34c3442592785171abce5560ae2b618c5645.tar.gz cpython-baee34c3442592785171abce5560ae2b618c5645.tar.bz2 |
Issue #15489: Add a __sizeof__ implementation for BytesIO objects.
Patch by Serhiy Storchaka.
Diffstat (limited to 'Modules')
-rw-r--r-- | Modules/_io/bytesio.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Modules/_io/bytesio.c b/Modules/_io/bytesio.c index 51fad21..ae8c1c1 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -794,6 +794,17 @@ bytesio_init(bytesio *self, PyObject *args, PyObject *kwds) return 0; } +static PyObject * +bytesio_sizeof(bytesio *self, void *unused) +{ + Py_ssize_t res; + + res = sizeof(bytesio); + if (self->buf) + res += self->buf_size; + return PyLong_FromSsize_t(res); +} + static int bytesio_traverse(bytesio *self, visitproc visit, void *arg) { @@ -835,6 +846,7 @@ static struct PyMethodDef bytesio_methods[] = { {"truncate", (PyCFunction)bytesio_truncate, METH_VARARGS, truncate_doc}, {"__getstate__", (PyCFunction)bytesio_getstate, METH_NOARGS, NULL}, {"__setstate__", (PyCFunction)bytesio_setstate, METH_O, NULL}, + {"__sizeof__", (PyCFunction)bytesio_sizeof, METH_NOARGS, NULL}, {NULL, NULL} /* sentinel */ }; |