summaryrefslogtreecommitdiffstats
path: root/Python/compile.c
diff options
context:
space:
mode:
authorJeremy Hylton <jeremy@alum.mit.edu>2007-02-27 01:01:59 (GMT)
committerJeremy Hylton <jeremy@alum.mit.edu>2007-02-27 01:01:59 (GMT)
commit37075c5acee9d25b1d0a8e8a945964a5c0c9b1e1 (patch)
tree6eb8ff72a357da9010878e003cc8404267fc0689 /Python/compile.c
parentc6a1ef3fe15632e4476a70d80ad4bb5f61dd5953 (diff)
downloadcpython-37075c5acee9d25b1d0a8e8a945964a5c0c9b1e1.zip
cpython-37075c5acee9d25b1d0a8e8a945964a5c0c9b1e1.tar.gz
cpython-37075c5acee9d25b1d0a8e8a945964a5c0c9b1e1.tar.bz2
Fix long-standing bug in name mangling for package imports
Reported by Mike Verdone.
Diffstat (limited to 'Python/compile.c')
-rw-r--r--Python/compile.c14
1 files changed, 12 insertions, 2 deletions
diff --git a/Python/compile.c b/Python/compile.c
index 9fa3cb1..9b1af92 100644
--- a/Python/compile.c
+++ b/Python/compile.c
@@ -194,7 +194,17 @@ _Py_Mangle(PyObject *privateobj, PyObject *ident)
}
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 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx)
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;