◐ Shell
clean mode source ↗

[3.14] gh-140104: Set next_instr properly in the JIT during exceptions (GH-140233) by efimov-mikhail · Pull Request #140687 · python/cpython

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.14] gh-140104: Set next_instr properly in the JIT during exceptions (GH-140233) #140687

Changes from all commits

Commits

File filter

Filter by extension

Conversations

Failed to load comments.

Loading

Jump to

Jump to file

Failed to load files.

Loading

Diff view
Diff view

21 changes: 21 additions & 0 deletions Lib/test/test_capi/test_opt.py

Original file line number Diff line number Diff line change
Expand Up @@ -1972,6 +1972,27 @@ def testfunc(n):
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
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.

4 changes: 3 additions & 1 deletion Python/ceval_macros.h

Original file line number Diff line number Diff line change
Expand Up @@ -368,7 +368,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 after this_instr, not this_instr! */ \
next_instr = frame->instr_ptr + 1; \
JUMP_TO_LABEL(error); \
} \
DISPATCH(); \
Expand Down