Author: Brian Kearns <[email protected]>
Branch: stdlib-2.7.4
Changeset: r63197:9fd06caad8aa
Date: 2013-04-10 03:48 -0400
http://bitbucket.org/pypy/pypy/changeset/9fd06caad8aa/

Log:    fix settrace: SETUP_WITH acts like SETUP_FINALLY for setting
        f_lineno (cpython issue14612)

diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -17,7 +17,7 @@
 
 # Define some opcodes used
 g = globals()
-for op in '''DUP_TOP POP_TOP SETUP_LOOP SETUP_EXCEPT SETUP_FINALLY
+for op in '''DUP_TOP POP_TOP SETUP_LOOP SETUP_EXCEPT SETUP_FINALLY SETUP_WITH
 POP_BLOCK END_FINALLY'''.split():
     g[op] = stdlib_opcode.opmap[op]
 HAVE_ARGUMENT = stdlib_opcode.HAVE_ARGUMENT
@@ -518,7 +518,7 @@
         if ord(code[new_lasti]) in (DUP_TOP, POP_TOP):
             raise OperationError(space.w_ValueError,
                   space.wrap("can't jump to 'except' line as there's no 
exception"))
-            
+
         # Don't jump into or out of a finally block.
         f_lasti_setup_addr = -1
         new_lasti_setup_addr = -1
@@ -526,18 +526,18 @@
         addr = 0
         while addr < len(code):
             op = ord(code[addr])
-            if op in (SETUP_LOOP, SETUP_EXCEPT, SETUP_FINALLY):
+            if op in (SETUP_LOOP, SETUP_EXCEPT, SETUP_FINALLY, SETUP_WITH):
                 blockstack.append([addr, False])
             elif op == POP_BLOCK:
                 setup_op = ord(code[blockstack[-1][0]])
-                if setup_op == SETUP_FINALLY:
+                if setup_op == SETUP_FINALLY or setup_op == SETUP_WITH:
                     blockstack[-1][1] = True
                 else:
                     blockstack.pop()
             elif op == END_FINALLY:
                 if len(blockstack) > 0:
                     setup_op = ord(code[blockstack[-1][0]])
-                    if setup_op == SETUP_FINALLY:
+                    if setup_op == SETUP_FINALLY or setup_op == SETUP_WITH:
                         blockstack.pop()
 
             if addr == new_lasti or addr == self.last_instr:
@@ -549,12 +549,12 @@
                         if addr == self.last_instr:
                             f_lasti_setup_addr = setup_addr
                         break
-                    
+
             if op >= HAVE_ARGUMENT:
                 addr += 3
             else:
                 addr += 1
-                
+
         assert len(blockstack) == 0
 
         if new_lasti_setup_addr != f_lasti_setup_addr:
@@ -574,7 +574,7 @@
         while addr < max_addr:
             op = ord(code[addr])
 
-            if op in (SETUP_LOOP, SETUP_EXCEPT, SETUP_FINALLY):
+            if op in (SETUP_LOOP, SETUP_EXCEPT, SETUP_FINALLY, SETUP_WITH):
                 delta_iblock += 1
             elif op == POP_BLOCK:
                 delta_iblock -= 1
diff --git a/pypy/interpreter/test/test_pyframe.py 
b/pypy/interpreter/test/test_pyframe.py
--- a/pypy/interpreter/test/test_pyframe.py
+++ b/pypy/interpreter/test/test_pyframe.py
@@ -66,8 +66,10 @@
 
         def function():
             xyz
+            with open(self.tempfile1, 'w') as f:
+                pass
             return 3
-        
+
         import sys
         sys.settrace(tracer)
         function()
@@ -241,7 +243,7 @@
     def test_trace_ignore_hidden(self):
         import sys
         import _testing
-            
+
         l = []
         def trace(a,b,c):
             l.append((a,b,c))
@@ -293,7 +295,7 @@
             return trace
 
         def g():
-            raise Exception            
+            raise Exception
         def f():
             try:
                 g()
@@ -381,7 +383,6 @@
         assert len(l) == 2
         assert issubclass(l[0][0], Exception)
         assert issubclass(l[1][0], Exception)
-        
 
     def test_trace_generator_finalisation(self):
         import sys
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to