Skip to content

Commit 4e3bac2

Browse files
committed
py/runtime: Convert mp_uint_t to size_t where appropriate.
1 parent a937750 commit 4e3bac2

3 files changed

Lines changed: 24 additions & 24 deletions

File tree

py/nativeglue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -86,7 +86,7 @@ mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type) {
8686

8787
// wrapper that accepts n_args and n_kw in one argument
8888
// (native emitter can only pass at most 3 arguments to a function)
89-
mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, mp_uint_t n_args_kw, const mp_obj_t *args) {
89+
mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, size_t n_args_kw, const mp_obj_t *args) {
9090
return mp_call_function_n_kw(fun_in, n_args_kw & 0xff, (n_args_kw >> 8) & 0xff, args);
9191
}
9292

py/runtime.c

Lines changed: 15 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs) {
301301
}
302302
} else if (MP_OBJ_IS_TYPE(rhs, &mp_type_tuple)) {
303303
mp_obj_tuple_t *tuple = MP_OBJ_TO_PTR(rhs);
304-
for (mp_uint_t i = 0; i < tuple->len; i++) {
304+
for (size_t i = 0; i < tuple->len; i++) {
305305
rhs = tuple->items[i];
306306
if (!mp_obj_is_exception_type(rhs)) {
307307
goto unsupported_op;
@@ -580,7 +580,7 @@ mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2) {
580580
}
581581

582582
// args contains, eg: arg0 arg1 key0 value0 key1 value1
583-
mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
583+
mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, size_t n_args, size_t n_kw, const mp_obj_t *args) {
584584
// TODO improve this: fun object can specify its type and we parse here the arguments,
585585
// passing to the function arrays of fixed and keyword arguments
586586

@@ -604,7 +604,7 @@ mp_obj_t mp_call_function_n_kw(mp_obj_t fun_in, mp_uint_t n_args, mp_uint_t n_kw
604604

605605
// args contains: fun self/NULL arg(0) ... arg(n_args-2) arg(n_args-1) kw_key(0) kw_val(0) ... kw_key(n_kw-1) kw_val(n_kw-1)
606606
// if n_args==0 and n_kw==0 then there are only fun and self/NULL
607-
mp_obj_t mp_call_method_n_kw(mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args) {
607+
mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args) {
608608
DEBUG_OP_printf("call method (fun=%p, self=%p, n_args=" UINT_FMT ", n_kw=" UINT_FMT ", args=%p)\n", args[0], args[1], n_args, n_kw, args);
609609
int adjust = (args[1] == MP_OBJ_NULL) ? 0 : 1;
610610
return mp_call_function_n_kw(args[0], n_args + adjust, n_kw, args + 2 - adjust);
@@ -614,7 +614,7 @@ mp_obj_t mp_call_method_n_kw(mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *a
614614
#if !MICROPY_STACKLESS
615615
STATIC
616616
#endif
617-
void mp_call_prepare_args_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const mp_obj_t *args, mp_call_args_t *out_args) {
617+
void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args, mp_call_args_t *out_args) {
618618
mp_obj_t fun = *args++;
619619
mp_obj_t self = MP_OBJ_NULL;
620620
if (have_self) {
@@ -724,7 +724,7 @@ void mp_call_prepare_args_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const
724724
// dictionary
725725
mp_map_t *map = mp_obj_dict_get_map(kw_dict);
726726
assert(args2_len + 2 * map->used <= args2_alloc); // should have enough, since kw_dict_len is in this case hinted correctly above
727-
for (mp_uint_t i = 0; i < map->alloc; i++) {
727+
for (size_t i = 0; i < map->alloc; i++) {
728728
if (MP_MAP_SLOT_IS_FILLED(map, i)) {
729729
// the key must be a qstr, so intern it if it's a string
730730
mp_obj_t key = map->table[i].key;
@@ -780,7 +780,7 @@ void mp_call_prepare_args_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const
780780
out_args->n_alloc = args2_alloc;
781781
}
782782

783-
mp_obj_t mp_call_method_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const mp_obj_t *args) {
783+
mp_obj_t mp_call_method_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args) {
784784
mp_call_args_t out_args;
785785
mp_call_prepare_args_n_kw_var(have_self, n_args_n_kw, args, &out_args);
786786

@@ -791,7 +791,7 @@ mp_obj_t mp_call_method_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const mp
791791
}
792792

793793
// unpacked items are stored in reverse order into the array pointed to by items
794-
void mp_unpack_sequence(mp_obj_t seq_in, mp_uint_t num, mp_obj_t *items) {
794+
void mp_unpack_sequence(mp_obj_t seq_in, size_t num, mp_obj_t *items) {
795795
mp_uint_t seq_len;
796796
if (MP_OBJ_IS_TYPE(seq_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(seq_in, &mp_type_list)) {
797797
mp_obj_t *seq_items;
@@ -805,7 +805,7 @@ void mp_unpack_sequence(mp_obj_t seq_in, mp_uint_t num, mp_obj_t *items) {
805805
} else if (seq_len > num) {
806806
goto too_long;
807807
}
808-
for (mp_uint_t i = 0; i < num; i++) {
808+
for (size_t i = 0; i < num; i++) {
809809
items[i] = seq_items[num - 1 - i];
810810
}
811811
} else {
@@ -841,9 +841,9 @@ void mp_unpack_sequence(mp_obj_t seq_in, mp_uint_t num, mp_obj_t *items) {
841841
}
842842

843843
// unpacked items are stored in reverse order into the array pointed to by items
844-
void mp_unpack_ex(mp_obj_t seq_in, mp_uint_t num_in, mp_obj_t *items) {
845-
mp_uint_t num_left = num_in & 0xff;
846-
mp_uint_t num_right = (num_in >> 8) & 0xff;
844+
void mp_unpack_ex(mp_obj_t seq_in, size_t num_in, mp_obj_t *items) {
845+
size_t num_left = num_in & 0xff;
846+
size_t num_right = (num_in >> 8) & 0xff;
847847
DEBUG_OP_printf("unpack ex " UINT_FMT " " UINT_FMT "\n", num_left, num_right);
848848
mp_uint_t seq_len;
849849
if (MP_OBJ_IS_TYPE(seq_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(seq_in, &mp_type_list)) {
@@ -861,11 +861,11 @@ void mp_unpack_ex(mp_obj_t seq_in, mp_uint_t num_in, mp_obj_t *items) {
861861
if (seq_len < num_left + num_right) {
862862
goto too_short;
863863
}
864-
for (mp_uint_t i = 0; i < num_right; i++) {
864+
for (size_t i = 0; i < num_right; i++) {
865865
items[i] = seq_items[seq_len - 1 - i];
866866
}
867867
items[num_right] = mp_obj_new_list(seq_len - num_left - num_right, seq_items + num_left);
868-
for (mp_uint_t i = 0; i < num_left; i++) {
868+
for (size_t i = 0; i < num_left; i++) {
869869
items[num_right + 1 + i] = seq_items[num_left - 1 - i];
870870
}
871871
} else {
@@ -890,7 +890,7 @@ void mp_unpack_ex(mp_obj_t seq_in, mp_uint_t num_in, mp_obj_t *items) {
890890
goto too_short;
891891
}
892892
items[num_right] = MP_OBJ_FROM_PTR(rest);
893-
for (mp_uint_t i = 0; i < num_right; i++) {
893+
for (size_t i = 0; i < num_right; i++) {
894894
items[num_right - 1 - i] = rest->items[rest->len - num_right + i];
895895
}
896896
mp_obj_list_set_len(MP_OBJ_FROM_PTR(rest), rest->len - num_right);
@@ -1350,7 +1350,7 @@ void mp_import_all(mp_obj_t module) {
13501350

13511351
// TODO: Support __all__
13521352
mp_map_t *map = mp_obj_dict_get_map(MP_OBJ_FROM_PTR(mp_obj_module_get_globals(module)));
1353-
for (mp_uint_t i = 0; i < map->alloc; i++) {
1353+
for (size_t i = 0; i < map->alloc; i++) {
13541354
if (MP_MAP_SLOT_IS_FILLED(map, i)) {
13551355
qstr name = MP_OBJ_QSTR_VALUE(map->table[i].key);
13561356
if (*qstr_str(name) != '_') {

py/runtime.h

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -92,17 +92,17 @@ mp_obj_t mp_binary_op(mp_uint_t op, mp_obj_t lhs, mp_obj_t rhs);
9292
mp_obj_t mp_call_function_0(mp_obj_t fun);
9393
mp_obj_t mp_call_function_1(mp_obj_t fun, mp_obj_t arg);
9494
mp_obj_t mp_call_function_2(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
95-
mp_obj_t mp_call_function_n_kw(mp_obj_t fun, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
96-
mp_obj_t mp_call_method_n_kw(mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
97-
mp_obj_t mp_call_method_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const mp_obj_t *args);
95+
mp_obj_t mp_call_function_n_kw(mp_obj_t fun, size_t n_args, size_t n_kw, const mp_obj_t *args);
96+
mp_obj_t mp_call_method_n_kw(size_t n_args, size_t n_kw, const mp_obj_t *args);
97+
mp_obj_t mp_call_method_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args);
9898
mp_obj_t mp_call_method_self_n_kw(mp_obj_t meth, mp_obj_t self, size_t n_args, size_t n_kw, const mp_obj_t *args);
9999
// Call function and catch/dump exception - for Python callbacks from C code
100100
void mp_call_function_1_protected(mp_obj_t fun, mp_obj_t arg);
101101
void mp_call_function_2_protected(mp_obj_t fun, mp_obj_t arg1, mp_obj_t arg2);
102102

103103
typedef struct _mp_call_args_t {
104104
mp_obj_t fun;
105-
mp_uint_t n_args, n_kw, n_alloc;
105+
size_t n_args, n_kw, n_alloc;
106106
mp_obj_t *args;
107107
} mp_call_args_t;
108108

@@ -111,11 +111,11 @@ typedef struct _mp_call_args_t {
111111
// prepares argument array suitable for passing to ->call() method of a
112112
// function object (and mp_call_function_n_kw()).
113113
// (Only needed in stackless mode.)
114-
void mp_call_prepare_args_n_kw_var(bool have_self, mp_uint_t n_args_n_kw, const mp_obj_t *args, mp_call_args_t *out_args);
114+
void mp_call_prepare_args_n_kw_var(bool have_self, size_t n_args_n_kw, const mp_obj_t *args, mp_call_args_t *out_args);
115115
#endif
116116

117-
void mp_unpack_sequence(mp_obj_t seq, mp_uint_t num, mp_obj_t *items);
118-
void mp_unpack_ex(mp_obj_t seq, mp_uint_t num, mp_obj_t *items);
117+
void mp_unpack_sequence(mp_obj_t seq, size_t num, mp_obj_t *items);
118+
void mp_unpack_ex(mp_obj_t seq, size_t num, mp_obj_t *items);
119119
mp_obj_t mp_store_map(mp_obj_t map, mp_obj_t key, mp_obj_t value);
120120
mp_obj_t mp_load_attr(mp_obj_t base, qstr attr);
121121
void mp_convert_member_lookup(mp_obj_t obj, const mp_obj_type_t *type, mp_obj_t member, mp_obj_t *dest);
@@ -155,7 +155,7 @@ NORETURN void mp_exc_recursion_depth(void);
155155
// helper functions for native/viper code
156156
mp_uint_t mp_convert_obj_to_native(mp_obj_t obj, mp_uint_t type);
157157
mp_obj_t mp_convert_native_to_obj(mp_uint_t val, mp_uint_t type);
158-
mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, mp_uint_t n_args_kw, const mp_obj_t *args);
158+
mp_obj_t mp_native_call_function_n_kw(mp_obj_t fun_in, size_t n_args_kw, const mp_obj_t *args);
159159
void mp_native_raise(mp_obj_t o);
160160

161161
#define mp_sys_path (MP_OBJ_FROM_PTR(&MP_STATE_VM(mp_sys_path_obj)))

0 commit comments

Comments
 (0)