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
2cc71565
Commit
2cc71565
authored
May 25, 2012
by
Hynek Schlawack
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
#4841: Fix FileIO constructor to honor closefd when called repeatedly
Patch by Victor Stinner.
parent
1a01ebc4
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
20 additions
and
3 deletions
+20
-3
Lib/test/test_io.py
Lib/test/test_io.py
+13
-0
Modules/_io/fileio.c
Modules/_io/fileio.c
+7
-3
No files found.
Lib/test/test_io.py
View file @
2cc71565
...
...
@@ -634,6 +634,19 @@ class IOTest(unittest.TestCase):
for
obj
in
test
:
self
.
assertTrue
(
hasattr
(
obj
,
"__dict__"
))
def
test_fileio_closefd
(
self
):
# Issue #4841
with
self
.
open
(
__file__
,
'rb'
)
as
f1
,
\
self
.
open
(
__file__
,
'rb'
)
as
f2
:
fileio
=
self
.
FileIO
(
f1
.
fileno
(),
closefd
=
False
)
# .__init__() must not close f1
fileio
.
__init__
(
f2
.
fileno
(),
closefd
=
False
)
f1
.
readline
()
# .close() must not close f2
fileio
.
close
()
f2
.
readline
()
class
CIOTest
(
IOTest
):
def
test_IOBase_finalize
(
self
):
...
...
Modules/_io/fileio.c
View file @
2cc71565
...
...
@@ -227,9 +227,13 @@ fileio_init(PyObject *oself, PyObject *args, PyObject *kwds)
assert
(
PyFileIO_Check
(
oself
));
if
(
self
->
fd
>=
0
)
{
/* Have to close the existing file first. */
if
(
internal_close
(
self
)
<
0
)
return
-
1
;
if
(
self
->
closefd
)
{
/* Have to close the existing file first. */
if
(
internal_close
(
self
)
<
0
)
return
-
1
;
}
else
self
->
fd
=
-
1
;
}
if
(
!
PyArg_ParseTupleAndKeywords
(
args
,
kwds
,
"O|si:fileio"
,
...
...
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