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
bff5df0d
Commit
bff5df0d
authored
Jul 29, 2012
by
Antoine Pitrou
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Issue #15487: Add a __sizeof__ implementation for buffered I/O objects.
Patch by Serhiy Storchaka.
parent
c02e1e65
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
35 additions
and
4 deletions
+35
-4
Lib/test/test_io.py
Lib/test/test_io.py
+18
-4
Misc/NEWS
Misc/NEWS
+3
-0
Modules/_io/bufferedio.c
Modules/_io/bufferedio.c
+14
-0
No files found.
Lib/test/test_io.py
View file @
bff5df0d
...
...
@@ -748,6 +748,20 @@ class CommonBufferedTests:
buf
.
raw
=
x
class
SizeofTest
:
@
support
.
cpython_only
def
test_sizeof
(
self
):
bufsize1
=
4096
bufsize2
=
8192
rawio
=
self
.
MockRawIO
()
bufio
=
self
.
tp
(
rawio
,
buffer_size
=
bufsize1
)
size
=
sys
.
getsizeof
(
bufio
)
-
bufsize1
rawio
=
self
.
MockRawIO
()
bufio
=
self
.
tp
(
rawio
,
buffer_size
=
bufsize2
)
self
.
assertEqual
(
sys
.
getsizeof
(
bufio
),
size
+
bufsize2
)
class
BufferedReaderTest
(
unittest
.
TestCase
,
CommonBufferedTests
):
read_mode
=
"rb"
...
...
@@ -931,7 +945,7 @@ class BufferedReaderTest(unittest.TestCase, CommonBufferedTests):
"failed for {}: {} != 0"
.
format
(
n
,
rawio
.
_extraneous_reads
))
class
CBufferedReaderTest
(
BufferedReaderTest
):
class
CBufferedReaderTest
(
BufferedReaderTest
,
SizeofTest
):
tp
=
io
.
BufferedReader
def
test_constructor
(
self
):
...
...
@@ -1194,7 +1208,7 @@ class BufferedWriterTest(unittest.TestCase, CommonBufferedTests):
self
.
tp
(
self
.
MockRawIO
(),
8
,
12
)
class
CBufferedWriterTest
(
BufferedWriterTest
):
class
CBufferedWriterTest
(
BufferedWriterTest
,
SizeofTest
):
tp
=
io
.
BufferedWriter
def
test_constructor
(
self
):
...
...
@@ -1582,8 +1596,8 @@ class BufferedRandomTest(BufferedReaderTest, BufferedWriterTest):
f
.
flush
()
self
.
assertEqual
(
raw
.
getvalue
(),
b'1b
\
n
2def
\
n
3
\
n
'
)
class
CBufferedRandomTest
(
CBufferedReaderTest
,
CBufferedWriterTest
,
BufferedRandom
Test
):
class
CBufferedRandomTest
(
CBufferedReaderTest
,
CBufferedWriterTest
,
BufferedRandomTest
,
Sizeof
Test
):
tp
=
io
.
BufferedRandom
def
test_constructor
(
self
):
...
...
Misc/NEWS
View file @
bff5df0d
...
...
@@ -92,6 +92,9 @@ Core and Builtins
Library
-------
- Issue #15487: Add a __sizeof__ implementation for buffered I/O objects.
Patch by Serhiy Storchaka.
- Issue #15402: An issue in the struct module that caused sys.getsizeof to
return incorrect results for struct.Struct instances has been fixed.
Initial patch by Serhiy Storchaka.
...
...
Modules/_io/bufferedio.c
View file @
bff5df0d
...
...
@@ -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
}
};
...
...
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