diff options
author | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2005-10-23 18:37:42 (GMT) |
---|---|---|
committer | Neil Schemenauer <nascheme@enme.ucalgary.ca> | 2005-10-23 18:37:42 (GMT) |
commit | 8b528b28f15a78c116fc90303194ad8b1476034d (patch) | |
tree | b172112938d7e6850dd67217308f21eddfcb7356 /Python/compile.c | |
parent | 3a44aaa30fd3f3d39abdbc3608b9f1b08b2443be (diff) | |
download | cpython-8b528b28f15a78c116fc90303194ad8b1476034d.zip cpython-8b528b28f15a78c116fc90303194ad8b1476034d.tar.gz cpython-8b528b28f15a78c116fc90303194ad8b1476034d.tar.bz2 |
Fix private name mangling. The symtable also must do mangles so that
the scope of names can be correctly determined.
Diffstat (limited to 'Python/compile.c')
-rw-r--r-- | Python/compile.c | 20 |
1 files changed, 16 insertions, 4 deletions
diff --git a/Python/compile.c b/Python/compile.c index 5e7f35d..fe6fd50 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -2701,10 +2701,11 @@ inplace_binop(struct compiler *c, operator_ty op) static int compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx) { - int op, scope; + int op, scope, r, arg; enum { OP_FAST, OP_GLOBAL, OP_DEREF, OP_NAME } optype; PyObject *dict = c->u->u_names; + PyObject *mangled; /* XXX AugStore isn't used anywhere! */ /* First check for assignment to __debug__. Param? */ @@ -2713,9 +2714,13 @@ 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); + if (!mangled) + return 0; + op = 0; optype = OP_NAME; - scope = PyST_GetScope(c->u->u_ste, name); + scope = PyST_GetScope(c->u->u_ste, mangled); switch (scope) { case FREE: dict = c->u->u_freevars; @@ -2755,6 +2760,7 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx) "can not delete variable '%s' referenced " "in nested scope", PyString_AS_STRING(name)); + Py_DECREF(mangled); return 0; break; case Param: @@ -2772,7 +2778,8 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx) case Param: assert(0); /* impossible */ } - ADDOP_O(c, op, name, varnames); + ADDOP_O(c, op, mangled, varnames); + Py_DECREF(mangled); return 1; case OP_GLOBAL: switch (ctx) { @@ -2801,7 +2808,12 @@ compiler_nameop(struct compiler *c, identifier name, expr_context_ty ctx) } assert(op); - return compiler_addop_name(c, op, dict, name); + arg = compiler_add_o(c, dict, mangled); + if (arg < 0) + return 0; + r = compiler_addop_i(c, op, arg); + Py_DECREF(mangled); + return r; } static int |