]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
backport fix for SF buf #505315 from trunk
authorJeremy Hylton <jeremy@alum.mit.edu>
Sat, 20 Apr 2002 05:07:05 +0000 (05:07 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Sat, 20 Apr 2002 05:07:05 +0000 (05:07 +0000)
Lib/test/output/test_scope
Lib/test/test_scope.py
Objects/frameobject.c

index 5c80b6e5c6d463bd4187ed76617e3f86ba70f82f..a439e441e60aeaf009519badb3e2c19088ee12b7 100644 (file)
@@ -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
index 85cfed4749b669024999d915cc57522e40a218a6..f39bbc2037203d041c39fad457f769213c6d814a 100644 (file)
@@ -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)()
index 165121d8f8715505ff3254e28a9fd23136438c95..b1aa156f81768c497df330b8432a0968e826ef15 100644 (file)
@@ -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)))