mirror of
https://github.com/python/cpython.git
synced 2025-11-01 18:51:43 +00:00
call close on the underlying stream even if flush raises (closes #16597)
Patch by Serhiy Storchaka.
This commit is contained in:
parent
5ff3f73d94
commit
68623614f0
5 changed files with 80 additions and 13 deletions
|
|
@ -484,7 +484,7 @@ buffered_closed_get(buffered *self, void *context)
|
|||
static PyObject *
|
||||
buffered_close(buffered *self, PyObject *args)
|
||||
{
|
||||
PyObject *res = NULL;
|
||||
PyObject *res = NULL, *exc = NULL, *val, *tb;
|
||||
int r;
|
||||
|
||||
CHECK_INITIALIZED(self)
|
||||
|
|
@ -512,13 +512,29 @@ buffered_close(buffered *self, PyObject *args)
|
|||
res = PyObject_CallMethodObjArgs((PyObject *)self, _PyIO_str_flush, NULL);
|
||||
if (!ENTER_BUFFERED(self))
|
||||
return NULL;
|
||||
if (res == NULL) {
|
||||
goto end;
|
||||
}
|
||||
Py_XDECREF(res);
|
||||
if (res == NULL)
|
||||
PyErr_Fetch(&exc, &val, &tb);
|
||||
else
|
||||
Py_DECREF(res);
|
||||
|
||||
res = PyObject_CallMethodObjArgs(self->raw, _PyIO_str_close, NULL);
|
||||
|
||||
if (exc != NULL) {
|
||||
if (res != NULL) {
|
||||
Py_CLEAR(res);
|
||||
PyErr_Restore(exc, val, tb);
|
||||
}
|
||||
else {
|
||||
PyObject *val2;
|
||||
Py_DECREF(exc);
|
||||
Py_XDECREF(tb);
|
||||
PyErr_Fetch(&exc, &val2, &tb);
|
||||
PyErr_NormalizeException(&exc, &val2, &tb);
|
||||
PyException_SetContext(val2, val);
|
||||
PyErr_Restore(exc, val2, tb);
|
||||
}
|
||||
}
|
||||
|
||||
end:
|
||||
LEAVE_BUFFERED(self)
|
||||
return res;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue