Skip to content

Commit c3f64d9

Browse files
committed
py: Change qstr_* functions to use size_t as the type for str len arg.
1 parent 4e7107a commit c3f64d9

File tree

9 files changed

+25
-25
lines changed

9 files changed

+25
-25
lines changed

cc3200/bootmgr/main.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -414,7 +414,7 @@ int main (void) {
414414
//*****************************************************************************
415415
#include "py/qstr.h"
416416

417-
const byte *qstr_data(qstr q, mp_uint_t *len) {
417+
const byte *qstr_data(qstr q, size_t *len) {
418418
*len = 0;
419419
return NULL;
420420
}

py/compile.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1025,7 +1025,7 @@ STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) {
10251025
if (i > 0) {
10261026
*str_dest++ = '.';
10271027
}
1028-
mp_uint_t str_src_len;
1028+
size_t str_src_len;
10291029
const byte *str_src = qstr_data(MP_PARSE_NODE_LEAF_ARG(pns->nodes[i]), &str_src_len);
10301030
memcpy(str_dest, str_src, str_src_len);
10311031
str_dest += str_src_len;
@@ -2115,7 +2115,7 @@ STATIC void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) {
21152115
byte *s_dest = (byte*)vstr.buf;
21162116
for (int i = 0; i < n; i++) {
21172117
if (MP_PARSE_NODE_IS_LEAF(pns->nodes[i])) {
2118-
mp_uint_t s_len;
2118+
size_t s_len;
21192119
const byte *s = qstr_data(MP_PARSE_NODE_LEAF_ARG(pns->nodes[i]), &s_len);
21202120
memcpy(s_dest, s, s_len);
21212121
s_dest += s_len;
@@ -2473,7 +2473,7 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) {
24732473
if (comp->pass != MP_PASS_EMIT) {
24742474
EMIT_ARG(load_const_obj, mp_const_none);
24752475
} else {
2476-
mp_uint_t len;
2476+
size_t len;
24772477
const byte *data = qstr_data(arg, &len);
24782478
EMIT_ARG(load_const_obj, mp_obj_new_bytes(data, len));
24792479
}

py/emitglue.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -492,7 +492,7 @@ STATIC void mp_print_uint(mp_print_t *print, mp_uint_t n) {
492492
}
493493

494494
STATIC void save_qstr(mp_print_t *print, qstr qst) {
495-
mp_uint_t len;
495+
size_t len;
496496
const byte *str = qstr_data(qst, &len);
497497
mp_print_uint(print, len);
498498
mp_print_bytes(print, str, len);

py/emitinlinethumb.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -406,7 +406,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a
406406
// three_args =
407407
// "subs", RLO, RLO, I3, asm_thumb_subs_reg_reg_i3
408408

409-
mp_uint_t op_len;
409+
size_t op_len;
410410
const char *op_str = (const char*)qstr_data(op, &op_len);
411411

412412
#if MICROPY_EMIT_INLINE_THUMB_FLOAT

py/mpprint.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -472,7 +472,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) {
472472
case 'q':
473473
{
474474
qstr qst = va_arg(args, qstr);
475-
mp_uint_t len;
475+
size_t len;
476476
const char *str = (const char*)qstr_data(qst, &len);
477477
if (prec < 0) {
478478
prec = len;

py/objstr.c

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2039,7 +2039,7 @@ const char *mp_obj_str_get_data(mp_obj_t self_in, mp_uint_t *len) {
20392039
}
20402040

20412041
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
2042-
const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, mp_uint_t *len) {
2042+
const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len) {
20432043
if (MP_OBJ_IS_QSTR(self_in)) {
20442044
return qstr_data(MP_OBJ_QSTR_VALUE(self_in), len);
20452045
} else {

py/objstr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -45,17 +45,17 @@ typedef struct _mp_obj_str_t {
4545

4646
// use this macro to extract the string length
4747
#define GET_STR_LEN(str_obj_in, str_len) \
48-
mp_uint_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
48+
size_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
4949
{ str_len = qstr_len(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_len = ((mp_obj_str_t*)str_obj_in)->len; }
5050

5151
// use this macro to extract the string data and length
5252
#if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C
53-
const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, mp_uint_t *len);
53+
const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len);
5454
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \
55-
mp_uint_t str_len; const byte *str_data = mp_obj_str_get_data_no_check(str_obj_in, &str_len);
55+
size_t str_len; const byte *str_data = mp_obj_str_get_data_no_check(str_obj_in, &str_len);
5656
#else
5757
#define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \
58-
const byte *str_data; mp_uint_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
58+
const byte *str_data; size_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \
5959
{ str_data = qstr_data(MP_OBJ_QSTR_VALUE(str_obj_in), &str_len); } \
6060
else { str_len = ((mp_obj_str_t*)str_obj_in)->len; str_data = ((mp_obj_str_t*)str_obj_in)->data; }
6161
#endif

py/qstr.c

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
#endif
7474

7575
// this must match the equivalent function in makeqstrdata.py
76-
mp_uint_t qstr_compute_hash(const byte *data, mp_uint_t len) {
76+
mp_uint_t qstr_compute_hash(const byte *data, size_t len) {
7777
// djb2 algorithm; see http://www.cse.yorku.ca/~oz/hash.html
7878
mp_uint_t hash = 5381;
7979
for (const byte *top = data + len; data < top; data++) {
@@ -137,7 +137,7 @@ STATIC qstr qstr_add(const byte *q_ptr) {
137137
return MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len - 1;
138138
}
139139

140-
qstr qstr_find_strn(const char *str, mp_uint_t str_len) {
140+
qstr qstr_find_strn(const char *str, size_t str_len) {
141141
// work out hash of str
142142
mp_uint_t str_hash = qstr_compute_hash((const byte*)str, str_len);
143143

@@ -158,7 +158,7 @@ qstr qstr_from_str(const char *str) {
158158
return qstr_from_strn(str, strlen(str));
159159
}
160160

161-
qstr qstr_from_strn(const char *str, mp_uint_t len) {
161+
qstr qstr_from_strn(const char *str, size_t len) {
162162
assert(len < (1 << (8 * MICROPY_QSTR_BYTES_IN_LEN)));
163163
qstr q = qstr_find_strn(str, len);
164164
if (q == 0) {
@@ -182,7 +182,7 @@ qstr qstr_from_strn(const char *str, mp_uint_t len) {
182182

183183
if (MP_STATE_VM(qstr_last_chunk) == NULL) {
184184
// no existing memory for the interned string so allocate a new chunk
185-
mp_uint_t al = n_bytes;
185+
size_t al = n_bytes;
186186
if (al < MICROPY_ALLOC_QSTR_CHUNK_INIT) {
187187
al = MICROPY_ALLOC_QSTR_CHUNK_INIT;
188188
}
@@ -211,7 +211,7 @@ qstr qstr_from_strn(const char *str, mp_uint_t len) {
211211
return q;
212212
}
213213

214-
byte *qstr_build_start(mp_uint_t len, byte **q_ptr) {
214+
byte *qstr_build_start(size_t len, byte **q_ptr) {
215215
assert(len < (1 << (8 * MICROPY_QSTR_BYTES_IN_LEN)));
216216
*q_ptr = m_new(byte, MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len + 1);
217217
Q_SET_LENGTH(*q_ptr, len);
@@ -236,7 +236,7 @@ mp_uint_t qstr_hash(qstr q) {
236236
return Q_GET_HASH(find_qstr(q));
237237
}
238238

239-
mp_uint_t qstr_len(qstr q) {
239+
size_t qstr_len(qstr q) {
240240
const byte *qd = find_qstr(q);
241241
return Q_GET_LENGTH(qd);
242242
}
@@ -247,7 +247,7 @@ const char *qstr_str(qstr q) {
247247
return (const char*)Q_GET_DATA(qd);
248248
}
249249

250-
const byte *qstr_data(qstr q, mp_uint_t *len) {
250+
const byte *qstr_data(qstr q, size_t *len) {
251251
const byte *qd = find_qstr(q);
252252
*len = Q_GET_LENGTH(qd);
253253
return Q_GET_DATA(qd);

py/qstr.h

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -57,19 +57,19 @@ typedef struct _qstr_pool_t {
5757

5858
void qstr_init(void);
5959

60-
mp_uint_t qstr_compute_hash(const byte *data, mp_uint_t len);
61-
qstr qstr_find_strn(const char *str, mp_uint_t str_len); // returns MP_QSTR_NULL if not found
60+
mp_uint_t qstr_compute_hash(const byte *data, size_t len);
61+
qstr qstr_find_strn(const char *str, size_t str_len); // returns MP_QSTR_NULL if not found
6262

6363
qstr qstr_from_str(const char *str);
64-
qstr qstr_from_strn(const char *str, mp_uint_t len);
64+
qstr qstr_from_strn(const char *str, size_t len);
6565

66-
byte *qstr_build_start(mp_uint_t len, byte **q_ptr);
66+
byte *qstr_build_start(size_t len, byte **q_ptr);
6767
qstr qstr_build_end(byte *q_ptr);
6868

6969
mp_uint_t qstr_hash(qstr q);
7070
const char *qstr_str(qstr q);
71-
mp_uint_t qstr_len(qstr q);
72-
const byte *qstr_data(qstr q, mp_uint_t *len);
71+
size_t qstr_len(qstr q);
72+
const byte *qstr_data(qstr q, size_t *len);
7373

7474
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);
7575
void qstr_dump_data(void);

0 commit comments

Comments
 (0)