Skip to content

Commit 6904583

Browse files
committed
extmod/modure: Make num_matches store actual number of matches.
1 parent 8c70523 commit 6904583

File tree

1 file changed

+3
-3
lines changed

1 file changed

+3
-3
lines changed

extmod/modure.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -54,13 +54,13 @@ typedef struct _mp_obj_match_t {
5454
STATIC void match_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t self_in, mp_print_kind_t kind) {
5555
(void)kind;
5656
mp_obj_match_t *self = self_in;
57-
print(env, "<match num=%d @%p>", self->num_matches);
57+
print(env, "<match num=%d>", self->num_matches);
5858
}
5959

6060
STATIC mp_obj_t match_group(mp_obj_t self_in, mp_obj_t no_in) {
6161
mp_obj_match_t *self = self_in;
6262
mp_int_t no = mp_obj_int_get_truncated(no_in);
63-
if (no < 0 || no >= self->num_matches / 2) {
63+
if (no < 0 || no >= self->num_matches) {
6464
nlr_raise(mp_obj_new_exception_arg1(&mp_type_IndexError, no_in));
6565
}
6666

@@ -104,7 +104,7 @@ STATIC mp_obj_t re_exec(bool is_anchored, uint n_args, const mp_obj_t *args) {
104104
}
105105

106106
match->base.type = &match_type;
107-
match->num_matches = caps_num;
107+
match->num_matches = caps_num / 2; // caps_num counts start and end pointers
108108
match->str = args[1];
109109
return match;
110110
}

0 commit comments

Comments
 (0)