From 32450e8e4f1a59d73da86228c71f14f94c80013c Mon Sep 17 00:00:00 2001 From: Edd Barrett Date: Thu, 5 Mar 2026 15:30:54 +0000 Subject: [PATCH] Fix printing of yk locations. I suspected we were mis-placing locations. We weren't. We were printing them incorrectly in the bytecode dump. Before/after of bytecode dump of a simple test program: ```diff ... 03 JUMP 13 -05 DUP_TOP +05 ykloc: DUP_TOP 06 STORE_FAST 1 07 LOAD_FAST 0 08 LOAD_FAST 1 09 BINARY_OP 14 __iadd__ 10 STORE_FAST 0 11 LOAD_CONST_SMALL_INT 1 -12 ykloc: BINARY_OP 14 __iadd__ +12 BINARY_OP 14 __iadd__ 13 DUP_TOP 14 LOAD_CONST_SMALL_INT 100000 18 BINARY_OP 0 __lt__ 19 POP_JUMP_IF_TRUE 5 ... ``` Note `POP_JUMP_IF_TRUE 5` means "jump to bytecode offset 5 if true". Although it appears as an absolute jump in the dump, in-memory is stored as an ip-relative back-jump. --- py/showbc.c | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/py/showbc.c b/py/showbc.c index 8675d25ac5656..6fd25124fbb05 100644 --- a/py/showbc.c +++ b/py/showbc.c @@ -151,7 +151,9 @@ void mp_bytecode_print(const mp_print_t *print, const mp_raw_code_t *rc, size_t } } #ifdef USE_YK - mp_bytecode_print2(print, ip, fun_data_len - prelude_size, rc->children, cm, rc->yklocs); + // Pass a ptr to the location corresponding with the first non-header ip. + YkLocation *yklocs = rc->yklocs + prelude_size; + mp_bytecode_print2(print, ip, fun_data_len - prelude_size, rc->children, cm, yklocs); #else mp_bytecode_print2(print, ip, fun_data_len - prelude_size, rc->children, cm); #endif