File tree Expand file tree Collapse file tree 3 files changed +29
-2
lines changed
Misc/NEWS.d/next/Core_and_Builtins Expand file tree Collapse file tree 3 files changed +29
-2
lines changed Original file line number Diff line number Diff line change @@ -1992,6 +1992,27 @@ def gen():
19921992 next(g)
19931993 """ % _testinternalcapi .SPECIALIZATION_THRESHOLD ))
19941994
1995+ def test_next_instr_for_exception_handler_set (self ):
1996+ # gh-140104: We just want the exception to be caught properly.
1997+ def f ():
1998+ for i in range (TIER2_THRESHOLD + 3 ):
1999+ try :
2000+ undefined_variable (i )
2001+ except Exception :
2002+ pass
2003+
2004+ f ()
2005+
2006+ def test_next_instr_for_exception_handler_set_lasts_instr (self ):
2007+ # gh-140104: We just want the exception to be caught properly.
2008+ def f ():
2009+ a_list = []
2010+ for _ in range (TIER2_THRESHOLD + 3 ):
2011+ try :
2012+ a_list ["" ] = 0
2013+ except Exception :
2014+ pass
2015+
19952016
19962017def global_identity (x ):
19972018 return x
Original file line number Diff line number Diff line change 1+ Fix a bug with exception handling in the JIT. Patch by Ken Jin. Bug reported
2+ by Daniel Diniz.
Original file line number Diff line number Diff line change @@ -376,7 +376,9 @@ do { \
376376 frame = tstate -> current_frame ; \
377377 stack_pointer = _PyFrame_GetStackPointer (frame ); \
378378 if (next_instr == NULL ) { \
379- next_instr = frame -> instr_ptr ; \
379+ /* gh-140104: The exception handler expects frame->instr_ptr
380+ to after this_instr, not this_instr! */ \
381+ next_instr = frame -> instr_ptr + 1 ; \
380382 JUMP_TO_LABEL (error ); \
381383 } \
382384 DISPATCH (); \
@@ -404,7 +406,9 @@ do { \
404406 stack_pointer = _PyFrame_GetStackPointer(frame); \
405407 if (next_instr == NULL) \
406408 { \
407- next_instr = frame->instr_ptr; \
409+ /* gh-140104: The exception handler expects frame->instr_ptr
410+ to after this_instr, not this_instr! */ \
411+ next_instr = frame -> instr_ptr + 1 ; \
408412 goto error ; \
409413 } \
410414 DISPATCH (); \
You can’t perform that action at this time.
0 commit comments