diff options
author | Hynek Schlawack <hs@ox.cx> | 2012-05-25 08:05:53 (GMT) |
---|---|---|
committer | Hynek Schlawack <hs@ox.cx> | 2012-05-25 08:05:53 (GMT) |
commit | 2cc71565154b2092da9b15e205567c13e07f331a (patch) | |
tree | 4ce37916feb8fa7c9d496281f793038893446e52 /Modules/_io/fileio.c | |
parent | 1a01ebc41cbbfc127865f82656879a58c2560543 (diff) | |
download | cpython-2cc71565154b2092da9b15e205567c13e07f331a.zip cpython-2cc71565154b2092da9b15e205567c13e07f331a.tar.gz cpython-2cc71565154b2092da9b15e205567c13e07f331a.tar.bz2 |
#4841: Fix FileIO constructor to honor closefd when called repeatedly
Patch by Victor Stinner.
Diffstat (limited to 'Modules/_io/fileio.c')
-rw-r--r-- | Modules/_io/fileio.c | 10 |
1 files changed, 7 insertions, 3 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c index d5b03ee..c51d697 100644 --- a/Modules/_io/fileio.c +++ b/Modules/_io/fileio.c @@ -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", |