Skip to content
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
Modules/_io/fileio.c
  • Loading branch information
iritkatriel committed Feb 24, 2023
commit 6157ce8fc44b10aa4a8b5696f4ea819333422e8c
31 changes: 17 additions & 14 deletions Modules/_io/fileio.c
Original file line number Diff line number Diff line change
Expand Up @@ -88,14 +88,13 @@ static PyObject *
fileio_dealloc_warn(fileio *self, PyObject *source)
{
if (self->fd >= 0 && self->closefd) {
PyObject *exc, *val, *tb;
PyErr_Fetch(&exc, &val, &tb);
PyObject *exc = PyErr_GetRaisedException();
if (PyErr_ResourceWarning(source, 1, "unclosed file %R", source)) {
/* Spurious errors can appear at shutdown */
if (PyErr_ExceptionMatches(PyExc_Warning))
PyErr_WriteUnraisable((PyObject *) self);
}
PyErr_Restore(exc, val, tb);
PyErr_SetRaisedException(exc);
}
Py_RETURN_NONE;
}
Expand Down Expand Up @@ -140,28 +139,33 @@ _io_FileIO_close_impl(fileio *self)
/*[clinic end generated code: output=7737a319ef3bad0b input=f35231760d54a522]*/
{
PyObject *res;
PyObject *exc, *val, *tb;
PyObject *exc;
int rc;
res = PyObject_CallMethodOneArg((PyObject*)&PyRawIOBase_Type,
&_Py_ID(close), (PyObject *)self);
if (!self->closefd) {
self->fd = -1;
return res;
}
if (res == NULL)
PyErr_Fetch(&exc, &val, &tb);
if (res == NULL) {
exc = PyErr_GetRaisedException();
}
if (self->finalizing) {
PyObject *r = fileio_dealloc_warn(self, (PyObject *) self);
if (r)
if (r) {
Py_DECREF(r);
else
}
else {
PyErr_Clear();
}
}
rc = internal_close(self);
if (res == NULL)
_PyErr_ChainExceptions(exc, val, tb);
if (rc < 0)
if (res == NULL) {
_PyErr_ChainExceptions1(exc);
}
if (rc < 0) {
Py_CLEAR(res);
}
return res;
}

Expand Down Expand Up @@ -487,10 +491,9 @@ _io_FileIO___init___impl(fileio *self, PyObject *nameobj, const char *mode,
if (!fd_is_own)
self->fd = -1;
if (self->fd >= 0) {
PyObject *exc, *val, *tb;
PyErr_Fetch(&exc, &val, &tb);
PyObject *exc = PyErr_GetRaisedException();
internal_close(self);
_PyErr_ChainExceptions(exc, val, tb);
_PyErr_ChainExceptions1(exc);
}

done:
Expand Down