Author: Carl Friedrich Bolz <[email protected]>
Branch: py3.5-refactor-sys_exc_info
Changeset: r88425:3f27a0c78aa5
Date: 2016-11-17 08:56 +0000
http://bitbucket.org/pypy/pypy/changeset/3f27a0c78aa5/
Log: (arigo) typos. write a minimal test now for the expected errors
diff --git a/pypy/interpreter/pyframe.py b/pypy/interpreter/pyframe.py
--- a/pypy/interpreter/pyframe.py
+++ b/pypy/interpreter/pyframe.py
@@ -655,7 +655,9 @@
blockstack.append(addr)
blockstack.append(-1)
elif op == POP_BLOCK:
- assert len(blockstack) >= 3
+ if len(blockstack) < 3:
+ raise oefmt(space.w_SystemError,
+ "blocks not properly nested in this bytecode")
blockstack.pop()
setup_op = ord(code[blockstack.pop()])
if setup_op != SETUP_LOOP:
@@ -670,22 +672,24 @@
assert ii >= 0
handler_addr = blockstack[ii]
if addr == new_lasti:
- new_lasti_setup_addr = handler_addr
+ new_lasti_handler_addr = handler_addr
if addr == self.last_instr:
- f_lasti_setup_addr = handler_addr
+ f_lasti_handler_addr = handler_addr
if op >= HAVE_ARGUMENT:
addr += 3
else:
addr += 1
- assert len(blockstack) == 0
+ if len(blockstack) != 1:
+ raise oefmt(space.w_SystemError,
+ "blocks not properly nested in this bytecode")
if new_lasti_handler_addr != f_lasti_handler_addr:
raise oefmt(space.w_ValueError,
"can't jump into or out of an 'expect' or "
"'finally' block (%d -> %d)",
- f_lasti_handler_addr, new_lasti_setup_addr)
+ f_lasti_handler_addr, new_lasti_handler_addr)
# now we know we're not jumping into or out of a place which
# needs a SysExcInfoRestorer. Check that we're not jumping
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
@@ -87,6 +87,40 @@
sys.settrace(None)
# assert did not crash
+ def test_f_lineno_set_2(self):
+ counter = [0]
+ errors = []
+
+ def tracer(f, event, *args):
+ if event == 'line':
+ counter[0] += 1
+ if counter[0] == 2:
+ try:
+ f.f_lineno += 2
+ except ValueError as e:
+ errors.append(e)
+ return tracer
+
+ # obscure: call open beforehand, py3k's open invokes some app
+ # level code that confuses our tracing (likely due to the
+ # testing env, otherwise it's not a problem)
+ f = open(self.tempfile1, 'w')
+ def function():
+ try:
+ raise ValueError
+ except ValueError:
+ x = 42
+ return x
+
+ import sys
+ sys.settrace(tracer)
+ x = function()
+ sys.settrace(None)
+ assert x == 42
+ assert len(errors) == 1
+ assert str(errors[0]).startswith(
+ "can't jump into or out of an 'expect' or 'finally' block")
+
def test_f_lineno_set_firstline(self):
r"""
seen = []
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit