summaryrefslogtreecommitdiffstats
path: root/Modules
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-20 22:35:53 (GMT)
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-20 22:35:53 (GMT)
commit254dd59068e027f98a1f9ac5b81e43e4685e5ac6 (patch)
tree5d19e8dacb9eec2902dc7db23c765fa61b9cd0a4 /Modules
parent7065f376e08bce1657904d3b2acb9989949f3efc (diff)
parenta3712a9a6c9a05de287d2403cdb5aecbc417ce93 (diff)
downloadcpython-254dd59068e027f98a1f9ac5b81e43e4685e5ac6.zip
cpython-254dd59068e027f98a1f9ac5b81e43e4685e5ac6.tar.gz
cpython-254dd59068e027f98a1f9ac5b81e43e4685e5ac6.tar.bz2
Issue #5700: io.FileIO() called flush() after closing the file.
flush() was not called in close() if closefd=False.
Diffstat (limited to 'Modules')
-rw-r--r--Modules/_io/fileio.c21
1 files changed, 14 insertions, 7 deletions
diff --git a/Modules/_io/fileio.c b/Modules/_io/fileio.c
index 2435513..9c67394 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -127,11 +127,18 @@ internal_close(fileio *self)
static PyObject *
fileio_close(fileio *self)
{
+ PyObject *res;
+ PyObject *exc, *val, *tb;
+ int rc;
_Py_IDENTIFIER(close);
+ res = _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
+ &PyId_close, "O", self);
if (!self->closefd) {
self->fd = -1;
- Py_RETURN_NONE;
+ return res;
}
+ if (res == NULL)
+ PyErr_Fetch(&exc, &val, &tb);
if (self->finalizing) {
PyObject *r = fileio_dealloc_warn(self, (PyObject *) self);
if (r)
@@ -139,12 +146,12 @@ fileio_close(fileio *self)
else
PyErr_Clear();
}
- errno = internal_close(self);
- if (errno < 0)
- return NULL;
-
- return _PyObject_CallMethodId((PyObject*)&PyRawIOBase_Type,
- &PyId_close, "O", self);
+ rc = internal_close(self);
+ if (res == NULL)
+ _PyErr_ChainExceptions(exc, val, tb);
+ if (rc < 0)
+ Py_CLEAR(res);
+ return res;
}
static PyObject *