Skip to content

Commit ccc5254

Browse files
committed
py/objarray: Convert mp_uint_t to size_t where appropriate.
1 parent c0d9500 commit ccc5254

3 files changed

Lines changed: 22 additions & 22 deletions

File tree

py/obj.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -613,8 +613,8 @@ mp_obj_t mp_obj_new_int_from_ull(unsigned long long val); // this must return a
613613
mp_obj_t mp_obj_new_str(const char* data, size_t len, bool make_qstr_if_not_already);
614614
mp_obj_t mp_obj_new_str_from_vstr(const mp_obj_type_t *type, vstr_t *vstr);
615615
mp_obj_t mp_obj_new_bytes(const byte* data, size_t len);
616-
mp_obj_t mp_obj_new_bytearray(mp_uint_t n, void *items);
617-
mp_obj_t mp_obj_new_bytearray_by_ref(mp_uint_t n, void *items);
616+
mp_obj_t mp_obj_new_bytearray(size_t n, void *items);
617+
mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items);
618618
#if MICROPY_PY_BUILTINS_FLOAT
619619
mp_obj_t mp_obj_new_int_from_float(mp_float_t val);
620620
mp_obj_t mp_obj_new_complex(mp_float_t real, mp_float_t imag);
@@ -639,7 +639,7 @@ mp_obj_t mp_obj_new_super(mp_obj_t type, mp_obj_t obj);
639639
mp_obj_t mp_obj_new_bound_meth(mp_obj_t meth, mp_obj_t self);
640640
mp_obj_t mp_obj_new_getitem_iter(mp_obj_t *args);
641641
mp_obj_t mp_obj_new_module(qstr module_name);
642-
mp_obj_t mp_obj_new_memoryview(byte typecode, mp_uint_t nitems, void *items);
642+
mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items);
643643

644644
mp_obj_type_t *mp_obj_get_type(mp_const_obj_t o_in);
645645
const char *mp_obj_get_type_str(mp_const_obj_t o_in);

py/objarray.c

Lines changed: 16 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@
5656
#if MICROPY_PY_BUILTINS_MEMORYVIEW
5757
#define TYPECODE_MASK (0x7f)
5858
#else
59-
#define TYPECODE_MASK (~(mp_uint_t)0)
59+
#define TYPECODE_MASK (~(size_t)0)
6060
#endif
6161

