Skip to content

Commit 39dc145

Browse files
committed
py: Change [u]int to mp_[u]int_t in qstr.[ch], and some other places.
This should pretty much resolve issue micropython#50.
1 parent 3eaa0c3 commit 39dc145

File tree

12 files changed

+44
-69
lines changed

12 files changed

+44
-69
lines changed

py/bc.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ typedef struct _mp_code_state {
4242
mp_obj_t *sp;
4343
// bit 0 is saved currently_in_except_block value
4444
mp_exc_stack_t *exc_sp;
45-
uint n_state;
45+
mp_uint_t n_state;
4646
// Variable-length
4747
mp_obj_t state[0];
4848
// Variable-length, never accessed by name, only as (void*)(state + n_state)

py/compile.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1459,7 +1459,7 @@ STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) {
14591459
if (i > 0) {
14601460
*str_dest++ = '.';
14611461
}
1462-
uint str_src_len;
1462+
mp_uint_t str_src_len;
14631463
const byte *str_src = qstr_data(MP_PARSE_NODE_LEAF_ARG(pns->nodes[i]), &str_src_len);
14641464
memcpy(str_dest, str_src, str_src_len);
14651465
str_dest += str_src_len;
@@ -2563,7 +2563,7 @@ void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) {
25632563
byte *s_dest = qstr_build_start(n_bytes, &q_ptr);
25642564
for (int i = 0; i < n; i++) {
25652565
if (MP_PARSE_NODE_IS_LEAF(pns->nodes[i])) {
2566-
uint s_len;
2566+
mp_uint_t s_len;
25672567
const byte *s = qstr_data(MP_PARSE_NODE_LEAF_ARG(pns->nodes[i]), &s_len);
25682568
memcpy(s_dest, s, s_len);
25692569
s_dest += s_len;

py/emitnative.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1075,7 +1075,7 @@ STATIC void emit_native_import_star(emit_t *emit) {
10751075
STATIC void emit_native_load_const_tok(emit_t *emit, mp_token_kind_t tok) {
10761076
DEBUG_printf("load_const_tok(tok=%u)\n", tok);
10771077
emit_native_pre(emit);
1078-
int vtype;
1078+
vtype_kind_t vtype;
10791079
mp_uint_t val;
10801080
if (emit->do_viper_types) {
10811081
switch (tok) {

py/objboundmeth.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@ mp_obj_t bound_meth_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, con
5555

5656
// need to insert self->self before all other args and then call self->meth
5757

58-
int n_total = n_args + 2 * n_kw;
58+
mp_uint_t n_total = n_args + 2 * n_kw;
5959
if (n_total <= 4) {
6060
// use stack to allocate temporary args array
6161
mp_obj_t args2[5];

py/objclosure.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const
4646

4747
// need to concatenate closed-over-vars and args
4848

49-
int n_total = self->n_closed + n_args + 2 * n_kw;
49+
mp_uint_t n_total = self->n_closed + n_args + 2 * n_kw;
5050
if (n_total <= 5) {
5151
// use stack to allocate temporary args array
5252
mp_obj_t args2[5];
@@ -68,7 +68,7 @@ mp_obj_t closure_call(mp_obj_t self_in, mp_uint_t n_args, mp_uint_t n_kw, const
6868
STATIC void closure_print(void (*print)(void *env, const char *fmt, ...), void *env, mp_obj_t o_in, mp_print_kind_t kind) {
6969
mp_obj_closure_t *o = o_in;
7070
print(env, "<closure %s at %p, n_closed=%u ", mp_obj_fun_get_name(o->fun), o, o->n_closed);
71-
for (int i = 0; i < o->n_closed; i++) {
71+
for (mp_uint_t i = 0; i < o->n_closed; i++) {
7272
if (o->closed[i] == MP_OBJ_NULL) {
7373
print(env, "(nil)");
7474
} else {

py/objfun.c

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -116,29 +116,6 @@ const mp_obj_type_t mp_type_fun_builtin = {
116116
.binary_op = mp_obj_fun_binary_op,
117117
};
118118

119-
#if 0 // currently unused, and semi-obsolete
120-
mp_obj_t mp_make_function_var(int n_args_min, mp_fun_var_t fun) {
121-
mp_obj_fun_builtin_t *o = m_new_obj(mp_obj_fun_builtin_t);
122-
o->base.type = &mp_type_fun_native;
123-
o->is_kw = false;
124-
o->n_args_min = n_args_min;
125-
o->n_args_max = MP_OBJ_FUN_ARGS_MAX;
126-
o->fun = fun;
127-
return o;
128-
}
129-
130-
// min and max are inclusive
131-
mp_obj_t mp_make_function_var_between(int n_args_min, int n_args_max, mp_fun_var_t fun) {
132-
mp_obj_fun_builtin_t *o = m_new_obj(mp_obj_fun_builtin_t);
133-
o->base.type = &mp_type_fun_native;
134-
o->is_kw = false;
135-
o->n_args_min = n_args_min;
136-
o->n_args_max = n_args_max;
137-
o->fun = fun;
138-
return o;
139-
}
140-
#endif
141-
142119
/******************************************************************************/
143120
/* byte code functions */
144121

@@ -161,9 +138,9 @@ STATIC void fun_bc_print(void (*print)(void *env, const char *fmt, ...), void *e
161138
#endif
162139

163140
#if DEBUG_PRINT
164-
STATIC void dump_args(const mp_obj_t *a, int sz) {
141+
STATIC void dump_args(const mp_obj_t *a, mp_uint_t sz) {
165142
DEBUG_printf("%p: ", a);
166-
for (int i = 0; i < sz; i++) {
143+
for (mp_uint_t i = 0; i < sz; i++) {
167144
DEBUG_printf("%p ", a[i]);
168145
}
169146
DEBUG_printf("\n");

py/objstr.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -213,7 +213,7 @@ STATIC mp_obj_t bytes_make_new(mp_obj_t type_in, mp_uint_t n_args, mp_uint_t n_k
213213
return mp_obj_str_builder_end(o);
214214
}
215215

216-
int len;
216+
mp_int_t len;
217217
byte *data;
218218
vstr_t *vstr = NULL;
219219
mp_obj_t o = NULL;
@@ -293,7 +293,7 @@ mp_obj_t mp_obj_str_binary_op(mp_uint_t op, mp_obj_t lhs_in, mp_obj_t rhs_in) {
293293
// add 2 strings or bytes
294294

295295
GET_STR_DATA_LEN(rhs_in, rhs_data, rhs_len);
296-
int alloc_len = lhs_len + rhs_len;
296+
mp_uint_t alloc_len = lhs_len + rhs_len;
297297

298298
/* code for making qstr
299299
byte *q_ptr;
@@ -440,8 +440,8 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
440440
}
441441

442442
// count required length
443-
int required_len = 0;
444-
for (int i = 0; i < seq_len; i++) {
443+
mp_uint_t required_len = 0;
444+
for (mp_uint_t i = 0; i < seq_len; i++) {
445445
if (mp_obj_get_type(seq_items[i]) != self_type) {
446446
nlr_raise(mp_obj_new_exception_msg(&mp_type_TypeError,
447447
"join expects a list of str/bytes objects consistent with self object"));
@@ -456,7 +456,7 @@ STATIC mp_obj_t str_join(mp_obj_t self_in, mp_obj_t arg) {
456456
// make joined string
457457
byte *data;
458458
mp_obj_t joined_str = mp_obj_str_builder_start(self_type, required_len, &data);
459-
for (int i = 0; i < seq_len; i++) {
459+
for (mp_uint_t i = 0; i < seq_len; i++) {
460460
if (i > 0) {
461461
memcpy(data, sep_str, sep_len);
462462
data += sep_len;
@@ -562,7 +562,7 @@ STATIC mp_obj_t str_rsplit(mp_uint_t n_args, const mp_obj_t *args) {
562562
// Preallocate list to the max expected # of elements, as we
563563
// will fill it from the end.
564564
mp_obj_list_t *res = mp_obj_new_list(splits + 1, NULL);
565-
int idx = splits;
565+
mp_int_t idx = splits;
566566

567567
if (sep == mp_const_none) {
568568
assert(!"TODO: rsplit(None,n) not implemented");
@@ -598,7 +598,7 @@ STATIC mp_obj_t str_rsplit(mp_uint_t n_args, const mp_obj_t *args) {
598598
}
599599
if (idx != 0) {
600600
// We split less parts than split limit, now go cleanup surplus
601-
int used = org_splits + 1 - idx;
601+
mp_int_t used = org_splits + 1 - idx;
602602
memmove(res->items, &res->items[idx], used * sizeof(mp_obj_t));
603603
mp_seq_clear(res->items, used, res->alloc, sizeof(*res->items));
604604
res->len = used;
@@ -1554,7 +1554,7 @@ STATIC mp_obj_t str_caseconv(unichar (*op)(unichar), mp_obj_t self_in) {
15541554
GET_STR_DATA_LEN(self_in, self_data, self_len);
15551555
byte *data;
15561556
mp_obj_t s = mp_obj_str_builder_start(mp_obj_get_type(self_in), self_len, &data);
1557-
for (int i = 0; i < self_len; i++) {
1557+
for (mp_uint_t i = 0; i < self_len; i++) {
15581558
*data++ = op(*self_data++);
15591559
}
15601560
*data = 0;
@@ -1577,15 +1577,15 @@ STATIC mp_obj_t str_uni_istype(bool (*f)(unichar), mp_obj_t self_in) {
15771577
}
15781578

15791579
if (f != unichar_isupper && f != unichar_islower) {
1580-
for (int i = 0; i < self_len; i++) {
1580+
for (mp_uint_t i = 0; i < self_len; i++) {
15811581
if (!f(*self_data++)) {
15821582
return mp_const_false;
15831583
}
15841584
}
15851585
} else {
15861586
bool contains_alpha = false;
15871587

1588-
for (int i = 0; i < self_len; i++) { // only check alphanumeric characters
1588+
for (mp_uint_t i = 0; i < self_len; i++) { // only check alphanumeric characters
15891589
if (unichar_isalpha(*self_data++)) {
15901590
contains_alpha = true;
15911591
if (!f(*(self_data - 1))) { // -1 because we already incremented above

py/objstr.h

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -36,17 +36,17 @@ typedef struct _mp_obj_str_t {
3636

3737
// use this macro to extract the string hash
3838
#define GET_STR_HASH(str_obj_in, str_hash) \
39-
uint str_hash; if (MP_OBJ_IS_QSTR(str_obj_in)) \
39+
mp_uint_t str_hash; if (MP_OBJ_IS_QSTR(str_obj_in)) \
4040
{ str_hash = qstr_hash(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_hash = ((mp_obj_str_t*)str_obj_in)->hash; }
4141

4242
// use this macro to extract the string length
4343
#define GET_STR_LEN(str_obj_in, str_len) \
44-
uint str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
44+
mp_uint_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
4545
{ str_len = qstr_len(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_len = ((mp_obj_str_t*)str_obj_in)->len; }
4646

4747
// use this macro to extract the string data and length
4848
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \
49-
const byte *str_data; uint str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
49+
const byte *str_data; mp_uint_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
5050
{ str_data = qstr_data(MP_OBJ_QSTR_VALUE(str_obj_in), &str_len); } \
5151
else { str_len = ((mp_obj_str_t*)str_obj_in)->len; str_data = ((mp_obj_str_t*)str_obj_in)->data; }
5252

py/qstr.c

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -55,7 +55,7 @@
5555
#define Q_GET_DATA(q) ((q) + 4)
5656

5757
// this must match the equivalent function in makeqstrdata.py
58-
mp_uint_t qstr_compute_hash(const byte *data, uint len) {
58+
mp_uint_t qstr_compute_hash(const byte *data, mp_uint_t len) {
5959
// djb2 algorithm; see http://www.cse.yorku.ca/~oz/hash.html
6060
mp_uint_t hash = 5381;
6161
for (const byte *top = data + len; data < top; data++) {
@@ -71,9 +71,9 @@ mp_uint_t qstr_compute_hash(const byte *data, uint len) {
7171

7272
typedef struct _qstr_pool_t {
7373
struct _qstr_pool_t *prev;
74-
uint total_prev_len;
75-
uint alloc;
76-
uint len;
74+
mp_uint_t total_prev_len;
75+
mp_uint_t alloc;
76+
mp_uint_t len;
7777
const byte *qstrs[];
7878
} qstr_pool_t;
7979

@@ -130,7 +130,7 @@ STATIC qstr qstr_add(const byte *q_ptr) {
130130
return last_pool->total_prev_len + last_pool->len - 1;
131131
}
132132

133-
qstr qstr_find_strn(const char *str, uint str_len) {
133+
qstr qstr_find_strn(const char *str, mp_uint_t str_len) {
134134
// work out hash of str
135135
mp_uint_t str_hash = qstr_compute_hash((const byte*)str, str_len);
136136

@@ -151,7 +151,7 @@ qstr qstr_from_str(const char *str) {
151151
return qstr_from_strn(str, strlen(str));
152152
}
153153

154-
qstr qstr_from_strn(const char *str, uint len) {
154+
qstr qstr_from_strn(const char *str, mp_uint_t len) {
155155
qstr q = qstr_find_strn(str, len);
156156
if (q == 0) {
157157
mp_uint_t hash = qstr_compute_hash((const byte*)str, len);
@@ -167,7 +167,7 @@ qstr qstr_from_strn(const char *str, uint len) {
167167
return q;
168168
}
169169

170-
byte *qstr_build_start(uint len, byte **q_ptr) {
170+
byte *qstr_build_start(mp_uint_t len, byte **q_ptr) {
171171
assert(len <= 65535);
172172
*q_ptr = m_new(byte, 4 + len + 1);
173173
(*q_ptr)[2] = len;
@@ -194,7 +194,7 @@ mp_uint_t qstr_hash(qstr q) {
194194
return Q_GET_HASH(find_qstr(q));
195195
}
196196

197-
uint qstr_len(qstr q) {
197+
mp_uint_t qstr_len(qstr q) {
198198
const byte *qd = find_qstr(q);
199199
return Q_GET_LENGTH(qd);
200200
}
@@ -205,13 +205,13 @@ const char *qstr_str(qstr q) {
205205
return (const char*)Q_GET_DATA(qd);
206206
}
207207

208-
const byte *qstr_data(qstr q, uint *len) {
208+
const byte *qstr_data(qstr q, mp_uint_t *len) {
209209
const byte *qd = find_qstr(q);
210210
*len = Q_GET_LENGTH(qd);
211211
return Q_GET_DATA(qd);
212212
}
213213

214-
void qstr_pool_info(uint *n_pool, uint *n_qstr, uint *n_str_data_bytes, uint *n_total_bytes) {
214+
void qstr_pool_info(mp_uint_t *n_pool, mp_uint_t *n_qstr, mp_uint_t *n_str_data_bytes, mp_uint_t *n_total_bytes) {
215215
*n_pool = 0;
216216
*n_qstr = 0;
217217
*n_str_data_bytes = 0;

py/qstr.h

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -45,20 +45,18 @@ typedef mp_uint_t qstr;
4545

4646
void qstr_init(void);
4747

48-
mp_uint_t qstr_compute_hash(const byte *data, uint len);
49-
qstr qstr_find_strn(const char *str, uint str_len); // returns MP_QSTR_NULL if not found
48+
mp_uint_t qstr_compute_hash(const byte *data, mp_uint_t len);
49+
qstr qstr_find_strn(const char *str, mp_uint_t str_len); // returns MP_QSTR_NULL if not found
5050

5151
qstr qstr_from_str(const char *str);
52-
qstr qstr_from_strn(const char *str, uint len);
53-
//qstr qstr_from_str_static(const char *str);
54-
//qstr qstr_from_strn_copy(const char *str, int len);
52+
qstr qstr_from_strn(const char *str, mp_uint_t len);
5553

56-
byte* qstr_build_start(uint len, byte **q_ptr);
54+
byte* qstr_build_start(mp_uint_t len, byte **q_ptr);
5755
qstr qstr_build_end(byte *q_ptr);
5856

5957
mp_uint_t qstr_hash(qstr q);
6058
const char* qstr_str(qstr q);
61-
uint qstr_len(qstr q);
62-
const byte* qstr_data(qstr q, uint *len);
59+
mp_uint_t qstr_len(qstr q);
60+
const byte* qstr_data(qstr q, mp_uint_t *len);
6361

64-
void qstr_pool_info(uint *n_pool, uint *n_qstr, uint *n_str_data_bytes, uint *n_total_bytes);
62+
void qstr_pool_info(mp_uint_t *n_pool, mp_uint_t *n_qstr, mp_uint_t *n_str_data_bytes, mp_uint_t *n_total_bytes);

0 commit comments

Comments
 (0)