Co-authored-by: Ken Jin <kenjin@python.org>
Co-authored-by: devdanzin <74280297+devdanzin@users.noreply.github.com>
Co-authored-by: Chris Eibl <138194463+chris-eibl@users.noreply.github.com>
assert ex is not None
"""))
+ def test_next_instr_for_exception_handler_set(self):
+ # gh-140104: We just want the exception to be caught properly.
+ def f():
+ for i in range(TIER2_THRESHOLD + 3):
+ try:
+ undefined_variable(i)
+ except Exception:
+ pass
+
+ f()
+
+ def test_next_instr_for_exception_handler_set_lasts_instr(self):
+ # gh-140104: We just want the exception to be caught properly.
+ def f():
+ a_list = []
+ for _ in range(TIER2_THRESHOLD + 3):
+ try:
+ a_list[""] = 0
+ except Exception:
+ pass
+
def global_identity(x):
return x
--- /dev/null
+Fix a bug with exception handling in the JIT. Patch by Ken Jin. Bug reported
+by Daniel Diniz.
frame = tstate->current_frame; \
stack_pointer = _PyFrame_GetStackPointer(frame); \
if (next_instr == NULL) { \
- next_instr = frame->instr_ptr; \
+ /* gh-140104: The exception handler expects frame->instr_ptr
+ to after this_instr, not this_instr! */ \
+ next_instr = frame->instr_ptr + 1; \
JUMP_TO_LABEL(error); \
} \
DISPATCH(); \