From: Ken Jin <28750310+Fidget-Spinner@users.noreply.github.com> Date: Mon, 20 Oct 2025 23:52:56 +0000 (+0100) Subject: Fix a bug with where the executors get inserted during EXTENDED_ARG X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dd0e16f7e1eeb32de05d335502cd1a628508f8c2;p=thirdparty%2FPython%2Fcpython.git Fix a bug with where the executors get inserted during EXTENDED_ARG --- diff --git a/Include/internal/pycore_uop.h b/Include/internal/pycore_uop.h index 86bea31204ca..bccc0b00a4d2 100644 --- a/Include/internal/pycore_uop.h +++ b/Include/internal/pycore_uop.h @@ -36,7 +36,7 @@ typedef struct _PyUOpInstruction{ } _PyUOpInstruction; // This is the length of the trace we translate initially. -#define UOP_MAX_TRACE_LENGTH 1400 +#define UOP_MAX_TRACE_LENGTH 1500 #define UOP_BUFFER_SIZE (UOP_MAX_TRACE_LENGTH * sizeof(_PyUOpInstruction)) /* Bloom filter with m = 256 diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 0ba8286fc467..7df899dc50e8 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -2979,7 +2979,13 @@ dummy_func( } int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL); if (!_is_sys_tracing) { - _PyJIT_InitializeTracing(tstate, frame, this_instr, next_instr, STACK_LEVEL(), 0, NULL); + /* Back up over EXTENDED_ARGs so executor is inserted at the corret place */ + _Py_CODEUNIT *insert_exec_at = this_instr; + while (oparg > 255) { + oparg >>= 8; + insert_exec_at--; + } + _PyJIT_InitializeTracing(tstate, frame, insert_exec_at, next_instr, STACK_LEVEL(), 0, NULL); ENTER_TRACING(); } int _jump_taken = false; diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 28691b2c5c83..5cd7142adb33 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7671,7 +7671,12 @@ } int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL); if (!_is_sys_tracing) { - _PyJIT_InitializeTracing(tstate, frame, this_instr, next_instr, STACK_LEVEL(), 0, NULL); + _Py_CODEUNIT *insert_exec_at = this_instr; + while (oparg > 255) { + oparg >>= 8; + insert_exec_at--; + } + _PyJIT_InitializeTracing(tstate, frame, insert_exec_at, next_instr, STACK_LEVEL(), 0, NULL); ENTER_TRACING(); } int _jump_taken = false; diff --git a/Python/generated_tracer_cases.c.h b/Python/generated_tracer_cases.c.h index 9d739dc00db9..759bfd13cb83 100644 --- a/Python/generated_tracer_cases.c.h +++ b/Python/generated_tracer_cases.c.h @@ -8956,7 +8956,12 @@ } int _is_sys_tracing = (tstate->c_tracefunc != NULL) || (tstate->c_profilefunc != NULL); if (!_is_sys_tracing) { - _PyJIT_InitializeTracing(tstate, frame, this_instr, next_instr, STACK_LEVEL(), 0, NULL); + _Py_CODEUNIT *insert_exec_at = this_instr; + while (oparg > 255) { + oparg >>= 8; + insert_exec_at--; + } + _PyJIT_InitializeTracing(tstate, frame, insert_exec_at, next_instr, STACK_LEVEL(), 0, NULL); ENTER_TRACING(); } int _jump_taken = false;