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
bf775542
Commit
bf775542
authored
Oct 16, 2010
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
iterators passed to writelines() can close their files; don't segfault #10125
parent
f76942d6
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
16 additions
and
0 deletions
+16
-0
Lib/test/test_file2k.py
Lib/test/test_file2k.py
+8
-0
Misc/NEWS
Misc/NEWS
+3
-0
Objects/fileobject.c
Objects/fileobject.c
+5
-0
No files found.
Lib/test/test_file2k.py
View file @
bf775542
...
...
@@ -135,6 +135,14 @@ class AutoFileTests(unittest.TestCase):
def
testReadWhenWriting
(
self
):
self
.
assertRaises
(
IOError
,
self
.
f
.
read
)
def
testNastyWritelinesGenerator
(
self
):
def
nasty
():
for
i
in
range
(
5
):
if
i
==
3
:
self
.
f
.
close
()
yield
str
(
i
)
self
.
assertRaises
(
ValueError
,
self
.
f
.
writelines
,
nasty
())
def
testIssue5677
(
self
):
# Remark: Do not perform more than one test per open file,
# since that does NOT catch the readline error on Windows.
...
...
Misc/NEWS
View file @
bf775542
...
...
@@ -10,6 +10,9 @@ What's New in Python 2.7.1?
Core and Builtins
-----------------
- Issue #10125: Don't segfault when the iterator passed to ``file.writelines()``
closes the file.
- Issue #9997: Don't let the name "top" have special significance in scope
resolution.
...
...
Objects/fileobject.c
View file @
bf775542
...
...
@@ -1849,6 +1849,11 @@ file_writelines(PyFileObject *f, PyObject *seq)
}
PyList_SetItem
(
list
,
j
,
line
);
}
/* The iterator might have closed the file on us. */
if
(
f
->
f_fp
==
NULL
)
{
err_closed
();
goto
error
;
}
}
if
(
j
==
0
)
break
;
...
...
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