Skip to content

Commit cc2dbdd

Browse files
committed
py/emitbc: Produce correct line number info for large bytecode chunks.
Previous to this patch, for large chunks of bytecode that originated from a single source-code line, the bytecode-line mapping would generate something like (for 42 bytecode bytes and 1 line): BC_SKIP=31 LINE_SKIP=1 BC_SKIP=11 LINE_SKIP=0 This would mean that any errors in the last 11 bytecode bytes would be reported on the following line. This patch fixes it to generate instead: BC_SKIP=31 LINE_SKIP=0 BC_SKIP=11 LINE_SKIP=1
1 parent 8f1c6d9 commit cc2dbdd

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

py/emitbc.c

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -144,10 +144,15 @@ STATIC void emit_write_code_info_bytes_lines(emit_t *emit, mp_uint_t bytes_to_sk
144144
//printf(" %d %d\n", bytes_to_skip, lines_to_skip);
145145
while (bytes_to_skip > 0 || lines_to_skip > 0) {
146146
mp_uint_t b, l;
147-
if (lines_to_skip <= 6) {
147+
if (lines_to_skip <= 6 || bytes_to_skip > 0xf) {
148148
// use 0b0LLBBBBB encoding
149149
b = MIN(bytes_to_skip, 0x1f);
150-
l = MIN(lines_to_skip, 0x3);
150+
if (b < bytes_to_skip) {
151+
// we can't skip any lines until we skip all the bytes
152+
l = 0;
153+
} else {
154+
l = MIN(lines_to_skip, 0x3);
155+
}
151156
*emit_get_cur_to_write_code_info(emit, 1) = b | (l << 5);
152157
} else {
153158
// use 0b1LLLBBBB 0bLLLLLLLL encoding (l's LSB in second byte)

0 commit comments

Comments
 (0)