From 0cb3e7dea882d434a10bab82b3f72b50a0cc63a4 Mon Sep 17 00:00:00 2001 From: Sergey Miryanov Date: Thu, 7 May 2026 21:45:38 +0500 Subject: [PATCH 1/2] 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/2] 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 = {