mirror of
https://github.com/python/cpython.git
synced 2025-09-26 10:19:53 +00:00
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:
parent
c3ce9e357d
commit
f7fd8e4c94
7 changed files with 81 additions and 32 deletions
|
@ -2405,16 +2405,30 @@ static PyObject *
|
|||
textiowrapper_close(textio *self, PyObject *args)
|
||||
{
|
||||
PyObject *res;
|
||||
int r;
|
||||
CHECK_INITIALIZED(self);
|
||||
res = PyObject_CallMethod((PyObject *)self, "flush", NULL);
|
||||
if (res == NULL) {
|
||||
/* If flush() fails, just give up */
|
||||
PyErr_Clear();
|
||||
}
|
||||
else
|
||||
Py_DECREF(res);
|
||||
|
||||
return PyObject_CallMethod(self->buffer, "close", NULL);
|
||||
res = textiowrapper_closed_get(self, NULL);
|
||||
if (res == NULL)
|
||||
return NULL;
|
||||
r = PyObject_IsTrue(res);
|
||||
Py_DECREF(res);
|
||||
if (r < 0)
|
||||
return NULL;
|
||||
|
||||
if (r > 0) {
|
||||
Py_RETURN_NONE; /* stream already closed */
|
||||
}
|
||||
else {
|
||||
res = PyObject_CallMethod((PyObject *)self, "flush", NULL);
|
||||
if (res == NULL) {
|
||||
return NULL;
|
||||
}
|
||||
else
|
||||
Py_DECREF(res);
|
||||
|
||||
return PyObject_CallMethod(self->buffer, "close", NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static PyObject *
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue