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.
diff --git a/py/builtinimport.c b/py/builtinimport.c
index 17c1622..8101d63 100644
--- a/py/builtinimport.c
+++ b/py/builtinimport.c
@@ -97,7 +97,7 @@
STATIC mp_import_stat_t find_file(const char *file_str, uint file_len, vstr_t *dest) {
#if MICROPY_PY_SYS
// extract the list of paths
- mp_uint_t path_num;
+ size_t path_num;
mp_obj_t *path_items;
mp_obj_list_get(mp_sys_path, &path_num, &path_items);
diff --git a/py/modthread.c b/py/modthread.c
index ecf4705..d0e71da 100644
--- a/py/modthread.c
+++ b/py/modthread.c
@@ -215,7 +215,7 @@
thread_entry_args_t *th_args;
// get positional arguments
- mp_uint_t pos_args_len;
+ size_t pos_args_len;
mp_obj_t *pos_args_items;
mp_obj_get_array(args[1], &pos_args_len, &pos_args_items);
diff --git a/py/obj.c b/py/obj.c
index 4b5fe25..98ffa93 100644
--- a/py/obj.c
+++ b/py/obj.c
@@ -321,7 +321,7 @@
#endif
// note: returned value in *items may point to the interior of a GC block
-void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items) {
+void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items) {
if (MP_OBJ_IS_TYPE(o, &mp_type_tuple)) {
mp_obj_tuple_get(o, len, items);
} else if (MP_OBJ_IS_TYPE(o, &mp_type_list)) {
@@ -338,7 +338,7 @@
// note: returned value in *items may point to the interior of a GC block
void mp_obj_get_array_fixed_n(mp_obj_t o, size_t len, mp_obj_t **items) {
- mp_uint_t seq_len;
+ size_t seq_len;
mp_obj_get_array(o, &seq_len, items);
if (seq_len != len) {
if (MICROPY_ERROR_REPORTING == MICROPY_ERROR_REPORTING_TERSE) {
diff --git a/py/obj.h b/py/obj.h
index 71945f4..65543b7 100644
--- a/py/obj.h
+++ b/py/obj.h
@@ -676,7 +676,7 @@
void mp_obj_get_complex(mp_obj_t self_in, mp_float_t *real, mp_float_t *imag);
#endif
//qstr mp_obj_get_qstr(mp_obj_t arg);
-void mp_obj_get_array(mp_obj_t o, mp_uint_t *len, mp_obj_t **items); // *items may point inside a GC block
+void mp_obj_get_array(mp_obj_t o, size_t *len, mp_obj_t **items); // *items may point inside a GC block
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
size_t mp_get_index(const mp_obj_type_t *type, size_t len, mp_obj_t index, bool is_slice);
mp_obj_t mp_obj_id(mp_obj_t o_in);
@@ -728,7 +728,7 @@
#endif
// tuple
-void mp_obj_tuple_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items);
+void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
void mp_obj_tuple_del(mp_obj_t self_in);
mp_int_t mp_obj_tuple_hash(mp_obj_t self_in);
@@ -737,7 +737,7 @@
void mp_obj_list_init(struct _mp_obj_list_t *o, size_t n);
mp_obj_t mp_obj_list_append(mp_obj_t self_in, mp_obj_t arg);
mp_obj_t mp_obj_list_remove(mp_obj_t self_in, mp_obj_t value);
-void mp_obj_list_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items);
+void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items);
void mp_obj_list_set_len(mp_obj_t self_in, size_t len);
void mp_obj_list_store(mp_obj_t self_in, mp_obj_t index, mp_obj_t value);
mp_obj_t mp_obj_list_sort(size_t n_args, const mp_obj_t *args, mp_map_t *kwargs);
diff --git a/py/objfun.c b/py/objfun.c
index 4670521..2ce33cb 100644
--- a/py/objfun.c
+++ b/py/objfun.c
@@ -513,7 +513,7 @@
#endif
} else if (type == &mp_type_tuple || type == &mp_type_list) {
// pointer to start of tuple (could pass length, but then could use len(x) for that)
- mp_uint_t len;
+ size_t len;
mp_obj_t *items;
mp_obj_get_array(obj, &len, &items);
return (mp_uint_t)items;
diff --git a/py/objlist.c b/py/objlist.c
index 312cef6..45e69c8 100644
--- a/py/objlist.c
+++ b/py/objlist.c
@@ -192,7 +192,7 @@
#if MICROPY_PY_BUILTINS_SLICE
if (MP_OBJ_IS_TYPE(index, &mp_type_slice)) {
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
- mp_uint_t value_len; mp_obj_t *value_items;
+ size_t value_len; mp_obj_t *value_items;
mp_obj_get_array(value, &value_len, &value_items);
mp_bound_slice_t slice_out;
if (!mp_seq_get_fast_slice_indexes(self->len, index, &slice_out)) {
@@ -475,7 +475,7 @@
return MP_OBJ_FROM_PTR(o);
}
-void mp_obj_list_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items) {
+void mp_obj_list_get(mp_obj_t self_in, size_t *len, mp_obj_t **items) {
mp_obj_list_t *self = MP_OBJ_TO_PTR(self_in);
*len = self->len;
*items = self->items;
diff --git a/py/objnamedtuple.c b/py/objnamedtuple.c
index 2371518..5246874 100644
--- a/py/objnamedtuple.c
+++ b/py/objnamedtuple.c
@@ -158,7 +158,7 @@
STATIC mp_obj_t new_namedtuple_type(mp_obj_t name_in, mp_obj_t fields_in) {
qstr name = mp_obj_str_get_qstr(name_in);
- mp_uint_t n_fields;
+ size_t n_fields;
mp_obj_t *fields;
#if MICROPY_CPYTHON_COMPAT
if (MP_OBJ_IS_STR(fields_in)) {
diff --git a/py/objstr.c b/py/objstr.c
index 4053efb..682bd26 100644
--- a/py/objstr.c
+++ b/py/objstr.c
@@ -284,7 +284,7 @@
// check for modulo
if (op == MP_BINARY_OP_MODULO) {
mp_obj_t *args = &rhs_in;
- mp_uint_t n_args = 1;
+ size_t n_args = 1;
mp_obj_t dict = MP_OBJ_NULL;
if (MP_OBJ_IS_TYPE(rhs_in, &mp_type_tuple)) {
// TODO: Support tuple subclasses?
@@ -428,7 +428,7 @@
GET_STR_DATA_LEN(self_in, sep_str, sep_len);
// process args
- mp_uint_t seq_len;
+ size_t seq_len;
mp_obj_t *seq_items;
if (!MP_OBJ_IS_TYPE(arg, &mp_type_list) && !MP_OBJ_IS_TYPE(arg, &mp_type_tuple)) {
diff --git a/py/objtuple.c b/py/objtuple.c
index a8efdc7..fa5309a 100644
--- a/py/objtuple.c
+++ b/py/objtuple.c
@@ -244,7 +244,7 @@
return MP_OBJ_FROM_PTR(o);
}
-void mp_obj_tuple_get(mp_obj_t self_in, mp_uint_t *len, mp_obj_t **items) {
+void mp_obj_tuple_get(mp_obj_t self_in, size_t *len, mp_obj_t **items) {
assert(MP_OBJ_IS_TYPE(self_in, &mp_type_tuple));
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
*len = self->len;
diff --git a/py/objtype.c b/py/objtype.c
index a64832c..dd170b4 100644
--- a/py/objtype.c
+++ b/py/objtype.c
@@ -916,7 +916,7 @@
// TODO might need to make a copy of locals_dict; at least that's how CPython does it
// Basic validation of base classes
- mp_uint_t len;
+ size_t len;
mp_obj_t *items;
mp_obj_tuple_get(bases_tuple, &len, &items);
for (size_t i = 0; i < len; i++) {
@@ -1098,7 +1098,7 @@
}
STATIC mp_obj_t mp_obj_is_subclass(mp_obj_t object, mp_obj_t classinfo) {
- mp_uint_t len;
+ size_t len;
mp_obj_t *items;
if (MP_OBJ_IS_TYPE(classinfo, &mp_type_type)) {
len = 1;
diff --git a/py/runtime.c b/py/runtime.c
index 9f6c654..73886e1 100644
--- a/py/runtime.c
+++ b/py/runtime.c
@@ -670,7 +670,7 @@
// optimise the case of a tuple and list
// get the items
- mp_uint_t len;
+ size_t len;
mp_obj_t *items;
mp_obj_get_array(pos_seq, &len, &items);
@@ -799,7 +799,7 @@
// unpacked items are stored in reverse order into the array pointed to by items
void mp_unpack_sequence(mp_obj_t seq_in, size_t num, mp_obj_t *items) {
- mp_uint_t seq_len;
+ size_t seq_len;
if (MP_OBJ_IS_TYPE(seq_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(seq_in, &mp_type_list)) {
mp_obj_t *seq_items;
mp_obj_get_array(seq_in, &seq_len, &seq_items);
@@ -849,7 +849,7 @@
size_t num_left = num_in & 0xff;
size_t num_right = (num_in >> 8) & 0xff;
DEBUG_OP_printf("unpack ex " UINT_FMT " " UINT_FMT "\n", num_left, num_right);
- mp_uint_t seq_len;
+ size_t seq_len;
if (MP_OBJ_IS_TYPE(seq_in, &mp_type_tuple) || MP_OBJ_IS_TYPE(seq_in, &mp_type_list)) {
mp_obj_t *seq_items;
mp_obj_get_array(seq_in, &seq_len, &seq_items);