py/objtuple: Convert mp_uint_t to size_t where appropriate.

This commit is contained in:
Damien George 2017-02-16 16:09:51 +11:00
parent 891dc5c62c
commit 229823942c
4 changed files with 18 additions and 18 deletions

View File

@ -630,7 +630,7 @@ mp_obj_t mp_obj_new_fun_viper(mp_uint_t n_args, void *fun_data, mp_uint_t type_s
mp_obj_t mp_obj_new_fun_asm(mp_uint_t n_args, void *fun_data, mp_uint_t type_sig);
mp_obj_t mp_obj_new_gen_wrap(mp_obj_t fun);
mp_obj_t mp_obj_new_closure(mp_obj_t fun, mp_uint_t n_closed, const mp_obj_t *closed);
mp_obj_t mp_obj_new_tuple(mp_uint_t n, const mp_obj_t *items);
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items);
mp_obj_t mp_obj_new_list(mp_uint_t n, mp_obj_t *items);
mp_obj_t mp_obj_new_dict(mp_uint_t n_args);
mp_obj_t mp_obj_new_set(mp_uint_t n_args, mp_obj_t *items);

View File

@ -34,7 +34,7 @@ STATIC
#endif
void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields, mp_obj_tuple_t *o) {
mp_print_str(print, "(");
for (mp_uint_t i = 0; i < o->len; i++) {
for (size_t i = 0; i < o->len; i++) {
if (i > 0) {
mp_print_str(print, ", ");
}
@ -59,9 +59,9 @@ STATIC void mp_obj_attrtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
if (dest[0] == MP_OBJ_NULL) {
// load attribute
mp_obj_tuple_t *self = MP_OBJ_TO_PTR(self_in);
mp_uint_t len = self->len;
size_t len = self->len;
const qstr *fields = (const qstr*)MP_OBJ_TO_PTR(self->items[len]);
for (mp_uint_t i = 0; i < len; i++) {
for (size_t i = 0; i < len; i++) {
if (fields[i] == attr) {
dest[0] = self->items[i];
return;
@ -70,11 +70,11 @@ STATIC void mp_obj_attrtuple_attr(mp_obj_t self_in, qstr attr, mp_obj_t *dest) {
}
}
mp_obj_t mp_obj_new_attrtuple(const qstr *fields, mp_uint_t n, const mp_obj_t *items) {
mp_obj_t mp_obj_new_attrtuple(const qstr *fields, size_t n, const mp_obj_t *items) {
mp_obj_tuple_t *o = m_new_obj_var(mp_obj_tuple_t, mp_obj_t, n + 1);
o->base.type = &mp_type_attrtuple;
o->len = n;
for (mp_uint_t i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
o->items[i] = items[i];
}
o->items[n] = MP_OBJ_FROM_PTR(fields);

View File

@ -32,7 +32,7 @@
#include "py/runtime0.h"
#include "py/runtime.h"
STATIC mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, mp_uint_t cur);
STATIC mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, size_t cur);
/******************************************************************************/
/* tuple */
@ -45,7 +45,7 @@ void mp_obj_tuple_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
mp_print_str(print, "(");
kind = PRINT_REPR;
}
for (mp_uint_t i = 0; i < o->len; i++) {
for (size_t i = 0; i < o->len; i++) {
if (i > 0) {
mp_print_str(print, ", ");
}
@ -80,8 +80,8 @@ STATIC mp_obj_t mp_obj_tuple_make_new(const mp_obj_type_t *type_in, size_t n_arg
// TODO optimise for cases where we know the length of the iterator
mp_uint_t alloc = 4;
mp_uint_t len = 0;
size_t alloc = 4;
size_t len = 0;
mp_obj_t *items = m_new(mp_obj_t, alloc);
mp_obj_t iterable = mp_getiter(args[0]);
@ -127,7 +127,7 @@ mp_obj_t mp_obj_tuple_unary_op(mp_uint_t op, mp_obj_t self_in) {
case MP_UNARY_OP_HASH: {
// start hash with pointer to empty tuple, to make it fairly unique
mp_int_t hash = (mp_int_t)mp_const_empty_tuple;
for (mp_uint_t i = 0; i < self->len; i++) {
for (size_t i = 0; i < self->len; i++) {
hash += MP_OBJ_SMALL_INT_VALUE(mp_unary_op(MP_UNARY_OP_HASH, self->items[i]));
}
return MP_OBJ_NEW_SMALL_INT(hash);
@ -235,7 +235,7 @@ const mp_obj_type_t mp_type_tuple = {
// the zero-length tuple
const mp_obj_tuple_t mp_const_empty_tuple_obj = {{&mp_type_tuple}, 0};
mp_obj_t mp_obj_new_tuple(mp_uint_t n, const mp_obj_t *items) {
mp_obj_t mp_obj_new_tuple(size_t n, const mp_obj_t *items) {
if (n == 0) {
return mp_const_empty_tuple;
}
@ -243,7 +243,7 @@ mp_obj_t mp_obj_new_tuple(mp_uint_t n, const mp_obj_t *items) {
o->base.type = &mp_type_tuple;
o->len = n;
if (items) {
for (mp_uint_t i = 0; i < n; i++) {
for (size_t i = 0; i < n; i++) {
o->items[i] = items[i];
}
}
@ -270,7 +270,7 @@ typedef struct _mp_obj_tuple_it_t {
mp_obj_base_t base;
mp_fun_1_t iternext;
mp_obj_tuple_t *tuple;
mp_uint_t cur;
size_t cur;
} mp_obj_tuple_it_t;
STATIC mp_obj_t tuple_it_iternext(mp_obj_t self_in) {
@ -284,7 +284,7 @@ STATIC mp_obj_t tuple_it_iternext(mp_obj_t self_in) {
}
}
STATIC mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, mp_uint_t cur) {
STATIC mp_obj_t mp_obj_new_tuple_iterator(mp_obj_tuple_t *tuple, size_t cur) {
mp_obj_tuple_it_t *o = m_new_obj(mp_obj_tuple_it_t);
o->base.type = &mp_type_polymorph_iter;
o->iternext = tuple_it_iternext;

View File

@ -30,13 +30,13 @@
typedef struct _mp_obj_tuple_t {
mp_obj_base_t base;
mp_uint_t len;
size_t len;
mp_obj_t items[];
} mp_obj_tuple_t;
typedef struct _mp_rom_obj_tuple_t {
mp_obj_base_t base;
mp_uint_t len;
size_t len;
mp_rom_obj_t items[];
} mp_rom_obj_tuple_t;
@ -59,6 +59,6 @@ extern const mp_obj_type_t mp_type_attrtuple;
void mp_obj_attrtuple_print_helper(const mp_print_t *print, const qstr *fields, mp_obj_tuple_t *o);
#endif
mp_obj_t mp_obj_new_attrtuple(const qstr *fields, mp_uint_t n, const mp_obj_t *items);
mp_obj_t mp_obj_new_attrtuple(const qstr *fields, size_t n, const mp_obj_t *items);
#endif // __MICROPY_INCLUDED_PY_OBJTUPLE_H__