6262
STATIC mp_obj_t array_iterator_new(mp_obj_t array_in);
@@ -78,7 +78,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
7878
mp_printf(print, "array('%c'", o->typecode);
7979
if (o->len > 0) {
8080
mp_print_str(print, ", [");
81-
for (mp_uint_t i = 0; i < o->len; i++) {
81+
for (size_t i = 0; i < o->len; i++) {
8282
if (i > 0) {
8383
mp_print_str(print, ", ");
8484
}
@@ -92,7 +92,7 @@ STATIC void array_print(const mp_print_t *print, mp_obj_t o_in, mp_print_kind_t
9292
#endif
9393

9494
#if MICROPY_PY_BUILTINS_BYTEARRAY || MICROPY_PY_ARRAY
95-
STATIC mp_obj_array_t *array_new(char typecode, mp_uint_t n) {
95+
STATIC mp_obj_array_t *array_new(char typecode, size_t n) {
9696
int typecode_size = mp_binary_get_size('@', typecode, NULL);
9797
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
9898
#if MICROPY_PY_BUILTINS_BYTEARRAY && MICROPY_PY_ARRAY
@@ -124,13 +124,13 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
124124
// construct array from raw bytes
125125
// we round-down the len to make it a multiple of sz (CPython raises error)
126126
size_t sz = mp_binary_get_size('@', typecode, NULL);
127-
mp_uint_t len = bufinfo.len / sz;
127+
size_t len = bufinfo.len / sz;
128128
mp_obj_array_t *o = array_new(typecode, len);
129129
memcpy(o->items, bufinfo.buf, len * sz);
130130
return MP_OBJ_FROM_PTR(o);
131131
}
132132

133-
mp_uint_t len;
133+
size_t len;
134134
// Try to create array of exact len if initializer len is known
135135
mp_obj_t len_in = mp_obj_len_maybe(initializer);
136136
if (len_in == MP_OBJ_NULL) {
@@ -143,7 +143,7 @@ STATIC mp_obj_t array_construct(char typecode, mp_obj_t initializer) {
143143

144144
mp_obj_t iterable = mp_getiter(initializer);
145145
mp_obj_t item;
146-
mp_uint_t i = 0;
146+
size_t i = 0;
147147
while ((item = mp_iternext(iterable)) != MP_OBJ_STOP_ITERATION) {
148148
if (len == 0) {
149149
array_append(MP_OBJ_FROM_PTR(array), item);
@@ -198,7 +198,7 @@ STATIC mp_obj_t bytearray_make_new(const mp_obj_type_t *type_in, size_t n_args,
198198

199199
#if MICROPY_PY_BUILTINS_MEMORYVIEW
200200

201-
mp_obj_t mp_obj_new_memoryview(byte typecode, mp_uint_t nitems, void *items) {
201+
mp_obj_t mp_obj_new_memoryview(byte typecode, size_t nitems, void *items) {
202202
mp_obj_array_t *self = m_new_obj(mp_obj_array_t);
203203
self->base.type = &mp_type_memoryview;
204204
self->typecode = typecode;
@@ -254,7 +254,7 @@ STATIC mp_obj_t array_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in)
254254
size_t sz = mp_binary_get_size('@', lhs_bufinfo.typecode, NULL);
255255

256256
// convert byte count to element count (in case rhs is not multiple of sz)
257-
mp_uint_t rhs_len = rhs_bufinfo.len / sz;
257+
size_t rhs_len = rhs_bufinfo.len / sz;
258258

259259
// note: lhs->len is element count of lhs, lhs_bufinfo.len is byte count
260260
mp_obj_array_t *res = array_new(lhs_bufinfo.typecode, lhs->len + rhs_len);
@@ -345,7 +345,7 @@ STATIC mp_obj_t array_extend(mp_obj_t self_in, mp_obj_t arg_in) {
345345
size_t sz = mp_binary_get_size('@', self->typecode, NULL);
346346

347347
// convert byte count to element count
348-
mp_uint_t len = arg_bufinfo.len / sz;
348+
size_t len = arg_bufinfo.len / sz;
349349

350350
// make sure we have enough room to extend
351351
// TODO: alloc policy; at the moment we go conservative
@@ -384,7 +384,7 @@ STATIC mp_obj_t array_subscr(mp_obj_t self_in, mp_obj_t index_in, mp_obj_t value
384384
if (value != MP_OBJ_SENTINEL) {
385385
#if MICROPY_PY_ARRAY_SLICE_ASSIGN
386386
// Assign
387-
mp_uint_t src_len;
387+
size_t src_len;
388388
void *src_items;
389389
size_t item_sz = mp_binary_get_size('@', o->typecode & TYPECODE_MASK, NULL);
390390
if (MP_OBJ_IS_OBJ(value) && ((mp_obj_base_t*)MP_OBJ_TO_PTR(value))->type->subscr == array_subscr) {
@@ -501,7 +501,7 @@ STATIC mp_int_t array_get_buffer(mp_obj_t o_in, mp_buffer_info_t *bufinfo, mp_ui
501501
// read-only memoryview
502502
return 1;
503503
}
504-
bufinfo->buf = (uint8_t*)bufinfo->buf + (mp_uint_t)o->free * sz;
504+
bufinfo->buf = (uint8_t*)bufinfo->buf + (size_t)o->free * sz;
505505
}
506506
#else
507507
(void)flags;
@@ -562,20 +562,20 @@ const mp_obj_type_t mp_type_memoryview = {
562562
#endif
563563

564564
/* unused
565-
mp_uint_t mp_obj_array_len(mp_obj_t self_in) {
565+
size_t mp_obj_array_len(mp_obj_t self_in) {
566566
return ((mp_obj_array_t *)self_in)->len;
567567
}
568568
*/
569569

570570
#if MICROPY_PY_BUILTINS_BYTEARRAY
571-
mp_obj_t mp_obj_new_bytearray(mp_uint_t n, void *items) {
571+
mp_obj_t mp_obj_new_bytearray(size_t n, void *items) {
572572
mp_obj_array_t *o = array_new(BYTEARRAY_TYPECODE, n);
573573
memcpy(o->items, items, n);
574574
return MP_OBJ_FROM_PTR(o);
575575
}
576576

577577
// Create bytearray which references specified memory area
578-
mp_obj_t mp_obj_new_bytearray_by_ref(mp_uint_t n, void *items) {
578+
mp_obj_t mp_obj_new_bytearray_by_ref(size_t n, void *items) {
579579
mp_obj_array_t *o = m_new_obj(mp_obj_array_t);
580580
o->base.type = &mp_type_bytearray;
581581
o->typecode = BYTEARRAY_TYPECODE;
@@ -592,8 +592,8 @@ mp_obj_t mp_obj_new_bytearray_by_ref(mp_uint_t n, void *items) {
592592
typedef struct _mp_obj_array_it_t {
593593
mp_obj_base_t base;
594594
mp_obj_array_t *array;
595-
mp_uint_t offset;
596-
mp_uint_t cur;
595+
size_t offset;
596+
size_t cur;
597597
} mp_obj_array_it_t;
598598

599599
STATIC mp_obj_t array_it_iternext(mp_obj_t self_in) {

py/objarray.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,11 @@
3232

3333
typedef struct _mp_obj_array_t {
3434
mp_obj_base_t base;
35-
mp_uint_t typecode : 8;
35+
size_t typecode : 8;
3636
// free is number of unused elements after len used elements
3737
// alloc size = len + free
38-
mp_uint_t free : (8 * sizeof(mp_uint_t) - 8);
39-
mp_uint_t len; // in elements
38+
size_t free : (8 * sizeof(size_t) - 8);
39+
size_t len; // in elements
4040
void *items;
4141
} mp_obj_array_t;
4242

0 commit comments

Comments
 (0)