Skip to content

Commit 42f3de9

Browse files
committed
py: Convert [u]int to mp_[u]int_t where appropriate.
Addressing issue adafruit#50.
1 parent 877dba3 commit 42f3de9

25 files changed

+58
-80
lines changed

py/bc.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -75,9 +75,9 @@ STATIC NORETURN void fun_pos_args_mismatch(mp_obj_fun_bc_t *f, mp_uint_t expecte
7575
}
7676

7777
#if DEBUG_PRINT
78-
STATIC void dump_args(const mp_obj_t *a, int sz) {
78+
STATIC void dump_args(const mp_obj_t *a, mp_uint_t sz) {
7979
DEBUG_printf("%p: ", a);
80-
for (int i = 0; i < sz; i++) {
80+
for (mp_uint_t i = 0; i < sz; i++) {
8181
DEBUG_printf("%p ", a[i]);
8282
}
8383
DEBUG_printf("\n");
@@ -179,7 +179,7 @@ continue2:;
179179
// fill in defaults for positional args
180180
mp_obj_t *d = &code_state->state[n_state - self->n_pos_args];
181181
mp_obj_t *s = &self->extra_args[self->n_def_args - 1];
182-
for (int i = self->n_def_args; i > 0; i--, d++, s--) {
182+
for (mp_uint_t i = self->n_def_args; i > 0; i--, d++, s--) {
183183
if (*d == MP_OBJ_NULL) {
184184
*d = *s;
185185
}

py/bc.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,8 +53,8 @@ mp_uint_t mp_decode_uint(const byte **ptr);
5353

5454
mp_vm_return_kind_t mp_execute_bytecode(mp_code_state *code_state, volatile mp_obj_t inject_exc);
5555
void mp_setup_code_state(mp_code_state *code_state, mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const mp_obj_t *args);
56-
void mp_bytecode_print(const void *descr, const byte *code, int len);
57-
void mp_bytecode_print2(const byte *code, int len);
56+
void mp_bytecode_print(const void *descr, const byte *code, mp_uint_t len);
57+
void mp_bytecode_print2(const byte *code, mp_uint_t len);
5858

5959
// Helper macros to access pointer with least significant bit holding a flag
6060
#define MP_TAGPTR_PTR(x) ((void*)((mp_uint_t)(x) & ~((mp_uint_t)1)))

py/binary.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ int mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign) {
9999
return size;
100100
}
101101

102-
mp_obj_t mp_binary_get_val_array(char typecode, void *p, int index) {
102+
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index) {
103103
mp_int_t val = 0;
104104
switch (typecode) {
105105
case 'b':
@@ -250,7 +250,7 @@ void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **
250250
mp_binary_set_int(MIN(size, sizeof(val)), struct_type == '>', p, in);
251251
}
252252

253-
void mp_binary_set_val_array(char typecode, void *p, int index, mp_obj_t val_in) {
253+
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in) {
254254
switch (typecode) {
255255
#if MICROPY_PY_BUILTINS_FLOAT
256256
case 'f':
@@ -265,7 +265,7 @@ void mp_binary_set_val_array(char typecode, void *p, int index, mp_obj_t val_in)
265265
}
266266
}
267267

268-
void mp_binary_set_val_array_from_int(char typecode, void *p, int index, mp_int_t val) {
268+
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val) {
269269
switch (typecode) {
270270
case 'b':
271271
((int8_t*)p)[index] = val;

py/binary.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@
2929
#define BYTEARRAY_TYPECODE 0
3030

3131
int mp_binary_get_size(char struct_type, char val_type, mp_uint_t *palign);
32-
mp_obj_t mp_binary_get_val_array(char typecode, void *p, int index);
33-
void mp_binary_set_val_array(char typecode, void *p, int index, mp_obj_t val_in);
34-
void mp_binary_set_val_array_from_int(char typecode, void *p, int index, mp_int_t val);
32+
mp_obj_t mp_binary_get_val_array(char typecode, void *p, mp_uint_t index);
33+
void mp_binary_set_val_array(char typecode, void *p, mp_uint_t index, mp_obj_t val_in);
34+
void mp_binary_set_val_array_from_int(char typecode, void *p, mp_uint_t index, mp_int_t val);
3535
mp_obj_t mp_binary_get_val(char struct_type, char val_type, byte **ptr);
3636
void mp_binary_set_val(char struct_type, char val_type, mp_obj_t val_in, byte **ptr);
3737
long long mp_binary_get_int(mp_uint_t size, bool is_signed, bool big_endian, byte *p);

py/builtin.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -415,9 +415,9 @@ STATIC mp_obj_t mp_builtin_print(mp_uint_t n_args, const mp_obj_t *args, mp_map_
415415

416416
pfenv_t pfenv;
417417
pfenv.data = stream_obj;
418-
pfenv.print_strn = (void (*)(void *, const char *, unsigned int))mp_stream_write;
418+
pfenv.print_strn = (void (*)(void *, const char *, mp_uint_t))mp_stream_write;
419419
#endif
420-
for (int i = 0; i < n_args; i++) {
420+
for (mp_uint_t i = 0; i < n_args; i++) {
421421
if (i > 0) {
422422
#if MICROPY_PY_IO
423423
mp_stream_write(stream_obj, sep_data, sep_len);

py/builtinimport.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ STATIC mp_import_stat_t find_file(const char *file_str, uint file_len, vstr_t *d
8282
return stat_dir_or_file(dest);
8383
} else {
8484
// go through each path looking for a directory or file
85-
for (int i = 0; i < path_num; i++) {
85+
for (mp_uint_t i = 0; i < path_num; i++) {
8686
vstr_reset(dest);
8787
mp_uint_t p_len;
8888
const char *p = mp_obj_str_get_data(path_items[i], &p_len);
@@ -167,7 +167,7 @@ STATIC void do_load(mp_obj_t module_obj, vstr_t *file) {
167167
mp_obj_t mp_builtin___import__(mp_uint_t n_args, mp_obj_t *args) {
168168
#if DEBUG_PRINT
169169
DEBUG_printf("__import__:\n");
170-
for (int i = 0; i < n_args; i++) {
170+
for (mp_uint_t i = 0; i < n_args; i++) {
171171
DEBUG_printf(" ");
172172
mp_obj_print(args[i], PRINT_REPR);
173173
DEBUG_printf("\n");
@@ -176,7 +176,7 @@ mp_obj_t mp_builtin___import__(mp_uint_t n_args, mp_obj_t *args) {
176176

177177
mp_obj_t module_name = args[0];
178178
mp_obj_t fromtuple = mp_const_none;
179-
int level = 0;
179+
mp_int_t level = 0;
180180
if (n_args >= 4) {
181181
fromtuple = args[3];
182182
if (n_args >= 5) {

py/compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -493,7 +493,7 @@ STATIC void cpython_c_tuple_emit_const(compiler_t *comp, mp_parse_node_t pn, vst
493493
return;
494494
}
495495

496-
int arg = MP_PARSE_NODE_LEAF_ARG(pn);
496+
mp_uint_t arg = MP_PARSE_NODE_LEAF_ARG(pn);
497497
switch (MP_PARSE_NODE_LEAF_KIND(pn)) {
498498
case MP_PARSE_NODE_ID: assert(0);
499499
case MP_PARSE_NODE_INTEGER: vstr_printf(vstr, "%s", qstr_str(arg)); break;
@@ -853,7 +853,7 @@ STATIC void c_assign(compiler_t *comp, mp_parse_node_t pn, assign_kind_t assign_
853853
assert(0);
854854
} else if (MP_PARSE_NODE_IS_LEAF(pn)) {
855855
if (MP_PARSE_NODE_IS_ID(pn)) {
856-
int arg = MP_PARSE_NODE_LEAF_ARG(pn);
856+
qstr arg = MP_PARSE_NODE_LEAF_ARG(pn);
857857
switch (assign_kind) {
858858
case ASSIGN_STORE:
859859
case ASSIGN_AUG_STORE:

py/modstruct.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ STATIC mp_obj_t struct_pack(uint n_args, mp_obj_t *args) {
164164
// TODO: "The arguments must match the values required by the format exactly."
165165
const char *fmt = mp_obj_str_get_str(args[0]);
166166
char fmt_type = get_fmt_type(&fmt);
167-
int size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
167+
mp_int_t size = MP_OBJ_SMALL_INT_VALUE(struct_calcsize(args[0]));
168168
byte *p;
169169
mp_obj_t res = mp_obj_str_builder_start(&mp_type_bytes, size, &p);
170170
memset(p, 0, size);

py/mpz.c

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@
5858
returns sign(i - j)
5959
assumes i, j are normalised
6060
*/
61-
STATIC mp_int_t mpn_cmp(const mpz_dig_t *idig, mp_uint_t ilen, const mpz_dig_t *jdig, mp_uint_t jlen) {
61+
STATIC int mpn_cmp(const mpz_dig_t *idig, mp_uint_t ilen, const mpz_dig_t *jdig, mp_uint_t jlen) {
6262
if (ilen < jlen) { return -1; }
6363
if (ilen > jlen) { return 1; }
6464

@@ -361,7 +361,7 @@ STATIC void mpn_div(mpz_dig_t *num_dig, mp_uint_t *num_len, mpz_dig_t *den_dig,
361361

362362
// handle simple cases
363363
{
364-
mp_int_t cmp = mpn_cmp(num_dig, *num_len, den_dig, den_len);
364+
int cmp = mpn_cmp(num_dig, *num_len, den_dig, den_len);
365365
if (cmp == 0) {
366366
*num_len = 0;
367367
quo_dig[0] = 1;
@@ -744,8 +744,8 @@ bool mpz_is_even(const mpz_t *z) {
744744
return z->len == 0 || (z->dig[0] & 1) == 0;
745745
}
746746

747-
mp_int_t mpz_cmp(const mpz_t *z1, const mpz_t *z2) {
748-
mp_int_t cmp = z2->neg - z1->neg;
747+
int mpz_cmp(const mpz_t *z1, const mpz_t *z2) {
748+
int cmp = (int)z2->neg - (int)z1->neg;
749749
if (cmp != 0) {
750750
return cmp;
751751
}

py/mpz.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ bool mpz_is_neg(const mpz_t *z);
8888
bool mpz_is_odd(const mpz_t *z);
8989
bool mpz_is_even(const mpz_t *z);
9090

91-
mp_int_t mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);
91+
int mpz_cmp(const mpz_t *lhs, const mpz_t *rhs);
9292

9393
mpz_t *mpz_abs(const mpz_t *z);
9494
mpz_t *mpz_neg(const mpz_t *z);

0 commit comments

Comments
 (0)