cleanup for the issue 19081 fix - pull the file open and close outside of the
zip_searchorder scanning loop in get_module_code(). [already done in 3.3 and 3.4]
This commit is contained in:
parent
9be238d313
commit
6de7260877
|
@ -1292,6 +1292,8 @@ get_module_code(ZipImporter *self, char *fullname,
|
||||||
char *subname, path[MAXPATHLEN + 1];
|
char *subname, path[MAXPATHLEN + 1];
|
||||||
int len;
|
int len;
|
||||||
struct st_zip_searchorder *zso;
|
struct st_zip_searchorder *zso;
|
||||||
|
FILE *fp;
|
||||||
|
char *archive;
|
||||||
|
|
||||||
subname = get_subname(fullname);
|
subname = get_subname(fullname);
|
||||||
|
|
||||||
|
@ -1299,10 +1301,12 @@ get_module_code(ZipImporter *self, char *fullname,
|
||||||
if (len < 0)
|
if (len < 0)
|
||||||
return NULL;
|
return NULL;
|
||||||
|
|
||||||
|
fp = safely_reopen_archive(self, &archive);
|
||||||
|
if (fp == NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
for (zso = zip_searchorder; *zso->suffix; zso++) {
|
for (zso = zip_searchorder; *zso->suffix; zso++) {
|
||||||
PyObject *code = NULL;
|
PyObject *code = NULL;
|
||||||
FILE *fp;
|
|
||||||
char *archive;
|
|
||||||
|
|
||||||
strcpy(path + len, zso->suffix);
|
strcpy(path + len, zso->suffix);
|
||||||
if (Py_VerboseFlag > 1)
|
if (Py_VerboseFlag > 1)
|
||||||
|
@ -1310,10 +1314,6 @@ get_module_code(ZipImporter *self, char *fullname,
|
||||||
PyString_AsString(self->archive),
|
PyString_AsString(self->archive),
|
||||||
SEP, path);
|
SEP, path);
|
||||||
|
|
||||||
fp = safely_reopen_archive(self, &archive);
|
|
||||||
if (fp == NULL)
|
|
||||||
return NULL;
|
|
||||||
|
|
||||||
toc_entry = PyDict_GetItemString(self->files, path);
|
toc_entry = PyDict_GetItemString(self->files, path);
|
||||||
if (toc_entry != NULL) {
|
if (toc_entry != NULL) {
|
||||||
time_t mtime = 0;
|
time_t mtime = 0;
|
||||||
|
@ -1327,7 +1327,6 @@ get_module_code(ZipImporter *self, char *fullname,
|
||||||
code = get_code_from_data(archive, fp, ispackage,
|
code = get_code_from_data(archive, fp, ispackage,
|
||||||
isbytecode, mtime,
|
isbytecode, mtime,
|
||||||
toc_entry);
|
toc_entry);
|
||||||
fclose(fp);
|
|
||||||
if (code == Py_None) {
|
if (code == Py_None) {
|
||||||
/* bad magic number or non-matching mtime
|
/* bad magic number or non-matching mtime
|
||||||
in byte code, try next */
|
in byte code, try next */
|
||||||
|
@ -1337,11 +1336,12 @@ get_module_code(ZipImporter *self, char *fullname,
|
||||||
if (code != NULL && p_modpath != NULL)
|
if (code != NULL && p_modpath != NULL)
|
||||||
*p_modpath = PyString_AsString(
|
*p_modpath = PyString_AsString(
|
||||||
PyTuple_GetItem(toc_entry, 0));
|
PyTuple_GetItem(toc_entry, 0));
|
||||||
|
fclose(fp);
|
||||||
return code;
|
return code;
|
||||||
}
|
}
|
||||||
fclose(fp);
|
|
||||||
}
|
}
|
||||||
PyErr_Format(ZipImportError, "can't find module '%.200s'", fullname);
|
PyErr_Format(ZipImportError, "can't find module '%.200s'", fullname);
|
||||||
|
fclose(fp);
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue