Skip to content

Commit 6213ad7

Browse files
committed
py: Convert mp_uint_t to size_t for tuple/list accessors.
This patch changes mp_uint_t to size_t for the len argument of the following public facing C functions: mp_obj_tuple_get mp_obj_list_get mp_obj_get_array These functions take a pointer to the len argument (to be filled in by the function) and callers of these functions should update their code so the type of len is changed to size_t. For ports that don't use nan-boxing there should be no change in generate code because the size of the type remains the same (word sized), and in a lot of cases there won't even be a compiler warning if the type remains as mp_uint_t. The reason for this change is to standardise on the use of size_t for variables that count memory (or memory related) sizes/lengths. It helps builds that use nan-boxing.
1 parent f781618 commit 6213ad7

11 files changed

Lines changed: 19 additions & 19 deletions

File tree

py/builtinimport.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,7 +97,7 @@ STATIC mp_import_stat_t stat_dir_or_file(vstr_t *path) {
9797
STATIC mp_import_stat_t find_file(const char *file_str, uint file_len, vstr_t *dest) {
9898
#if MICROPY_PY_SYS
9999
// extract the list of paths
100-
mp_uint_t path_num;
100+
size_t path_num;
101101
mp_obj_t *path_items;
102102
mp_obj_list_get(mp_sys_path, &path_num, &path_items);
103103

py/modthread.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -215,7 +215,7 @@ STATIC mp_obj_t mod_thread_start_new_thread(size_t n_args, const mp_obj_t *args)
215215
thread_entry_args_t *th_args;
216216

217217
// get positional arguments
218-
mp_uint_t pos_args_len;
218+
size_t pos_args_len;
219219
mp_obj_t *pos_args_items;
220220
mp_obj_get_array(args[1], &pos_args_len, &pos_args_items);
221221

py/obj.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -321,7 +321,7 @@ void mp_obj_get_complex(mp_obj_t arg, mp_float_t *real, mp_float_t *imag) {
321321
#endif
322322

323323
// note: returned value in *items may point to the interior of a GC block
324-
void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items) {
324+
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
325325
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) {
326326
mp_obj_tuple_get(o, len, items);
327327
} else if (MP_OBJ_IS_TYPE(o, &mp_type_list)) {
@@ -338,7 +338,7 @@ void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items) {
338338

339339
// note: returned value in *items may point to the interior of a GC block
340340
void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) {
341-
mp_uint_t seq_len;
341+
size_t seq_len;
342342
mp_obj_get_array(o, &seq_len, items);
343343
if (seq_len != len) {
344344
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {

py/obj.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -676,7 +676,7 @@ mp_float_t mp_obj_get_float(mp_obj_t self_in);
676676
void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
677677
#endif
678678
//qstr mp_obj_get_qstr(mp_obj_t arg);
679-
void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items); // *items may point inside a GC block
679+
void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items); // *items may point inside a GC block
680680
void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items); // *items may point inside a GC block
681681
size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool is_slice);
682682
mp_obj_t mp_obj_id(mp_obj_t o_in);
@@ -728,7 +728,7 @@ mp_obj_t mp_obj_complex_binary_op(mp_uint_t op, mp_float_t lhs_real, mp_float_t
728728
#endif
729729

730730
// tuple
731-
void mp_obj_tuple_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items);
731+
void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
732732
void mp_obj_tuple_del(mp_obj_t self_in);
733733
mp_int_t mp_obj_tuple_hash(mp_obj_t self_in);
734734

@@ -737,7 +737,7 @@ struct _mp_obj_list_t;
737737
void mp_obj_list_init(struct _mp_obj_list_t *o, size_t n);
738738
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
739739
mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value);
740-
void mp_obj_list_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items);
740+
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
741741
void mp_obj_list_set_len(mp_obj_t self_in, size_t len);
742742
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
743743
mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);

