diff options
author | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-05 17:23:16 (GMT) |
---|---|---|
committer | Jeremy Hylton <jeremy@alum.mit.edu> | 2001-02-05 17:23:16 (GMT) |
commit | 2524d699f572c5839dcc5c6a7ce06533ac2ef0a6 (patch) | |
tree | 0049b47096e0dfc1fc1698594cc7de97ae53b57f | |
parent | ecdaadb7c6db269e6f81d0f89f1918e3d029b6e8 (diff) | |
download | cpython-2524d699f572c5839dcc5c6a7ce06533ac2ef0a6.zip cpython-2524d699f572c5839dcc5c6a7ce06533ac2ef0a6.tar.gz cpython-2524d699f572c5839dcc5c6a7ce06533ac2ef0a6.tar.bz2 |
SF patch 103596 by Nick Mathewson: rause UnboundLocalError for
uninitialized free variables
-rw-r--r-- | Python/ceval.c | 16 |
1 files changed, 16 insertions, 0 deletions
diff --git a/Python/ceval.c b/Python/ceval.c index 264ba30..9d65495 100644 --- a/Python/ceval.c +++ b/Python/ceval.c @@ -1646,6 +1646,22 @@ eval_code2(PyCodeObject *co, PyObject *globals, PyObject *locals, case LOAD_DEREF: x = freevars[oparg]; w = PyCell_Get(x); + if (w == NULL) { + if (oparg < f->f_ncells) + v = PyTuple_GetItem(co->co_cellvars, + oparg); + else + v = PyTuple_GetItem( + co->co_freevars, + oparg - f->f_ncells); + + format_exc_check_arg( + PyExc_UnboundLocalError, + UNBOUNDLOCAL_ERROR_MSG, + v); + err = -1; + break; + } Py_INCREF(w); PUSH(w); break; |