]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Backport of Tim's checkin 2.178:
authorThomas Wouters <thomas@python.org>
Wed, 11 Jul 2001 12:03:44 +0000 (12:03 +0000)
committerThomas Wouters <thomas@python.org>
Wed, 11 Jul 2001 12:03:44 +0000 (12:03 +0000)
SF bug #438295: [Windows] __init__.py cause strange behavior

Probable fix (the bug report doesn't have enough info to say for sure).
find_init_module():  Insist on a case-sensitive match for __init__ files.
Given __INIT__.PY instead, find_init_module() thought that was fine, but
the later attempt to do find_module("__INIT__.PY") didn't and its caller
silently suppressed the resulting ImportError.  Now find_init_module()
refuses to accept __INIT__.PY to begin with.

Python/import.c

index 15bcca0d201ed6a44fdfb536a0d6347d28fa437f..3d55fe4c33c3ab7057bfac7100d38c9f20773663 100644 (file)
@@ -1194,26 +1194,43 @@ case_ok(char *buf, int len, int namelen, char *name)
 static int
 find_init_module(char *buf)
 {
-       size_t save_len = strlen(buf);
+       const size_t save_len = strlen(buf);
        size_t i = save_len;
+       char *pname;  /* pointer to start of __init__ */
        struct stat statbuf;
 
+/*     For calling case_ok(buf, len, namelen, name):
+ *     /a/b/c/d/e/f/g/h/i/j/k/some_long_module_name.py\0
+ *     ^                      ^                   ^    ^
+ *     |--------------------- buf ---------------------|
+ *     |------------------- len ------------------|
+ *                            |------ name -------|
+ *                            |----- namelen -----|
+ */
        if (save_len + 13 >= MAXPATHLEN)
                return 0;
        buf[i++] = SEP;
-       strcpy(buf+i, "__init__.py");
+       pname = buf + i;
+       strcpy(pname, "__init__.py");
        if (stat(buf, &statbuf) == 0) {
-               buf[save_len] = '\0';
-               return 1;
+               if (case_ok(buf,
+                           save_len + 9,       /* len("/__init__") */
+                           8,                  /* len("__init__") */
+                           pname)) {
+                       buf[save_len] = '\0';
+                       return 1;
+               }
        }
-       i += strlen(buf+i);
-       if (Py_OptimizeFlag)
-               strcpy(buf+i, "o");
-       else
-               strcpy(buf+i, "c");
+       i += strlen(pname);
+       strcpy(buf+i, Py_OptimizeFlag ? "o" : "c");
        if (stat(buf, &statbuf) == 0) {
-               buf[save_len] = '\0';
-               return 1;
+               if (case_ok(buf,
+                           save_len + 9,       /* len("/__init__") */
+                           8,                  /* len("__init__") */
+                           pname)) {
+                       buf[save_len] = '\0';
+                       return 1;
+               }
        }
        buf[save_len] = '\0';
        return 0;