From 0cb3e7dea882d434a10bab82b3f72b50a0cc63a4 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Thu, 7 May 2026 21:45:38 +0500 Subject: [PATCH 1/7] Fix warning for _YIELD_VALUE --- Modules/_testinternalcapi/test_cases.c.h | 4 ++-- Python/bytecodes.c | 2 +- Python/executor_cases.c.h | 2 +- Python/generated_cases.c.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/_testinternalcapi/test_cases.c.h b/Modules/_testinternalcapi/test_cases.c.h index 238e17bea303d3..894c4d16e11bdd 100644 --- a/Modules/_testinternalcapi/test_cases.c.h +++ b/Modules/_testinternalcapi/test_cases.c.h @@ -7946,7 +7946,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } @@ -13056,7 +13056,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 3bd489122da9d4..cf34db74a158cf 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1867,7 +1867,7 @@ dummy_func( assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index b6a2821db3007e..4edbc999ef32bf 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -9346,7 +9346,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 2623105656c90c..900b6179286db6 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7945,7 +7945,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } @@ -13053,7 +13053,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } From 7938098f5392aedae8f799167617a5cfb03498d3 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Fri, 8 May 2026 09:53:51 +0500 Subject: [PATCH 2/7] Use Py_ssize_t for offset --- Include/internal/pycore_code.h | 2 +- Include/internal/pycore_instruments.h | 2 +- Modules/_testinternalcapi/test_cases.c.h | 6 ++++-- Python/bytecodes.c | 3 ++- Python/executor_cases.c.h | 3 ++- Python/generated_cases.c.h | 6 ++++-- Python/instrumentation.c | 2 +- 7 files changed, 15 insertions(+), 9 deletions(-) diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h index 5b1fddbe15b98b..6673a5df9a4170 100644 --- a/Include/internal/pycore_code.h +++ b/Include/internal/pycore_code.h @@ -540,7 +540,7 @@ typedef struct { PyAPI_FUNC(int) _Py_Instrument(PyCodeObject *co, PyInterpreterState *interp); // Export for '_testinternalcapi' shared extension -PyAPI_FUNC(_Py_CODEUNIT) _Py_GetBaseCodeUnit(PyCodeObject *code, int offset); +PyAPI_FUNC(_Py_CODEUNIT) _Py_GetBaseCodeUnit(PyCodeObject *code, Py_ssize_t offset); extern int _PyInstruction_GetLength(PyCodeObject *code, int offset); diff --git a/Include/internal/pycore_instruments.h b/Include/internal/pycore_instruments.h index 56b55e93a014cb..d134064d9ca24b 100644 --- a/Include/internal/pycore_instruments.h +++ b/Include/internal/pycore_instruments.h @@ -122,7 +122,7 @@ extern int _Py_Instrumentation_GetLine(PyCodeObject *code, _PyCoLineInstrumentationData *line_data, int index); static inline uint8_t -_PyCode_GetOriginalOpcode(_PyCoLineInstrumentationData *line_data, int index) +_PyCode_GetOriginalOpcode(_PyCoLineInstrumentationData *line_data, Py_ssize_t index) { return line_data->data[index*line_data->bytes_per_entry]; } diff --git a/Modules/_testinternalcapi/test_cases.c.h b/Modules/_testinternalcapi/test_cases.c.h index 894c4d16e11bdd..dcc2b9ef7fa54f 100644 --- a/Modules/_testinternalcapi/test_cases.c.h +++ b/Modules/_testinternalcapi/test_cases.c.h @@ -7946,7 +7946,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + assert(i > 0); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } @@ -13056,7 +13057,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + assert(i > 0); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/bytecodes.c b/Python/bytecodes.c index cf34db74a158cf..cf7a56c95ff600 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1867,7 +1867,8 @@ dummy_func( assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + assert(i > 0); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 4edbc999ef32bf..67219fc9c61a05 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -9346,7 +9346,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + assert(i > 0); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 900b6179286db6..61d1bb5ec18324 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7945,7 +7945,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + assert(i > 0); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } @@ -13053,7 +13054,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); + assert(i > 0); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/instrumentation.c b/Python/instrumentation.c index 51bcbfdb3b6c55..00ac171658815e 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -635,7 +635,7 @@ sanity_check_instrumentation(PyCodeObject *code) /* Get the underlying code unit, stripping instrumentation and ENTER_EXECUTOR */ _Py_CODEUNIT -_Py_GetBaseCodeUnit(PyCodeObject *code, int i) +_Py_GetBaseCodeUnit(PyCodeObject *code, Py_ssize_t i) { _Py_CODEUNIT *src_instr = _PyCode_CODE(code) + i; _Py_CODEUNIT inst = { From 72b4b9420027cc7d8ff64a1822c73d3552b8594f Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Tue, 12 May 2026 09:31:43 +0500 Subject: [PATCH 3/7] Revert "Use Py_ssize_t for offset" This reverts commit 7938098f5392aedae8f799167617a5cfb03498d3. --- Include/internal/pycore_code.h | 2 +- Include/internal/pycore_instruments.h | 2 +- Modules/_testinternalcapi/test_cases.c.h | 6 ++---- Python/bytecodes.c | 3 +-- Python/executor_cases.c.h | 3 +-- Python/generated_cases.c.h | 6 ++---- Python/instrumentation.c | 2 +- 7 files changed, 9 insertions(+), 15 deletions(-) diff --git a/Include/internal/pycore_code.h b/Include/internal/pycore_code.h index 6673a5df9a4170..5b1fddbe15b98b 100644 --- a/Include/internal/pycore_code.h +++ b/Include/internal/pycore_code.h @@ -540,7 +540,7 @@ typedef struct { PyAPI_FUNC(int) _Py_Instrument(PyCodeObject *co, PyInterpreterState *interp); // Export for '_testinternalcapi' shared extension -PyAPI_FUNC(_Py_CODEUNIT) _Py_GetBaseCodeUnit(PyCodeObject *code, Py_ssize_t offset); +PyAPI_FUNC(_Py_CODEUNIT) _Py_GetBaseCodeUnit(PyCodeObject *code, int offset); extern int _PyInstruction_GetLength(PyCodeObject *code, int offset); diff --git a/Include/internal/pycore_instruments.h b/Include/internal/pycore_instruments.h index d134064d9ca24b..56b55e93a014cb 100644 --- a/Include/internal/pycore_instruments.h +++ b/Include/internal/pycore_instruments.h @@ -122,7 +122,7 @@ extern int _Py_Instrumentation_GetLine(PyCodeObject *code, _PyCoLineInstrumentationData *line_data, int index); static inline uint8_t -_PyCode_GetOriginalOpcode(_PyCoLineInstrumentationData *line_data, Py_ssize_t index) +_PyCode_GetOriginalOpcode(_PyCoLineInstrumentationData *line_data, int index) { return line_data->data[index*line_data->bytes_per_entry]; } diff --git a/Modules/_testinternalcapi/test_cases.c.h b/Modules/_testinternalcapi/test_cases.c.h index dcc2b9ef7fa54f..894c4d16e11bdd 100644 --- a/Modules/_testinternalcapi/test_cases.c.h +++ b/Modules/_testinternalcapi/test_cases.c.h @@ -7946,8 +7946,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); - assert(i > 0); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } @@ -13057,8 +13056,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); - assert(i > 0); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/bytecodes.c b/Python/bytecodes.c index cf7a56c95ff600..cf34db74a158cf 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1867,8 +1867,7 @@ dummy_func( assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); - assert(i > 0); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 67219fc9c61a05..4edbc999ef32bf 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -9346,8 +9346,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); - assert(i > 0); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 61d1bb5ec18324..900b6179286db6 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7945,8 +7945,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); - assert(i > 0); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } @@ -13054,8 +13053,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); - assert(i > 0); + int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/instrumentation.c b/Python/instrumentation.c index 00ac171658815e..51bcbfdb3b6c55 100644 --- a/Python/instrumentation.c +++ b/Python/instrumentation.c @@ -635,7 +635,7 @@ sanity_check_instrumentation(PyCodeObject *code) /* Get the underlying code unit, stripping instrumentation and ENTER_EXECUTOR */ _Py_CODEUNIT -_Py_GetBaseCodeUnit(PyCodeObject *code, Py_ssize_t i) +_Py_GetBaseCodeUnit(PyCodeObject *code, int i) { _Py_CODEUNIT *src_instr = _PyCode_CODE(code) + i; _Py_CODEUNIT inst = { From fcddba07928fec5683f925b2fbe1efaa7aba63f7 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Tue, 12 May 2026 09:37:30 +0500 Subject: [PATCH 4/7] Use Py_ssize_t before casting to int --- Modules/_testinternalcapi/test_cases.c.h | 10 ++++++---- Python/bytecodes.c | 5 +++-- Python/executor_cases.c.h | 5 +++-- Python/generated_cases.c.h | 10 ++++++---- 4 files changed, 18 insertions(+), 12 deletions(-) diff --git a/Modules/_testinternalcapi/test_cases.c.h b/Modules/_testinternalcapi/test_cases.c.h index 894c4d16e11bdd..16fb5392bdb4b4 100644 --- a/Modules/_testinternalcapi/test_cases.c.h +++ b/Modules/_testinternalcapi/test_cases.c.h @@ -7946,8 +7946,9 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; + Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i < INT_MAX); + int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } #endif @@ -13056,8 +13057,9 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; + Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i < INT_MAX); + int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } #endif diff --git a/Python/bytecodes.c b/Python/bytecodes.c index cf34db74a158cf..760a41902e570b 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1867,8 +1867,9 @@ dummy_func( assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; + Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i < INT_MAX); + int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } #endif diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 4edbc999ef32bf..06ac6a5bb954c4 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -9346,8 +9346,9 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; + Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i < INT_MAX); + int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } #endif diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index 900b6179286db6..de70e1cdf75cdd 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7945,8 +7945,9 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; + Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i < INT_MAX); + int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } #endif @@ -13053,8 +13054,9 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - int i = (int)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), i).op.code; + Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i < INT_MAX); + int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } #endif From 4ebb7d72ae82fdd4e9dfded420cb57b17a182a82 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Tue, 12 May 2026 15:26:59 +0500 Subject: [PATCH 5/7] Update Python/bytecodes.c Co-authored-by: Victor Stinner --- Python/bytecodes.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Python/bytecodes.c b/Python/bytecodes.c index 760a41902e570b..a13fb3dbfd3253 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1867,8 +1867,8 @@ dummy_func( assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - assert(i >= 0 && i < INT_MAX); + Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } From c286935016820217227dd8d2ab2c5bcce49b3832 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Tue, 12 May 2026 15:30:22 +0500 Subject: [PATCH 6/7] Update generated files --- Modules/_testinternalcapi/test_cases.c.h | 8 ++++---- Python/executor_cases.c.h | 4 ++-- Python/generated_cases.c.h | 8 ++++---- 3 files changed, 10 insertions(+), 10 deletions(-) diff --git a/Modules/_testinternalcapi/test_cases.c.h b/Modules/_testinternalcapi/test_cases.c.h index 16fb5392bdb4b4..83a842c2394abd 100644 --- a/Modules/_testinternalcapi/test_cases.c.h +++ b/Modules/_testinternalcapi/test_cases.c.h @@ -7946,8 +7946,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - assert(i >= 0 && i < INT_MAX); + Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } @@ -13057,8 +13057,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - assert(i >= 0 && i < INT_MAX); + Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index 06ac6a5bb954c4..e9d50bd9208a32 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -9346,8 +9346,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - assert(i >= 0 && i < INT_MAX); + Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index de70e1cdf75cdd..f3e61685d0a812 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7945,8 +7945,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - assert(i >= 0 && i < INT_MAX); + Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } @@ -13054,8 +13054,8 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (Py_ssize_t)(frame->instr_ptr - _PyFrame_GetBytecode(frame)); - assert(i >= 0 && i < INT_MAX); + Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); } From 2a61efbe015a6f56227cd5da5eb0554d229aab97 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Tue, 12 May 2026 15:32:03 +0500 Subject: [PATCH 7/7] Remove redundant parenthesises --- Modules/_testinternalcapi/test_cases.c.h | 4 ++-- Python/bytecodes.c | 2 +- Python/executor_cases.c.h | 2 +- Python/generated_cases.c.h | 4 ++-- 4 files changed, 6 insertions(+), 6 deletions(-) diff --git a/Modules/_testinternalcapi/test_cases.c.h b/Modules/_testinternalcapi/test_cases.c.h index 83a842c2394abd..a2506524f0bb6d 100644 --- a/Modules/_testinternalcapi/test_cases.c.h +++ b/Modules/_testinternalcapi/test_cases.c.h @@ -7946,7 +7946,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); @@ -13057,7 +13057,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); diff --git a/Python/bytecodes.c b/Python/bytecodes.c index a13fb3dbfd3253..f7487c7136962f 100644 --- a/Python/bytecodes.c +++ b/Python/bytecodes.c @@ -1867,7 +1867,7 @@ dummy_func( assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); diff --git a/Python/executor_cases.c.h b/Python/executor_cases.c.h index e9d50bd9208a32..efa61d7de74e88 100644 --- a/Python/executor_cases.c.h +++ b/Python/executor_cases.c.h @@ -9346,7 +9346,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); diff --git a/Python/generated_cases.c.h b/Python/generated_cases.c.h index f3e61685d0a812..53e09a8f4523c7 100644 --- a/Python/generated_cases.c.h +++ b/Python/generated_cases.c.h @@ -7945,7 +7945,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER); @@ -13054,7 +13054,7 @@ assert(INLINE_CACHE_ENTRIES_SEND == INLINE_CACHE_ENTRIES_FOR_ITER); #if TIER_ONE && defined(Py_DEBUG) if (!PyStackRef_IsNone(frame->f_executable)) { - Py_ssize_t i = (frame->instr_ptr - _PyFrame_GetBytecode(frame)); + Py_ssize_t i = frame->instr_ptr - _PyFrame_GetBytecode(frame); assert(i >= 0 && i <= INT_MAX); int opcode = _Py_GetBaseCodeUnit(_PyFrame_GetCode(frame), (int)i).op.code; assert(opcode == SEND || opcode == FOR_ITER);