Issue #7865: The close() method of :mod:io objects should not swallow

exceptions raised by the implicit flush().  Also ensure that calling
close() several times is supported.  Patch by Pascal Chambon.
This commit is contained in:
Antoine Pitrou 2010-05-03 16:25:33 +00:00
parent c3ce9e357d
commit f7fd8e4c94
7 changed files with 81 additions and 32 deletions

View file

@ -183,11 +183,7 @@ iobase_close(PyObject *self, PyObject *args)
res = PyObject_CallMethodObjArgs(self, _PyIO_str_flush, NULL);
PyObject_SetAttrString(self, "__IOBase_closed", Py_True);
if (res == NULL) {
/* If flush() fails, just give up */
if (PyErr_ExceptionMatches(PyExc_IOError))
PyErr_Clear();
else
return NULL;
return NULL;
}
Py_XDECREF(res);
Py_RETURN_NONE;