summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-05-25 07:24:18 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-05-25 07:24:18 (GMT)
commit877effc2986ad30ecd5454811b0449bcfe3037f5 (patch)
tree0987ab6f596a0f6e3975f1e531d7dd76dc01fdbc /Modules
parent8e6287f50df14fb50cea43036ef4eec3998f823e (diff)
downloadcpython-877effc2986ad30ecd5454811b0449bcfe3037f5.zip
cpython-877effc2986ad30ecd5454811b0449bcfe3037f5.tar.gz
cpython-877effc2986ad30ecd5454811b0449bcfe3037f5.tar.bz2
#4841: Fix FileIO constructor to honor closefd when called repeatedly
Patch by Victor Stinner.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/fileio.c10
1 files changed, 7 insertions, 3 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 0048240..d1941df 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -198,9 +198,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",