Mercurial > cpython-lru_cache-weakref
diff Python/compile.c @ 30226:806179400f35 legacy-trunk
Fix for SF bug [ 784075 ] Fatal Python error: unknown scope
Make sure the inner function is not compiled when there is a syntax
error in the default arguments.
| author | Jeremy Hylton <jeremy@alum.mit.edu> |
|---|---|
| date | Thu, 28 Aug 2003 14:42:14 +0000 |
| parents | 3442e7cdace8 |
| children | c2c10f1eb8e2 |
line wrap: on
line diff
--- a/Python/compile.c Thu Aug 28 02:09:26 2003 +0000 +++ b/Python/compile.c Thu Aug 28 14:42:14 2003 +0000 @@ -3666,10 +3666,16 @@ XXX if we could pop the exception still on the stack */ } +/* Return the number of default values in the argument list. + + If a non-default argument follows a default argument, set an + exception and return -1. +*/ + static int com_argdefs(struct compiling *c, node *n) { - int i, nch, nargs, ndefs; + int i, nch, ndefs; if (TYPE(n) == lambdef) { /* lambdef: 'lambda' [varargslist] ':' test */ n = CHILD(n, 1); @@ -3686,14 +3692,12 @@ (fpdef ['=' test] ',')* '*' ....... | fpdef ['=' test] (',' fpdef ['=' test])* [','] */ nch = NCH(n); - nargs = 0; ndefs = 0; for (i = 0; i < nch; i++) { int t; if (TYPE(CHILD(n, i)) == STAR || TYPE(CHILD(n, i)) == DOUBLESTAR) break; - nargs++; i++; if (i >= nch) t = RPAR; /* Anything except EQUAL or COMMA */ @@ -3710,9 +3714,11 @@ } else { /* Treat "(a=1, b)" as an error */ - if (ndefs) + if (ndefs) { com_error(c, PyExc_SyntaxError, "non-default argument follows default argument"); + return -1; + } } if (t != COMMA) break; @@ -3727,6 +3733,8 @@ int ndefs; REQ(n, funcdef); /* funcdef: 'def' NAME parameters ':' suite */ ndefs = com_argdefs(c, n); + if (ndefs < 0) + return; symtable_enter_scope(c->c_symtable, STR(CHILD(n, 1)), TYPE(n), n->n_lineno); co = (PyObject *)icompile(n, c);
