Skip to content
Merged
Show file tree
Hide file tree
Changes from 5 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions Lib/test/test_capi/test_opt.py
Original file line number Diff line number Diff line change
Expand Up @@ -2637,6 +2637,17 @@ def f2():

f2()

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:
g(i)
except Exception:
pass

f()


def global_identity(x):
return x
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a bug with exception handling in the JIT. Patch by Ken Jin. Bug reported
by Daniel Diniz.
1 change: 0 additions & 1 deletion Python/bytecodes.c
Original file line number Diff line number Diff line change
Expand Up @@ -5384,7 +5384,6 @@ dummy_func(

tier2 op(_ERROR_POP_N, (target/2 --)) {
assert(oparg == 0);
frame->instr_ptr = _PyFrame_GetBytecode(frame) + target;
SYNC_SP();
GOTO_TIER_ONE(NULL);
}
Expand Down
4 changes: 3 additions & 1 deletion Python/ceval_macros.h
Original file line number Diff line number Diff line change
Expand Up @@ -358,7 +358,9 @@ do { \
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 be pointing to next_instr, not this_instr! */ \
next_instr = frame->instr_ptr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[frame->instr_ptr->op.code]]; \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
next_instr = frame->instr_ptr + 1 + _PyOpcode_Caches[_PyOpcode_Deopt[frame->instr_ptr->op.code]]; \
next_instr = frame->instr_ptr + 1;

Just +1 to compensate for the the -1 in label(exception_unwind)

Pointing to the next instruction does work, but it is unnecessary. As long as next_inst -1 points into the current instruction, unwinding works correctly.

JUMP_TO_LABEL(error); \
} \
DISPATCH(); \
Expand Down
1 change: 0 additions & 1 deletion Python/executor_cases.c.h

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading