Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 40960:541a8b1b5da7 legacy-trunk
Fix long-standing bug in name mangling for package imports
Reported by Mike Verdone.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Tue, 27 Feb 2007 01:01:59 +0000 |
| parents | c6774eb3a067 |
| children | 0b47446cc408 |
line wrap: on
line diff
--- a/Python/compile.c Mon Feb 26 23:54:17 2007 +0000 +++ b/Python/compile.c Tue Feb 27 01:01:59 2007 +0000 @@ -194,7 +194,17 @@ } p = PyString_AsString(privateobj); nlen = strlen(name); - if (name[nlen-1] == '_' && name[nlen-2] == '_') { + /* Don't mangle __id__ or names with dots. + + The only time a name with a dot can occur is when + we are compiling an import statement that has a + package name. + + TODO(jhylton): Decide whether we want to support + mangling of the module name, e.g. __M.X. + */ + if ((name[nlen-1] == '_' && name[nlen-2] == '_') + || strchr(name, '.')) { Py_INCREF(ident); return ident; /* Don't mangle __whatever__ */ } @@ -2243,7 +2253,7 @@ return compiler_error(c, "can not assign to __debug__"); } - mangled = _Py_Mangle(c->u->u_private, name); +mangled = _Py_Mangle(c->u->u_private, name); if (!mangled) return 0;
