Skip to content

Commit 9557076

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

File tree

1 file changed

+17
-6
lines changed

1 file changed

+17
-6
lines changed

py/objcode.c

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -126,29 +126,40 @@ 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);
133132

134133
static mp_obj_t code_colines_next(mp_obj_t iter_in) {
135134
mp_obj_colines_iter_t *iter = MP_OBJ_TO_PTR(iter_in);
135+
const byte *ci_end = iter->rc->prelude.line_info_top;
136136

137137
mp_uint_t start = iter->bc;
138138
mp_uint_t line_no = iter->source_line;
139+
bool another = true;
139140

140-
if (iter->ci >= iter->rc->prelude.line_info_top) {
141+
while (another && iter->ci < ci_end) {
142+
another = false;
143+
mp_code_lineinfo_t decoded = mp_bytecode_decode_lineinfo(&iter->ci);
144+
iter->bc += decoded.bc_increment;
145+
iter->source_line += decoded.line_increment;
146+
147+
if (decoded.bc_increment == 0) {
148+
line_no = iter->source_line;
149+
another = true;
150+
} else if (decoded.line_increment == 0) {
151+
another = true;
152+
}
153+
}
154+
155+
if (another) {
141156
mp_uint_t prelude_size = (iter->rc->prelude.opcodes - (const byte *)iter->rc->fun_data);
142157
mp_uint_t bc_end = iter->rc->fun_data_len - prelude_size;
143158
if (iter->bc >= bc_end) {
144159
return MP_OBJ_STOP_ITERATION;
145160
} else {
146161
iter->bc = bc_end;
147162
}
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;
152163
}
153164

154165
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