Issue #23694: Enhance _Py_fopen(), it now raises an exception on error

* If fopen() fails, OSError is raised with the original filename object.
* The GIL is now released while calling fopen()
This commit is contained in:
Victor Stinner 2015-03-18 01:39:23 +01:00
parent a555cfcb73
commit e42ccd2bfd
5 changed files with 44 additions and 24 deletions

View file

@ -875,7 +875,7 @@ read_directory(PyObject *archive)
fp = _Py_fopen_obj(archive, "rb");
if (fp == NULL) {
if (!PyErr_Occurred())
if (PyErr_ExceptionMatches(PyExc_OSError))
PyErr_Format(ZipImportError, "can't open Zip file: %R", archive);
return NULL;
}
@ -1073,12 +1073,8 @@ get_data(PyObject *archive, PyObject *toc_entry)
}
fp = _Py_fopen_obj(archive, "rb");
if (!fp) {
if (!PyErr_Occurred())
PyErr_Format(PyExc_IOError,
"zipimport: can not open file %U", archive);
if (!fp)
return NULL;
}
/* Check to make sure the local file header is correct */
if (fseek(fp, file_offset, 0) == -1) {