py/objfun.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -513,7 +513,7 @@ STATIC mp_uint_t convert_obj_for_inline_asm(mp_obj_t obj) {
513513
#endif
514514
} else if (type == &mp_type_tuple || type == &mp_type_list) {
515515
// pointer to start of tuple (could pass length, but then could use len(x) for that)
516-
mp_uint_t len;
516+
size_t len;
517517
mp_obj_t *items;
518518
mp_obj_get_array(obj, &len, &items);
519519
return (mp_uint_t)items;

py/objlist.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ STATIC mp_obj_t list_subscr(mp_obj_t self_in, mp_obj_t index, mp_obj_t value) {
192192
#if MICROPY_PY_BUILTINS_SLICE
193193
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
194194
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
195-
mp_uint_t value_len; mp_obj_t *value_items;
195+
size_t value_len; mp_obj_t *value_items;
196196
mp_obj_get_array(value, &value_len, &value_items);
197197
mp_bound_slice_t slice_out;
198198
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) {
@@ -475,7 +475,7 @@ mp_obj_t mp_obj_new_list(size_t n, mp_obj_t *items) {
475475
return MP_OBJ_FROM_PTR(o);
476476
}
477477

478-
void mp_obj_list_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items) {
478+
void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items) {
479479
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
480480
*len = self->len;
481481
*items = self->items;

py/objnamedtuple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ STATIC mp_obj_t mp_obj_new_namedtuple_type(qstr name, size_t n_fields, mp_obj_t
158158

159159
STATIC mp_obj_t new_namedtuple_type(mp_obj_t name_in, mp_obj_t fields_in) {
160160
qstr name = mp_obj_str_get_qstr(name_in);
161-
mp_uint_t n_fields;
161+
size_t n_fields;
162162
mp_obj_t *fields;
163163
#if MICROPY_CPYTHON_COMPAT
164164
if (MP_OBJ_IS_STR(fields_in)) {

py/objstr.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,7 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
284284
// check for modulo
285285
if (op == MP_BINARY_OP_MODULO) {
286286
mp_obj_t *args = &rhs_in;
287-
mp_uint_t n_args = 1;
287+
size_t n_args = 1;
288288
mp_obj_t dict = MP_OBJ_NULL;
289289
if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_tuple)) {
290290
// TODO: Support tuple subclasses?
@@ -428,7 +428,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
428428
GET_STR_DATA_LEN(self_in, sep_str, sep_len);
429429

430430
// process args
431-
mp_uint_t seq_len;
431+
size_t seq_len;
432432
mp_obj_t *seq_items;
433433

434434
if (!MP_OBJ_IS_TYPE(arg, &mp_type_list) && !MP_OBJ_IS_TYPE(arg, &mp_type_tuple)) {

py/objtuple.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -244,7 +244,7 @@ mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items) {
244244
return MP_OBJ_FROM_PTR(o);
245245
}
246246

247-
void mp_obj_tuple_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items) {
247+
void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items) {
248248
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_tuple));
249249
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
250250
*len = self->len;

py/objtype.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -916,7 +916,7 @@ mp_obj_t mp_obj_new_type(qstr name, mp_obj_t bases_tuple, mp_obj_t locals_dict)
916916
// TODO might need to make a copy of locals_dict; at least that's how CPython does it
917917

918918
// Basic validation of base classes
919-
mp_uint_t len;
919+
size_t len;
920920
mp_obj_t *items;
921921
mp_obj_tuple_get(bases_tuple, &len, &items);
922922
for (size_t i = 0; i < len; i++) {
@@ -1098,7 +1098,7 @@ bool mp_obj_is_subclass_fast(mp_const_obj_t object, mp_const_obj_t classinfo) {
10981098
}
10991099

11001100
STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
1101-
mp_uint_t len;
1101+
size_t len;
11021102
mp_obj_t *items;
11031103
if (MP_OBJ_IS_TYPE(classinfo, &mp_type_type)) {
11041104
len = 1;

0 commit comments

Comments
 (0)