Skip to content

Commit e66fd56

Browse files
committed
py/repl: Change mp_uint_t to size_t in repl helpers.
1 parent 7bd10c1 commit e66fd56

File tree

4 files changed

+14
-14
lines changed

4 files changed

+14
-14
lines changed

lib/mp-readline/readline.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -188,17 +188,17 @@ int readline_process_char(int c) {
188188
} else if (c == 9) {
189189
// tab magic
190190
const char *compl_str;
191-
mp_uint_t compl_len = mp_repl_autocomplete(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len, &mp_plat_print, &compl_str);
191+
size_t compl_len = mp_repl_autocomplete(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len, &mp_plat_print, &compl_str);
192192
if (compl_len == 0) {
193193
// no match
194-
} else if (compl_len == (mp_uint_t)(-1)) {
194+
} else if (compl_len == (size_t)(-1)) {
195195
// many matches
196196
mp_hal_stdout_tx_str(rl.prompt);
197197
mp_hal_stdout_tx_strn(rl.line->buf + rl.orig_line_len, rl.cursor_pos - rl.orig_line_len);
198198
redraw_from_cursor = true;
199199
} else {
200200
// one match
201-
for (mp_uint_t i = 0; i < compl_len; ++i) {
201+
for (size_t i = 0; i < compl_len; ++i) {
202202
vstr_ins_byte(rl.line, rl.cursor_pos + i, *compl_str++);
203203
}
204204
// set redraw parameters

py/repl.c

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232
#if MICROPY_HELPER_REPL
3333

3434
STATIC bool str_startswith_word(const char *str, const char *head) {
35-
mp_uint_t i;
35+
size_t i;
3636
for (i = 0; str[i] && head[i]; i++) {
3737
if (str[i] != head[i]) {
3838
return false;
@@ -124,7 +124,7 @@ bool mp_repl_continue_with_input(const char *input) {
124124
return false;
125125
}
126126

127-
mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t *print, const char **compl_str) {
127+
size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print, const char **compl_str) {
128128
// scan backwards to find start of "a.b.c" chain
129129
const char *org_str = str;
130130
const char *top = str + len;
@@ -145,13 +145,13 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
145145
while (str < top && *str != '.') {
146146
++str;
147147
}
148-
mp_uint_t s_len = str - s_start;
148+
size_t s_len = str - s_start;
149149

150150
if (str < top) {
151151
// a complete word, lookup in current dict
152152

153153
mp_obj_t obj = MP_OBJ_NULL;
154-
for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
154+
for (size_t i = 0; i < dict->map.alloc; i++) {
155155
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
156156
size_t d_len;
157157
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
@@ -194,8 +194,8 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
194194
// look for matches
195195
int n_found = 0;
196196
const char *match_str = NULL;
197-
mp_uint_t match_len = 0;
198-
for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
197+
size_t match_len = 0;
198+
for (size_t i = 0; i < dict->map.alloc; i++) {
199199
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
200200
size_t d_len;
201201
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
@@ -206,7 +206,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
206206
} else {
207207
// search for longest common prefix of match_str and d_str
208208
// (assumes these strings are null-terminated)
209-
for (mp_uint_t j = s_len; j <= match_len && j <= d_len; ++j) {
209+
for (size_t j = s_len; j <= match_len && j <= d_len; ++j) {
210210
if (match_str[j] != d_str[j]) {
211211
match_len = j;
212212
break;
@@ -245,7 +245,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
245245
#define MAX_LINE_LEN (4 * WORD_SLOT_LEN)
246246

247247
int line_len = MAX_LINE_LEN; // force a newline for first word
248-
for (mp_uint_t i = 0; i < dict->map.alloc; i++) {
248+
for (size_t i = 0; i < dict->map.alloc; i++) {
249249
if (MP_MAP_SLOT_IS_FILLED(&dict->map, i)) {
250250
size_t d_len;
251251
const char *d_str = mp_obj_str_get_data(dict->map.table[i].key, &d_len);
@@ -270,7 +270,7 @@ mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t
270270
}
271271
mp_print_str(print, "\n");
272272

273-
return (mp_uint_t)(-1); // indicate many matches
273+
return (size_t)(-1); // indicate many matches
274274
}
275275
}
276276
}

py/repl.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -32,7 +32,7 @@
3232

3333
#if MICROPY_HELPER_REPL
3434
bool mp_repl_continue_with_input(const char *input);
35-
mp_uint_t mp_repl_autocomplete(const char *str, mp_uint_t len, const mp_print_t *print, const char **compl_str);
35+
size_t mp_repl_autocomplete(const char *str, size_t len, const mp_print_t *print, const char **compl_str);
3636
#endif
3737

3838
#endif // __MICROPY_INCLUDED_PY_REPL_H__

unix/coverage.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -190,7 +190,7 @@ STATIC mp_obj_t extra_coverage(void) {
190190
mp_printf(&mp_plat_print, "# repl\n");
191191

192192
const char *str;
193-
mp_uint_t len = mp_repl_autocomplete("__n", 3, &mp_plat_print, &str);
193+
size_t len = mp_repl_autocomplete("__n", 3, &mp_plat_print, &str);
194194
mp_printf(&mp_plat_print, "%.*s\n", (int)len, str);
195195

196196
mp_store_global(MP_QSTR_sys, mp_import_name(MP_QSTR_sys, mp_const_none, MP_OBJ_NEW_SMALL_INT(0)));

0 commit comments

Comments
 (0)