[Python-checkins] cpython (2.7): cleanup for the issue 19081 fix - pull the file open and close outside of the
gregory.p.smith
python-checkins at python.org
Wed Jan 8 03:40:02 CET 2014
http://hg.python.org/cpython/rev/5609135c6e86
changeset: 88352:5609135c6e86
branch: 2.7
parent: 88339:89b3836f7378
user: Gregory P. Smith <greg at krypto.org>
date: Tue Jan 07 18:39:48 2014 -0800
summary:
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]
files:
Modules/zipimport.c | 16 ++++++++--------
1 files changed, 8 insertions(+), 8 deletions(-)
diff --git a/Modules/zipimport.c b/Modules/zipimport.c
--- a/Modules/zipimport.c
+++ b/Modules/zipimport.c
@@ -1292,6 +1292,8 @@
char *subname, path[MAXPATHLEN + 1];
int len;
struct st_zip_searchorder *zso;
+ FILE *fp;
+ char *archive;
subname = get_subname(fullname);
@@ -1299,10 +1301,12 @@
if (len < 0)
return NULL;
+ fp = safely_reopen_archive(self, &archive);
+ if (fp == NULL)
+ return NULL;
+
for (zso = zip_searchorder; *zso->suffix; zso++) {
PyObject *code = NULL;
- FILE *fp;
- char *archive;
strcpy(path + len, zso->suffix);
if (Py_VerboseFlag > 1)
@@ -1310,10 +1314,6 @@
PyString_AsString(self->archive),
SEP, path);
- fp = safely_reopen_archive(self, &archive);
- if (fp == NULL)
- return NULL;
-
toc_entry = PyDict_GetItemString(self->files, path);
if (toc_entry != NULL) {
time_t mtime = 0;
@@ -1327,7 +1327,6 @@
code = get_code_from_data(archive, fp, ispackage,
isbytecode, mtime,
toc_entry);
- fclose(fp);
if (code == Py_None) {
/* bad magic number or non-matching mtime
in byte code, try next */
@@ -1337,11 +1336,12 @@
if (code != NULL && p_modpath != NULL)
*p_modpath = PyString_AsString(
PyTuple_GetItem(toc_entry, 0));
+ fclose(fp);
return code;
}
- fclose(fp);
}
PyErr_Format(ZipImportError, "can't find module '%.200s'", fullname);
+ fclose(fp);
return NULL;
}
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list