Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
baee34c3
Commit
baee34c3
authored
Jul 30, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15489: Add a __sizeof__ implementation for BytesIO objects.
Patch by Serhiy Storchaka.
parent
bff5df0d
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
26 additions
and
0 deletions
+26
-0
Lib/test/test_memoryio.py
Lib/test/test_memoryio.py
+11
-0
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_io/bytesio.c
Modules/_io/bytesio.c
+12
-0
No files found.
Lib/test/test_memoryio.py
View file @
baee34c3
...
...
@@ -638,6 +638,17 @@ class CBytesIOTest(PyBytesIOTest):
memio
.
close
()
self
.
assertRaises
(
ValueError
,
memio
.
__setstate__
,
(
b"closed"
,
0
,
None
))
check_sizeof
=
support
.
check_sizeof
@
support
.
cpython_only
def
test_sizeof
(
self
):
basesize
=
support
.
calcobjsize
(
b'P2PP2P'
)
check
=
self
.
check_sizeof
self
.
assertEqual
(
object
.
__sizeof__
(
io
.
BytesIO
()),
basesize
)
check
(
io
.
BytesIO
(),
basesize
)
check
(
io
.
BytesIO
(
b'a'
),
basesize
+
1
+
1
)
check
(
io
.
BytesIO
(
b'a'
*
1000
),
basesize
+
1000
+
1
)
class
CStringIOTest
(
PyStringIOTest
):
ioclass
=
io
.
StringIO
...
...
Misc/NEWS
View file @
baee34c3
...
...
@@ -92,6 +92,9 @@ Core and Builtins
Library
-------
- Issue #15489: Add a __sizeof__ implementation for BytesIO objects.
Patch by Serhiy Storchaka.
- Issue #15487: Add a __sizeof__ implementation for buffered I/O objects.
Patch by Serhiy Storchaka.
...
...
Modules/_io/bytesio.c
View file @
baee34c3
...
...
@@ -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 */
};
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment