]> granicus.if.org Git - python/commitdiff
SF patch 419176 from MvL; fixed bug 418977
authorJeremy Hylton <jeremy@alum.mit.edu>
Tue, 8 May 2001 04:08:59 +0000 (04:08 +0000)
committerJeremy Hylton <jeremy@alum.mit.edu>
Tue, 8 May 2001 04:08:59 +0000 (04:08 +0000)
Two errors in dict_to_map() helper used by PyFrame_LocalsToFast().

Lib/test/output/test_scope
Lib/test/test_scope.py
Objects/frameobject.c

index fcd4e7a9793f01f9ae3d343ee7f672922b210884..1a44bb2d14ba4093b9906a64b5c6186407d65741 100644 (file)
@@ -18,3 +18,4 @@ test_scope
 17. class and global
 18. verify that locals() works
 19. var is bound and free in class
+20. interaction with trace function
index c42d881402bef1248b9f6451459cfb5cc2a0c019..fb5379067d68c0813f476535acba96f4313d69d9 100644 (file)
@@ -447,3 +447,23 @@ def f(x):
 
 inst = f(3)()
 verify(inst.a == inst.m())
+
+print "20. interaction with trace function"
+
+import sys
+def tracer(a,b,c):
+    return tracer
+
+def adaptgetter(name, klass, getter):
+    kind, des = getter
+    if kind == 1:       # AV happens when stepping from this line to next
+        if des == "":
+            des = "_%s__%s" % (klass.__name__, name)
+        return lambda obj: getattr(obj, des)
+
+class TestClass:
+    pass
+
+sys.settrace(tracer)
+adaptgetter("foo", TestClass, (1, ""))
+sys.settrace(None)
index 8e78f0f7f79947b2a98a8b12e5495944385623fd..6e66d23b420c5a1b9c55d6a49e61bc8bcf367435 100644 (file)
@@ -283,12 +283,9 @@ dict_to_map(PyObject *map, int nmap, PyObject *dict, PyObject **values,
                PyObject *value = PyDict_GetItem(dict, key);
                Py_XINCREF(value);
                if (deref) {
-                       if (value) {
+                       if (value || clear) {
                                if (PyCell_Set(values[j], value) < 0)
                                        PyErr_Clear();
-                       } else if (clear) {
-                               Py_XDECREF(values[j]);
-                               values[j] = value;
                        }
                } else if (value != NULL || clear) {
                        Py_XDECREF(values[j]);
@@ -370,10 +367,10 @@ PyFrame_LocalsToFast(PyFrameObject *f, int clear)
                        return;
                dict_to_map(f->f_code->co_cellvars, 
                            PyTuple_GET_SIZE(f->f_code->co_cellvars),
-                           locals, fast, 1, clear);
+                           locals, fast + f->f_nlocals, 1, clear);
                dict_to_map(f->f_code->co_freevars, 
                            PyTuple_GET_SIZE(f->f_code->co_freevars),
-                           locals, fast, 1, clear);
+                           locals, fast + f->f_nlocals + f->f_ncells, 1, clear);
        }
        PyErr_Restore(error_type, error_value, error_traceback);
 }