summaryrefslogtreecommitdiff
path: root/Modules/_io
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2015-02-21 00:35:09 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2015-02-21 00:35:09 +0200
commite0c33606506b8475e3d396a83d47fc3f1ebce893 (patch)
treecaa00832b7beb2f5bda7601f55999de5bcd5c4d7 /Modules/_io
parent66dbd68ea7492d3191d9bd01e23b0081db7bfe98 (diff)
downloadcpython-e0c33606506b8475e3d396a83d47fc3f1ebce893.tar.gz
Issue #5700: io.FileIO() called flush() after closing the file.
flush() was not called in close() if closefd=False.
Diffstat (limited to 'Modules/_io')
-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 a2b253bd03..80ca99c5bc 100644
--- a/Modules/_io/fileio.c
+++ b/Modules/_io/fileio.c
@@ -126,11 +126,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)
@@ -138,12 +145,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 *