From: Jeremy Hylton Date: Sat, 20 Apr 2002 05:07:05 +0000 (+0000) Subject: backport fix for SF buf #505315 from trunk X-Git-Tag: v2.2.2b1~414 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=8ba1671e393fba0ab164ee974372a38bf0f64fd1;p=thirdparty%2FPython%2Fcpython.git backport fix for SF buf #505315 from trunk --- diff --git a/Lib/test/output/test_scope b/Lib/test/output/test_scope index 5c80b6e5c6d4..a439e441e60a 100644 --- a/Lib/test/output/test_scope +++ b/Lib/test/output/test_scope @@ -21,3 +21,4 @@ test_scope 20. interaction with trace function 20. eval and exec with free variables 21. list comprehension with local variables +22. eval with free variables diff --git a/Lib/test/test_scope.py b/Lib/test/test_scope.py index 85cfed4749b6..f39bbc203720 100644 --- a/Lib/test/test_scope.py +++ b/Lib/test/test_scope.py @@ -512,3 +512,13 @@ try: print bad except NameError: pass + +print "22. eval with free variables" + +def f(x): + def g(): + x + eval("x + 1") + return g + +f(4)() diff --git a/Objects/frameobject.c b/Objects/frameobject.c index 165121d8f871..b1aa156f8176 100644 --- a/Objects/frameobject.c +++ b/Objects/frameobject.c @@ -416,8 +416,6 @@ PyFrame_FastToLocals(PyFrameObject *f) return; } } - if (f->f_nlocals == 0) - return; map = f->f_code->co_varnames; if (!PyDict_Check(locals) || !PyTuple_Check(map)) return; @@ -426,7 +424,8 @@ PyFrame_FastToLocals(PyFrameObject *f) j = PyTuple_Size(map); if (j > f->f_nlocals) j = f->f_nlocals; - map_to_dict(map, j, locals, fast, 0); + if (f->f_nlocals) + map_to_dict(map, j, locals, fast, 0); if (f->f_ncells || f->f_nfreevars) { if (!(PyTuple_Check(f->f_code->co_cellvars) && PyTuple_Check(f->f_code->co_freevars))) { @@ -455,7 +454,7 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) return; locals = f->f_locals; map = f->f_code->co_varnames; - if (locals == NULL || f->f_code->co_nlocals == 0) + if (locals == NULL) return; if (!PyDict_Check(locals) || !PyTuple_Check(map)) return; @@ -464,7 +463,8 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear) j = PyTuple_Size(map); if (j > f->f_nlocals) j = f->f_nlocals; - dict_to_map(f->f_code->co_varnames, j, locals, fast, 0, clear); + if (f->f_nlocals) + dict_to_map(f->f_code->co_varnames, j, locals, fast, 0, clear); if (f->f_ncells || f->f_nfreevars) { if (!(PyTuple_Check(f->f_code->co_cellvars) && PyTuple_Check(f->f_code->co_freevars)))