diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-12-20 11:55:16 -0600 |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-12-20 11:55:16 -0600 |
commit | 4c05969fc41d83e7da9ee3a2e15285a60b68ce23 (patch) | |
tree | c8a4ea23a1f982f788d8b1619d218b009091f3c9 /Modules/_io/textio.c | |
parent | 7643c92cdd0e8a3cfd83be9edae3964097b63f0e (diff) | |
parent | 68623614f095c8589ff17c004b9a05c537afc01f (diff) | |
download | cpython-git-4c05969fc41d83e7da9ee3a2e15285a60b68ce23.tar.gz |
merge 3.3 (#16597)
Diffstat (limited to 'Modules/_io/textio.c')
-rw-r--r-- | Modules/_io/textio.c | 24 |
1 files changed, 20 insertions, 4 deletions
diff --git a/Modules/_io/textio.c b/Modules/_io/textio.c index 8344d43767..4fc0caa84e 100644 --- a/Modules/_io/textio.c +++ b/Modules/_io/textio.c @@ -2548,6 +2548,7 @@ textiowrapper_close(textio *self, PyObject *args) Py_RETURN_NONE; /* stream already closed */ } else { + PyObject *exc = NULL, *val, *tb; if (self->deallocating) { res = _PyObject_CallMethodId(self->buffer, &PyId__dealloc_warn, "O", self); if (res) @@ -2556,13 +2557,28 @@ textiowrapper_close(textio *self, PyObject *args) PyErr_Clear(); } res = _PyObject_CallMethodId((PyObject *)self, &PyId_flush, NULL); - if (res == NULL) { - return NULL; - } + if (res == NULL) + PyErr_Fetch(&exc, &val, &tb); else Py_DECREF(res); - return _PyObject_CallMethodId(self->buffer, &PyId_close, NULL); + res = _PyObject_CallMethodId(self->buffer, &PyId_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); + } + } + return res; } } |