Skip to content

Commit 2fce33c

Browse files
committed
py/objcode: Skip spurious and split entries in co_lines.
Signed-off-by: Anson Mansfield <amansfield@mantaro.com>
1 parent 971b169 commit 2fce33c

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

py/objcode.c

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,6 @@ static mp_obj_t code_colines_iter(mp_obj_t self_in) {
126126
iter->bc = 0;
127127
iter->source_line = 1;
128128
iter->ci = self->rc->prelude.line_info;
129-
code_colines_next(MP_OBJ_FROM_PTR(iter));
130129
return MP_OBJ_FROM_PTR(iter);
131130
}
132131
static MP_DEFINE_CONST_FUN_OBJ_1(code_colines_obj, code_colines_iter);
@@ -136,19 +135,30 @@ static mp_obj_t code_colines_next(mp_obj_t iter_in) {
136135

137136
mp_uint_t start = iter->bc;
138137
mp_uint_t line_no = iter->source_line;
138+
bool another = true;
139139

140-
if (iter->ci >= iter->rc->prelude.line_info_top) {
140+
while (another && iter->ci < iter->rc->prelude.line_info_top) {
141+
another = false;
142+
mp_code_lineinfo_t decoded = mp_bytecode_decode_lineinfo(&iter->ci);
143+
iter->bc += decoded.bc_increment;
144+
iter->source_line += decoded.line_increment;
145+
146+
if (decoded.bc_increment == 0) {
147+
line_no = iter->source_line;
148+
another = true;
149+
} else if (decoded.line_increment == 0) {
150+
another = true;
151+
}
152+
}
153+
154+
if (another) {
141155
mp_uint_t prelude_size = (iter->rc->prelude.opcodes - (const byte *)iter->rc->fun_data);
142156
mp_uint_t bc_end = iter->rc->fun_data_len - prelude_size;
143157
if (iter->bc >= bc_end) {
144158
return MP_OBJ_STOP_ITERATION;
145159
} else {
146160
iter->bc = bc_end;
147161
}
148-
} else {
149-
mp_code_lineinfo_t decoded = mp_bytecode_decode_lineinfo(&iter->ci);
150-
iter->bc += decoded.bc_increment;
151-
iter->source_line += decoded.line_increment;
152162
}
153163

154164
mp_uint_t end = iter->bc;

0 commit comments

Comments
 (0)
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy