summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorHynek Schlawack <hs@ox.cx>2012-05-25 08:27:43 (GMT)
committerHynek Schlawack <hs@ox.cx>2012-05-25 08:27:43 (GMT)
commit9866d96e48e884edb8d7db468c03db316503bbbc (patch)
tree85d09a932a4453937921b777437ed8cf4e9fa566 /Modules
parent18eac4a1d67b3b4a6f51608f0c3c82fa662100b0 (diff)
parent2cc71565154b2092da9b15e205567c13e07f331a (diff)
downloadcpython-9866d96e48e884edb8d7db468c03db316503bbbc.zip
cpython-9866d96e48e884edb8d7db468c03db316503bbbc.tar.gz
cpython-9866d96e48e884edb8d7db468c03db316503bbbc.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 df3affe..726d17b 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -230,9 +230,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|siO:fileio",