diff options
author | Antoine Pitrou <solipsis@pitrou.net> | 2012-07-30 00:01:06 +0200 |
---|---|---|
committer | Antoine Pitrou <solipsis@pitrou.net> | 2012-07-30 00:01:06 +0200 |
commit | 8fab35814b65c50661e053f3e3ee73bcc061fd78 (patch) | |
tree | d756cc40037a05678bbf4b02c2b3a72bdc4b57c0 /Modules | |
parent | 7ab2a8bbb0f073b2f7e3c234afa2111853b32d69 (diff) | |
download | cpython-8fab35814b65c50661e053f3e3ee73bcc061fd78.tar.gz |
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 b40513f7a7..03f4c7d14a 100644 --- a/Modules/_io/bytesio.c +++ b/Modules/_io/bytesio.c @@ -834,6 +834,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) { @@ -876,6 +887,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 */ }; |