diff options
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/ctypes/test/test_values.py | 6 | ||||
-rw-r--r-- | Lib/dis.py | 56 | ||||
-rw-r--r-- | Lib/importlib/_bootstrap_external.py | 3 | ||||
-rw-r--r-- | Lib/opcode.py | 9 | ||||
-rw-r--r-- | Lib/test/test_code.py | 1 | ||||
-rw-r--r-- | Lib/test/test_dis.py | 185 | ||||
-rw-r--r-- | Lib/test/test_exceptions.py | 2 | ||||
-rw-r--r-- | Lib/test/test_sys.py | 7 | ||||
-rw-r--r-- | Lib/test/test_sys_settrace.py | 56 |
9 files changed, 193 insertions, 132 deletions
diff --git a/Lib/ctypes/test/test_values.py b/Lib/ctypes/test/test_values.py index 7514fe8..80f4ed0 100644 --- a/Lib/ctypes/test/test_values.py +++ b/Lib/ctypes/test/test_values.py @@ -80,9 +80,9 @@ class PythonValuesTestCase(unittest.TestCase): continue items.append((entry.name.decode("ascii"), entry.size)) - expected = [("__hello__", 137), - ("__phello__", -137), - ("__phello__.spam", 137), + expected = [("__hello__", 142), + ("__phello__", -142), + ("__phello__.spam", 142), ] self.assertEqual(items, expected, "PyImport_FrozenModules example " "in Doc/library/ctypes.rst may be out of date") @@ -203,6 +203,9 @@ _Instruction.offset.__doc__ = "Start index of operation within bytecode sequence _Instruction.starts_line.__doc__ = "Line started by this opcode (if any), otherwise None" _Instruction.is_jump_target.__doc__ = "True if other code jumps to here, otherwise False" +_ExceptionTableEntry = collections.namedtuple("_ExceptionTableEntry", + "start end target depth lasti") + _OPNAME_WIDTH = 20 _OPARG_WIDTH = 5 @@ -308,8 +311,33 @@ def _get_name_info(name_index, name_list): return argval, argrepr +def parse_varint(iterator): + b = next(iterator) + val = b & 63 + while b&64: + val <<= 6 + b = next(iterator) + val |= b&63 + return val + +def parse_exception_table(code): + iterator = iter(code.co_exceptiontable) + entries = [] + try: + while True: + start = parse_varint(iterator)*2 + length = parse_varint(iterator)*2 + end = start + length + target = parse_varint(iterator)*2 + dl = parse_varint(iterator) + depth = dl >> 1 + lasti = bool(dl&1) + entries.append(_ExceptionTableEntry(start, end, target, depth, lasti)) + except StopIteration: + return entries + def _get_instructions_bytes(code, varnames=None, names=None, constants=None, - cells=None, linestarts=None, line_offset=0): + cells=None, linestarts=None, line_offset=0, exception_entries=()): """Iterate over the instructions in a bytecode string. Generates a sequence of Instruction namedtuples giving the details of each @@ -318,7 +346,10 @@ def _get_instructions_bytes(code, varnames=None, names=None, constants=None, arguments. """ - labels = findlabels(code) + labels = set(findlabels(code)) + for start, end, target, _, _ in exception_entries: + for i in range(start, end): + labels.add(target) starts_line = None for offset, op, arg in _unpack_opargs(code): if linestarts is not None: @@ -369,8 +400,10 @@ def disassemble(co, lasti=-1, *, file=None): """Disassemble a code object.""" cell_names = co.co_cellvars + co.co_freevars linestarts = dict(findlinestarts(co)) + exception_entries = parse_exception_table(co) _disassemble_bytes(co.co_code, lasti, co.co_varnames, co.co_names, - co.co_consts, cell_names, linestarts, file=file) + co.co_consts, cell_names, linestarts, file=file, + exception_entries=exception_entries) def _disassemble_recursive(co, *, file=None, depth=None): disassemble(co, file=file) @@ -385,7 +418,7 @@ def _disassemble_recursive(co, *, file=None, depth=None): def _disassemble_bytes(code, lasti=-1, varnames=None, names=None, constants=None, cells=None, linestarts=None, - *, file=None, line_offset=0): + *, file=None, line_offset=0, exception_entries=()): # Omit the line number column entirely if we have no line number info show_lineno = bool(linestarts) if show_lineno: @@ -403,7 +436,7 @@ def _disassemble_bytes(code, lasti=-1, varnames=None, names=None, offset_width = 4 for instr in _get_instructions_bytes(code, varnames, names, constants, cells, linestarts, - line_offset=line_offset): + line_offset=line_offset, exception_entries=exception_entries): new_source_line = (show_lineno and instr.starts_line is not None and instr.offset > 0) @@ -412,6 +445,12 @@ def _disassemble_bytes(code, lasti=-1, varnames=None, names=None, is_current_instr = instr.offset == lasti print(instr._disassemble(lineno_width, is_current_instr, offset_width), file=file) + if exception_entries: + print("ExceptionTable:", file=file) + for entry in exception_entries: + lasti = " lasti" if entry.lasti else "" + end = entry.end-2 + print(f" {entry.start} to {end} -> {entry.target} [{entry.depth}]{lasti}", file=file) def _disassemble_str(source, **kwargs): """Compile the source string, then disassemble the code object.""" @@ -482,13 +521,15 @@ class Bytecode: self._linestarts = dict(findlinestarts(co)) self._original_object = x self.current_offset = current_offset + self.exception_entries = parse_exception_table(co) def __iter__(self): co = self.codeobj return _get_instructions_bytes(co.co_code, co.co_varnames, co.co_names, co.co_consts, self._cell_names, self._linestarts, - line_offset=self._line_offset) + line_offset=self._line_offset, + exception_entries=self.exception_entries) def __repr__(self): return "{}({!r})".format(self.__class__.__name__, @@ -519,7 +560,8 @@ class Bytecode: linestarts=self._linestarts, line_offset=self._line_offset, file=output, - lasti=offset) + lasti=offset, + exception_entries=self.exception_entries) return output.getvalue() diff --git a/Lib/importlib/_bootstrap_external.py b/Lib/importlib/_bootstrap_external.py index 9a73c7b..469610a 100644 --- a/Lib/importlib/_bootstrap_external.py +++ b/Lib/importlib/_bootstrap_external.py @@ -352,6 +352,7 @@ _code_type = type(_write_atomic.__code__) # Python 3.10b1 3437 (Undo making 'annotations' future by default - We like to dance among core devs!) # Python 3.10b1 3438 Safer line number table handling. # Python 3.10b1 3439 (Add ROT_N) +# Python 3.11a1 3450 Use exception table for unwinding ("zero cost" exception handling) # # MAGIC must change whenever the bytecode emitted by the compiler may no @@ -361,7 +362,7 @@ _code_type = type(_write_atomic.__code__) # Whenever MAGIC_NUMBER is changed, the ranges in the magic_values array # in PC/launcher.c must also be updated. -MAGIC_NUMBER = (3439).to_bytes(2, 'little') + b'\r\n' +MAGIC_NUMBER = (3450).to_bytes(2, 'little') + b'\r\n' _RAW_MAGIC_NUMBER = int.from_bytes(MAGIC_NUMBER, 'little') # For import.c _PYCACHE = '__pycache__' diff --git a/Lib/opcode.py b/Lib/opcode.py index 37e88e9..88022a4 100644 --- a/Lib/opcode.py +++ b/Lib/opcode.py @@ -86,11 +86,15 @@ def_op('MATCH_MAPPING', 31) def_op('MATCH_SEQUENCE', 32) def_op('MATCH_KEYS', 33) def_op('COPY_DICT_WITHOUT_KEYS', 34) +def_op('PUSH_EXC_INFO', 35) + +def_op('POP_EXCEPT_AND_RERAISE', 37) def_op('WITH_EXCEPT_START', 49) def_op('GET_AITER', 50) def_op('GET_ANEXT', 51) def_op('BEFORE_ASYNC_WITH', 52) +def_op('BEFORE_WITH', 53) def_op('END_ASYNC_FOR', 54) def_op('INPLACE_ADD', 55) @@ -124,7 +128,6 @@ def_op('RETURN_VALUE', 83) def_op('IMPORT_STAR', 84) def_op('SETUP_ANNOTATIONS', 85) def_op('YIELD_VALUE', 86) -def_op('POP_BLOCK', 87) def_op('POP_EXCEPT', 89) @@ -164,7 +167,6 @@ def_op('CONTAINS_OP', 118) def_op('RERAISE', 119) jabs_op('JUMP_IF_NOT_EXC_MATCH', 121) -jrel_op('SETUP_FINALLY', 122) # Distance to target address def_op('LOAD_FAST', 124) # Local variable number haslocal.append(124) @@ -190,7 +192,7 @@ hasfree.append(138) def_op('CALL_FUNCTION_KW', 141) # #args + #kwargs def_op('CALL_FUNCTION_EX', 142) # Flags -jrel_op('SETUP_WITH', 143) + def_op('EXTENDED_ARG', 144) EXTENDED_ARG = 144 def_op('LIST_APPEND', 145) @@ -201,7 +203,6 @@ hasfree.append(148) def_op('MATCH_CLASS', 152) -jrel_op('SETUP_ASYNC_WITH', 154) def_op('FORMAT_VALUE', 155) def_op('BUILD_CONST_KEY_MAP', 156) def_op('BUILD_STRING', 157) diff --git a/Lib/test/test_code.py b/Lib/test/test_code.py index 6aaf04c..c3dd678 100644 --- a/Lib/test/test_code.py +++ b/Lib/test/test_code.py @@ -227,6 +227,7 @@ class CodeTest(unittest.TestCase): co.co_name, co.co_firstlineno, co.co_lnotab, + co.co_exceptiontable, co.co_freevars, co.co_cellvars) diff --git a/Lib/test/test_dis.py b/Lib/test/test_dis.py index 21c68d4..f341a3e 100644 --- a/Lib/test/test_dis.py +++ b/Lib/test/test_dis.py @@ -282,42 +282,47 @@ dis_compound_stmt_str = """\ """ dis_traceback = """\ -%3d 0 SETUP_FINALLY 7 (to 16) +%3d 0 NOP %3d 2 LOAD_CONST 1 (1) 4 LOAD_CONST 2 (0) --> 6 BINARY_TRUE_DIVIDE 8 POP_TOP - 10 POP_BLOCK -%3d 12 LOAD_FAST 1 (tb) - 14 RETURN_VALUE +%3d 10 LOAD_FAST 1 (tb) + 12 RETURN_VALUE + >> 14 PUSH_EXC_INFO -%3d >> 16 DUP_TOP +%3d 16 DUP_TOP 18 LOAD_GLOBAL 0 (Exception) - 20 JUMP_IF_NOT_EXC_MATCH 29 (to 58) + 20 JUMP_IF_NOT_EXC_MATCH 28 (to 56) 22 POP_TOP 24 STORE_FAST 0 (e) 26 POP_TOP - 28 SETUP_FINALLY 10 (to 50) - -%3d 30 LOAD_FAST 0 (e) - 32 LOAD_ATTR 1 (__traceback__) - 34 STORE_FAST 1 (tb) - 36 POP_BLOCK - 38 POP_EXCEPT - 40 LOAD_CONST 0 (None) - 42 STORE_FAST 0 (e) - 44 DELETE_FAST 0 (e) - -%3d 46 LOAD_FAST 1 (tb) - 48 RETURN_VALUE - >> 50 LOAD_CONST 0 (None) - 52 STORE_FAST 0 (e) - 54 DELETE_FAST 0 (e) - 56 RERAISE 1 - -%3d >> 58 RERAISE 0 + +%3d 28 LOAD_FAST 0 (e) + 30 LOAD_ATTR 1 (__traceback__) + 32 STORE_FAST 1 (tb) + 34 POP_EXCEPT + 36 LOAD_CONST 0 (None) + 38 STORE_FAST 0 (e) + 40 DELETE_FAST 0 (e) + +%3d 42 LOAD_FAST 1 (tb) + 44 RETURN_VALUE + >> 46 LOAD_CONST 0 (None) + 48 STORE_FAST 0 (e) + 50 DELETE_FAST 0 (e) + 52 RERAISE 1 + >> 54 POP_EXCEPT_AND_RERAISE + +%3d >> 56 RERAISE 0 +ExceptionTable: + 2 to 8 -> 14 [0] + 14 to 26 -> 54 [3] lasti + 28 to 32 -> 46 [3] lasti + 46 to 52 -> 54 [3] lasti + 56 to 56 -> 54 [3] lasti """ % (TRACEBACK_CODE.co_firstlineno + 1, TRACEBACK_CODE.co_firstlineno + 2, TRACEBACK_CODE.co_firstlineno + 5, @@ -360,38 +365,46 @@ def _tryfinallyconst(b): b() dis_tryfinally = """\ -%3d 0 SETUP_FINALLY 6 (to 14) +%3d 0 NOP %3d 2 LOAD_FAST 0 (a) - 4 POP_BLOCK -%3d 6 LOAD_FAST 1 (b) - 8 CALL_FUNCTION 0 - 10 POP_TOP - 12 RETURN_VALUE - >> 14 LOAD_FAST 1 (b) +%3d 4 LOAD_FAST 1 (b) + 6 CALL_FUNCTION 0 + 8 POP_TOP + 10 RETURN_VALUE + >> 12 PUSH_EXC_INFO + 14 LOAD_FAST 1 (b) 16 CALL_FUNCTION 0 18 POP_TOP 20 RERAISE 0 + >> 22 POP_EXCEPT_AND_RERAISE +ExceptionTable: + 2 to 2 -> 12 [0] + 12 to 20 -> 22 [3] lasti """ % (_tryfinally.__code__.co_firstlineno + 1, _tryfinally.__code__.co_firstlineno + 2, _tryfinally.__code__.co_firstlineno + 4, ) dis_tryfinallyconst = """\ -%3d 0 SETUP_FINALLY 6 (to 14) +%3d 0 NOP -%3d 2 POP_BLOCK +%3d 2 NOP %3d 4 LOAD_FAST 0 (b) 6 CALL_FUNCTION 0 8 POP_TOP 10 LOAD_CONST 1 (1) 12 RETURN_VALUE - >> 14 LOAD_FAST 0 (b) - 16 CALL_FUNCTION 0 - 18 POP_TOP - 20 RERAISE 0 + 14 PUSH_EXC_INFO + 16 LOAD_FAST 0 (b) + 18 CALL_FUNCTION 0 + 20 POP_TOP + 22 RERAISE 0 + >> 24 POP_EXCEPT_AND_RERAISE +ExceptionTable: + 14 to 22 -> 24 [3] lasti """ % (_tryfinallyconst.__code__.co_firstlineno + 1, _tryfinallyconst.__code__.co_firstlineno + 2, _tryfinallyconst.__code__.co_firstlineno + 4, @@ -833,7 +846,7 @@ Argument count: 0 Positional-only arguments: 0 Kw-only arguments: 0 Number of locals: 2 -Stack size: 9 +Stack size: 10 Flags: OPTIMIZED, NEWLOCALS, NOFREE, COROUTINE Constants: 0: None @@ -1059,61 +1072,64 @@ expected_opinfo_jumpy = [ Instruction(opname='LOAD_CONST', opcode=100, arg=6, argval='Who let lolcatz into this test suite?', argrepr="'Who let lolcatz into this test suite?'", offset=98, starts_line=None, is_jump_target=False), Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=100, starts_line=None, is_jump_target=False), Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=102, starts_line=None, is_jump_target=False), - Instruction(opname='SETUP_FINALLY', opcode=122, arg=48, argval=202, argrepr='to 202', offset=104, starts_line=20, is_jump_target=True), - Instruction(opname='SETUP_FINALLY', opcode=122, arg=6, argval=120, argrepr='to 120', offset=106, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=108, starts_line=21, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=0, argrepr='0', offset=110, starts_line=None, is_jump_target=False), - Instruction(opname='BINARY_TRUE_DIVIDE', opcode=27, arg=None, argval=None, argrepr='', offset=112, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=114, starts_line=None, is_jump_target=False), - Instruction(opname='POP_BLOCK', opcode=87, arg=None, argval=None, argrepr='', offset=116, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_FORWARD', opcode=110, arg=12, argval=144, argrepr='to 144', offset=118, starts_line=None, is_jump_target=False), - Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=120, starts_line=22, is_jump_target=True), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=122, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_IF_NOT_EXC_MATCH', opcode=121, arg=106, argval=212, argrepr='to 212', offset=124, starts_line=None, is_jump_target=False), + Instruction(opname='NOP', opcode=9, arg=None, argval=None, argrepr='', offset=104, starts_line=20, is_jump_target=True), + Instruction(opname='LOAD_CONST', opcode=100, arg=5, argval=1, argrepr='1', offset=106, starts_line=21, is_jump_target=False), + Instruction(opname='LOAD_CONST', opcode=100, arg=7, argval=0, argrepr='0', offset=108, starts_line=None, is_jump_target=False), + Instruction(opname='BINARY_TRUE_DIVIDE', opcode=27, arg=None, argval=None, argrepr='', offset=110, starts_line=None, is_jump_target=False), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=112, starts_line=None, is_jump_target=False), + Instruction(opname='JUMP_FORWARD', opcode=110, arg=14, argval=144, argrepr='to 144', offset=114, starts_line=None, is_jump_target=False), + Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=116, starts_line=None, is_jump_target=False), + Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=118, starts_line=22, is_jump_target=False), + Instruction(opname='LOAD_GLOBAL', opcode=116, arg=2, argval='ZeroDivisionError', argrepr='ZeroDivisionError', offset=120, starts_line=None, is_jump_target=False), + Instruction(opname='JUMP_IF_NOT_EXC_MATCH', opcode=121, arg=109, argval=218, argrepr='to 218', offset=122, starts_line=None, is_jump_target=False), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=124, starts_line=None, is_jump_target=False), Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=126, starts_line=None, is_jump_target=False), Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=128, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=130, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=132, starts_line=23, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=134, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=136, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=138, starts_line=None, is_jump_target=False), - Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=140, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_FORWARD', opcode=110, arg=22, argval=188, argrepr='to 188', offset=142, starts_line=None, is_jump_target=False), + Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=130, starts_line=23, is_jump_target=False), + Instruction(opname='LOAD_CONST', opcode=100, arg=8, argval='Here we go, here we go, here we go...', argrepr="'Here we go, here we go, here we go...'", offset=132, starts_line=None, is_jump_target=False), + Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=134, starts_line=None, is_jump_target=False), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=136, starts_line=None, is_jump_target=False), + Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=138, starts_line=None, is_jump_target=False), + Instruction(opname='JUMP_FORWARD', opcode=110, arg=25, argval=192, argrepr='to 192', offset=140, starts_line=None, is_jump_target=False), + Instruction(opname='POP_EXCEPT_AND_RERAISE', opcode=37, arg=None, argval=None, argrepr='', offset=142, starts_line=None, is_jump_target=False), Instruction(opname='LOAD_FAST', opcode=124, arg=0, argval='i', argrepr='i', offset=144, starts_line=25, is_jump_target=True), - Instruction(opname='SETUP_WITH', opcode=143, arg=12, argval=172, argrepr='to 172', offset=146, starts_line=None, is_jump_target=False), + Instruction(opname='BEFORE_WITH', opcode=53, arg=None, argval=None, argrepr='', offset=146, starts_line=None, is_jump_target=False), Instruction(opname='STORE_FAST', opcode=125, arg=1, argval='dodgy', argrepr='dodgy', offset=148, starts_line=None, is_jump_target=False), Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=150, starts_line=26, is_jump_target=False), Instruction(opname='LOAD_CONST', opcode=100, arg=9, argval='Never reach this', argrepr="'Never reach this'", offset=152, starts_line=None, is_jump_target=False), Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=154, starts_line=None, is_jump_target=False), Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=156, starts_line=None, is_jump_target=False), - Instruction(opname='POP_BLOCK', opcode=87, arg=None, argval=None, argrepr='', offset=158, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=160, starts_line=25, is_jump_target=False), + Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=158, starts_line=25, is_jump_target=False), + Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=160, starts_line=None, is_jump_target=False), Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=162, starts_line=None, is_jump_target=False), - Instruction(opname='DUP_TOP', opcode=4, arg=None, argval=None, argrepr='', offset=164, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=3, argval=3, argrepr='', offset=166, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=168, starts_line=None, is_jump_target=False), - Instruction(opname='JUMP_FORWARD', opcode=110, arg=8, argval=188, argrepr='to 188', offset=170, starts_line=None, is_jump_target=False), - Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=172, starts_line=None, is_jump_target=True), - Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=89, argval=178, argrepr='to 178', offset=174, starts_line=None, is_jump_target=False), - Instruction(opname='RERAISE', opcode=119, arg=1, argval=1, argrepr='', offset=176, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=178, starts_line=None, is_jump_target=True), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=180, starts_line=None, is_jump_target=False), + Instruction(opname='CALL_FUNCTION', opcode=131, arg=3, argval=3, argrepr='', offset=164, starts_line=None, is_jump_target=False), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=166, starts_line=None, is_jump_target=False), + Instruction(opname='JUMP_FORWARD', opcode=110, arg=11, argval=192, argrepr='to 192', offset=168, starts_line=None, is_jump_target=False), + Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=170, starts_line=None, is_jump_target=False), + Instruction(opname='WITH_EXCEPT_START', opcode=49, arg=None, argval=None, argrepr='', offset=172, starts_line=None, is_jump_target=False), + Instruction(opname='POP_JUMP_IF_TRUE', opcode=115, arg=90, argval=180, argrepr='to 180', offset=174, starts_line=None, is_jump_target=False), + Instruction(opname='RERAISE', opcode=119, arg=4, argval=4, argrepr='', offset=176, starts_line=None, is_jump_target=False), + Instruction(opname='POP_EXCEPT_AND_RERAISE', opcode=37, arg=None, argval=None, argrepr='', offset=178, starts_line=None, is_jump_target=False), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=180, starts_line=None, is_jump_target=True), Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=182, starts_line=None, is_jump_target=False), - Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=184, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=186, starts_line=None, is_jump_target=False), - Instruction(opname='POP_BLOCK', opcode=87, arg=None, argval=None, argrepr='', offset=188, starts_line=None, is_jump_target=True), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=190, starts_line=28, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=192, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=194, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=196, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=198, starts_line=None, is_jump_target=False), - Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=200, starts_line=None, is_jump_target=False), - Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=202, starts_line=None, is_jump_target=True), - Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=204, starts_line=None, is_jump_target=False), - Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=206, starts_line=None, is_jump_target=False), - Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=208, starts_line=None, is_jump_target=False), - Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=210, starts_line=None, is_jump_target=False), - Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=212, starts_line=22, is_jump_target=True), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=184, starts_line=None, is_jump_target=False), + Instruction(opname='POP_EXCEPT', opcode=89, arg=None, argval=None, argrepr='', offset=186, starts_line=None, is_jump_target=False), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=188, starts_line=None, is_jump_target=False), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=190, starts_line=None, is_jump_target=False), + Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=192, starts_line=28, is_jump_target=True), + Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=194, starts_line=None, is_jump_target=False), + Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=196, starts_line=None, is_jump_target=False), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=198, starts_line=None, is_jump_target=False), + Instruction(opname='LOAD_CONST', opcode=100, arg=0, argval=None, argrepr='None', offset=200, starts_line=None, is_jump_target=False), + Instruction(opname='RETURN_VALUE', opcode=83, arg=None, argval=None, argrepr='', offset=202, starts_line=None, is_jump_target=False), + Instruction(opname='PUSH_EXC_INFO', opcode=35, arg=None, argval=None, argrepr='', offset=204, starts_line=None, is_jump_target=False), + Instruction(opname='LOAD_GLOBAL', opcode=116, arg=1, argval='print', argrepr='print', offset=206, starts_line=None, is_jump_target=False), + Instruction(opname='LOAD_CONST', opcode=100, arg=10, argval="OK, now we're done", argrepr='"OK, now we\'re done"', offset=208, starts_line=None, is_jump_target=False), + Instruction(opname='CALL_FUNCTION', opcode=131, arg=1, argval=1, argrepr='', offset=210, starts_line=None, is_jump_target=False), + Instruction(opname='POP_TOP', opcode=1, arg=None, argval=None, argrepr='', offset=212, starts_line=None, is_jump_target=False), + Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=214, starts_line=None, is_jump_target=False), + Instruction(opname='POP_EXCEPT_AND_RERAISE', opcode=37, arg=None, argval=None, argrepr='', offset=216, starts_line=None, is_jump_target=False), + Instruction(opname='RERAISE', opcode=119, arg=0, argval=0, argrepr='', offset=218, starts_line=22, is_jump_target=True), ] # One last piece of inspect fodder to check the default line number handling @@ -1211,6 +1227,7 @@ class BytecodeTests(unittest.TestCase): self.assertEqual(b.current_offset, tb.tb_lasti) def test_from_traceback_dis(self): + self.maxDiff = None tb = get_tb() b = dis.Bytecode.from_traceback(tb) self.assertEqual(b.dis(), dis_traceback) diff --git a/Lib/test/test_exceptions.py b/Lib/test/test_exceptions.py index 3c427fe..1fe479f 100644 --- a/Lib/test/test_exceptions.py +++ b/Lib/test/test_exceptions.py @@ -218,7 +218,7 @@ class ExceptionTests(unittest.TestCase): check('class foo:return 1', 1, 11) check('def f():\n continue', 2, 3) check('def f():\n break', 2, 3) - check('try:\n pass\nexcept:\n pass\nexcept ValueError:\n pass', 2, 3) + check('try:\n pass\nexcept:\n pass\nexcept ValueError:\n pass', 3, 1) # Errors thrown by tokenizer.c check('(0x+1)', 1, 3) diff --git a/Lib/test/test_sys.py b/Lib/test/test_sys.py index 1fd5247..4f26689 100644 --- a/Lib/test/test_sys.py +++ b/Lib/test/test_sys.py @@ -1273,13 +1273,12 @@ class SizeofTest(unittest.TestCase): check(sys.float_info, vsize('') + self.P * len(sys.float_info)) # frame import inspect - CO_MAXBLOCKS = 20 x = inspect.currentframe() ncells = len(x.f_code.co_cellvars) nfrees = len(x.f_code.co_freevars) - extras = x.f_code.co_stacksize + x.f_code.co_nlocals +\ - ncells + nfrees - 1 - check(x, vsize('4Pi2c4P3ic' + CO_MAXBLOCKS*'3i' + 'P' + extras*'P')) + localsplus = x.f_code.co_stacksize + x.f_code.co_nlocals +\ + ncells + nfrees + check(x, vsize('8P3i3c' + localsplus*'P')) # function def func(): pass check(func, size('14P')) diff --git a/Lib/test/test_sys_settrace.py b/Lib/test/test_sys_settrace.py index 40dd92c..12d4c28 100644 --- a/Lib/test/test_sys_settrace.py +++ b/Lib/test/test_sys_settrace.py @@ -1253,7 +1253,7 @@ class JumpTestCase(unittest.TestCase): output.append(6) output.append(7) - @async_jump_test(4, 5, [3, 5]) + @async_jump_test(4, 5, [3], (ValueError, 'into')) async def test_jump_out_of_async_for_block_forwards(output): for i in [1]: async for i in asynciter([1, 2]): @@ -1295,7 +1295,7 @@ class JumpTestCase(unittest.TestCase): output.append(8) output.append(9) - @jump_test(6, 7, [2, 7], (ZeroDivisionError, '')) + @jump_test(6, 7, [2], (ValueError, 'within')) def test_jump_in_nested_finally_2(output): try: output.append(2) @@ -1306,7 +1306,7 @@ class JumpTestCase(unittest.TestCase): output.append(7) output.append(8) - @jump_test(6, 11, [2, 11], (ZeroDivisionError, '')) + @jump_test(6, 11, [2], (ValueError, 'within')) def test_jump_in_nested_finally_3(output): try: output.append(2) @@ -1321,7 +1321,7 @@ class JumpTestCase(unittest.TestCase): output.append(11) output.append(12) - @jump_test(5, 11, [2, 4], (ValueError, 'after')) + @jump_test(5, 11, [2, 4], (ValueError, 'exception')) def test_no_jump_over_return_try_finally_in_finally_block(output): try: output.append(2) @@ -1417,8 +1417,8 @@ class JumpTestCase(unittest.TestCase): output.append(5) raise - @jump_test(5, 7, [4, 7, 8]) - def test_jump_between_except_blocks(output): + @jump_test(5, 7, [4], (ValueError, 'within')) + def test_no_jump_between_except_blocks(output): try: 1/0 except ZeroDivisionError: @@ -1428,8 +1428,8 @@ class JumpTestCase(unittest.TestCase): output.append(7) output.append(8) - @jump_test(5, 6, [4, 6, 7]) - def test_jump_within_except_block(output): + @jump_test(5, 6, [4], (ValueError, 'within')) + def test_no_jump_within_except_block(output): try: 1/0 except: @@ -1654,54 +1654,54 @@ class JumpTestCase(unittest.TestCase): output.append(2) output.append(3) - @async_jump_test(3, 2, [2, 2], (ValueError, 'into')) + @async_jump_test(3, 2, [2, 2], (ValueError, 'within')) async def test_no_jump_backwards_into_async_for_block(output): async for i in asynciter([1, 2]): output.append(2) output.append(3) - @jump_test(1, 3, [], (ValueError, 'into')) + @jump_test(1, 3, [], (ValueError, 'depth')) def test_no_jump_forwards_into_with_block(output): output.append(1) with tracecontext(output, 2): output.append(3) - @async_jump_test(1, 3, [], (ValueError, 'into')) + @async_jump_test(1, 3, [], (ValueError, 'depth')) async def test_no_jump_forwards_into_async_with_block(output): output.append(1) async with asynctracecontext(output, 2): output.append(3) - @jump_test(3, 2, [1, 2, -1], (ValueError, 'into')) + @jump_test(3, 2, [1, 2, -1], (ValueError, 'depth')) def test_no_jump_backwards_into_with_block(output): with tracecontext(output, 1): output.append(2) output.append(3) - @async_jump_test(3, 2, [1, 2, -1], (ValueError, 'into')) + @async_jump_test(3, 2, [1, 2, -1], (ValueError, 'depth')) async def test_no_jump_backwards_into_async_with_block(output): async with asynctracecontext(output, 1): output.append(2) output.append(3) - @jump_test(1, 3, [], (ValueError, 'into')) - def test_no_jump_forwards_into_try_finally_block(output): + @jump_test(1, 3, [3, 5]) + def test_jump_forwards_into_try_finally_block(output): output.append(1) try: output.append(3) finally: output.append(5) - @jump_test(5, 2, [2, 4], (ValueError, 'into')) - def test_no_jump_backwards_into_try_finally_block(output): + @jump_test(5, 2, [2, 4, 2, 4, 5]) + def test_jump_backwards_into_try_finally_block(output): try: output.append(2) finally: output.append(4) output.append(5) - @jump_test(1, 3, [], (ValueError, 'into')) - def test_no_jump_forwards_into_try_except_block(output): + @jump_test(1, 3, [3]) + def test_jump_forwards_into_try_except_block(output): output.append(1) try: output.append(3) @@ -1709,8 +1709,8 @@ class JumpTestCase(unittest.TestCase): output.append(5) raise - @jump_test(6, 2, [2], (ValueError, 'into')) - def test_no_jump_backwards_into_try_except_block(output): + @jump_test(6, 2, [2, 2, 6]) + def test_jump_backwards_into_try_except_block(output): try: output.append(2) except: @@ -1719,7 +1719,7 @@ class JumpTestCase(unittest.TestCase): output.append(6) # 'except' with a variable creates an implicit finally block - @jump_test(5, 7, [4], (ValueError, 'into')) + @jump_test(5, 7, [4], (ValueError, 'within')) def test_no_jump_between_except_blocks_2(output): try: 1/0 @@ -1756,7 +1756,7 @@ class JumpTestCase(unittest.TestCase): finally: output.append(5) - @jump_test(1, 5, [], (ValueError, "into an 'except'")) + @jump_test(1, 5, [], (ValueError, "into an exception")) def test_no_jump_into_bare_except_block(output): output.append(1) try: @@ -1764,7 +1764,7 @@ class JumpTestCase(unittest.TestCase): except: output.append(5) - @jump_test(1, 5, [], (ValueError, "into an 'except'")) + @jump_test(1, 5, [], (ValueError, "into an exception")) def test_no_jump_into_qualified_except_block(output): output.append(1) try: @@ -1772,7 +1772,7 @@ class JumpTestCase(unittest.TestCase): except Exception: output.append(5) - @jump_test(3, 6, [2, 5, 6], (ValueError, "into an 'except'")) + @jump_test(3, 6, [2, 5, 6], (ValueError, "into an exception")) def test_no_jump_into_bare_except_block_from_try_block(output): try: output.append(2) @@ -1783,7 +1783,7 @@ class JumpTestCase(unittest.TestCase): raise output.append(8) - @jump_test(3, 6, [2], (ValueError, "into an 'except'")) + @jump_test(3, 6, [2], (ValueError, "into an exception")) def test_no_jump_into_qualified_except_block_from_try_block(output): try: output.append(2) @@ -1794,7 +1794,7 @@ class JumpTestCase(unittest.TestCase): raise output.append(8) - @jump_test(7, 1, [1, 3, 6], (ValueError, "out of an 'except'")) + @jump_test(7, 1, [1, 3, 6], (ValueError, "within")) def test_no_jump_out_of_bare_except_block(output): output.append(1) try: @@ -1804,7 +1804,7 @@ class JumpTestCase(unittest.TestCase): output.append(6) output.append(7) - @jump_test(7, 1, [1, 3, 6], (ValueError, "out of an 'except'")) + @jump_test(7, 1, [1, 3, 6], (ValueError, "within")) def test_no_jump_out_of_qualified_except_block(output): output.append(1) try: |