Python 3.4 assertion handling. Improve verify

3.4 has jump optimization like 3.5.
verify.py: show mismatch on verification mismatch
This commit is contained in:
rocky
2016-07-14 05:19:16 -04:00
parent 1e25ffa879
commit 7b7a9fa4cf
10 changed files with 35 additions and 10 deletions

View File

@@ -134,16 +134,19 @@ class Scanner3(scan.Scanner):
bytecode = Bytecode(co, self.opc)
# Scan for assertions. Later we will
# turn 'LOAD_GLOBAL' to 'LOAD_ASSERT' for those
# assertions
# turn 'LOAD_GLOBAL' to 'LOAD_ASSERT'.
# 'LOAD_ASSERT' is used in assert statements.
self.load_asserts = set()
bs = list(bytecode)
n = len(bs)
for i in range(n):
inst = bs[i]
if inst.opname == 'POP_JUMP_IF_TRUE' and i+1 < n:
next_inst = bs[i+1]
# We need to detect the difference between
# "raise AssertionError" and
# "assert"
if inst.opname == 'POP_JUMP_IF_TRUE' and i+3 < n:
next_inst = bs[i+3]
if (next_inst.opname == 'LOAD_GLOBAL' and
next_inst.argval == 'AssertionError'):
self.load_asserts.add(next_inst.offset)