From c3f64d9799cdf8af88087eebe6628e83d658405c Mon Sep 17 00:00:00 2001 From: Damien George Date: Fri, 27 Nov 2015 12:23:18 +0000 Subject: [PATCH] py: Change qstr_* functions to use size_t as the type for str len arg. --- cc3200/bootmgr/main.c | 2 +- py/compile.c | 6 +++--- py/emitglue.c | 2 +- py/emitinlinethumb.c | 2 +- py/mpprint.c | 2 +- py/objstr.c | 2 +- py/objstr.h | 8 ++++---- py/qstr.c | 14 +++++++------- py/qstr.h | 12 ++++++------ 9 files changed, 25 insertions(+), 25 deletions(-) diff --git a/cc3200/bootmgr/main.c b/cc3200/bootmgr/main.c index d5b37c3131..97c8b36af4 100644 --- a/cc3200/bootmgr/main.c +++ b/cc3200/bootmgr/main.c @@ -414,7 +414,7 @@ int main (void) { //***************************************************************************** #include "py/qstr.h" -const byte *qstr_data(qstr q, mp_uint_t *len) { +const byte *qstr_data(qstr q, size_t *len) { *len = 0; return NULL; } diff --git a/py/compile.c b/py/compile.c index 4fcd64f291..6fffd9c0bf 100644 --- a/py/compile.c +++ b/py/compile.c @@ -1025,7 +1025,7 @@ STATIC void do_import_name(compiler_t *comp, mp_parse_node_t pn, qstr *q_base) { if (i > 0) { *str_dest++ = '.'; } - mp_uint_t str_src_len; + size_t str_src_len; const byte *str_src = qstr_data(MP_PARSE_NODE_LEAF_ARG(pns->nodes[i]), &str_src_len); memcpy(str_dest, str_src, str_src_len); str_dest += str_src_len; @@ -2115,7 +2115,7 @@ STATIC void compile_atom_string(compiler_t *comp, mp_parse_node_struct_t *pns) { byte *s_dest = (byte*)vstr.buf; for (int i = 0; i < n; i++) { if (MP_PARSE_NODE_IS_LEAF(pns->nodes[i])) { - mp_uint_t s_len; + size_t s_len; const byte *s = qstr_data(MP_PARSE_NODE_LEAF_ARG(pns->nodes[i]), &s_len); memcpy(s_dest, s, s_len); s_dest += s_len; @@ -2473,7 +2473,7 @@ STATIC void compile_node(compiler_t *comp, mp_parse_node_t pn) { if (comp->pass != MP_PASS_EMIT) { EMIT_ARG(load_const_obj, mp_const_none); } else { - mp_uint_t len; + size_t len; const byte *data = qstr_data(arg, &len); EMIT_ARG(load_const_obj, mp_obj_new_bytes(data, len)); } diff --git a/py/emitglue.c b/py/emitglue.c index 4eb9b76aa4..26fe3dec91 100644 --- a/py/emitglue.c +++ b/py/emitglue.c @@ -492,7 +492,7 @@ STATIC void mp_print_uint(mp_print_t *print, mp_uint_t n) { } STATIC void save_qstr(mp_print_t *print, qstr qst) { - mp_uint_t len; + size_t len; const byte *str = qstr_data(qst, &len); mp_print_uint(print, len); mp_print_bytes(print, str, len); diff --git a/py/emitinlinethumb.c b/py/emitinlinethumb.c index 949ef7a133..847210006f 100644 --- a/py/emitinlinethumb.c +++ b/py/emitinlinethumb.c @@ -406,7 +406,7 @@ STATIC void emit_inline_thumb_op(emit_inline_asm_t *emit, qstr op, mp_uint_t n_a // three_args = // "subs", RLO, RLO, I3, asm_thumb_subs_reg_reg_i3 - mp_uint_t op_len; + size_t op_len; const char *op_str = (const char*)qstr_data(op, &op_len); #if MICROPY_EMIT_INLINE_THUMB_FLOAT diff --git a/py/mpprint.c b/py/mpprint.c index 6b1f8b9134..54b0e47d15 100644 --- a/py/mpprint.c +++ b/py/mpprint.c @@ -472,7 +472,7 @@ int mp_vprintf(const mp_print_t *print, const char *fmt, va_list args) { case 'q': { qstr qst = va_arg(args, qstr); - mp_uint_t len; + size_t len; const char *str = (const char*)qstr_data(qst, &len); if (prec < 0) { prec = len; diff --git a/py/objstr.c b/py/objstr.c index 94a63c231b..d1c56b022c 100644 --- a/py/objstr.c +++ b/py/objstr.c @@ -2039,7 +2039,7 @@ const char *mp_obj_str_get_data(mp_obj_t self_in, mp_uint_t *len) { } #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C -const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, mp_uint_t *len) { +const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len) { if (MP_OBJ_IS_QSTR(self_in)) { return qstr_data(MP_OBJ_QSTR_VALUE(self_in), len); } else { diff --git a/py/objstr.h b/py/objstr.h index ec89400714..2c2bdbaee3 100644 --- a/py/objstr.h +++ b/py/objstr.h @@ -45,17 +45,17 @@ typedef struct _mp_obj_str_t { // use this macro to extract the string length #define GET_STR_LEN(str_obj_in, str_len) \ - mp_uint_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \ + size_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \ { str_len = qstr_len(MP_OBJ_QSTR_VALUE(str_obj_in)); } else { str_len = ((mp_obj_str_t*)str_obj_in)->len; } // use this macro to extract the string data and length #if MICROPY_OBJ_REPR == MICROPY_OBJ_REPR_C -const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, mp_uint_t *len); +const byte *mp_obj_str_get_data_no_check(mp_obj_t self_in, size_t *len); #define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \ - mp_uint_t str_len; const byte *str_data = mp_obj_str_get_data_no_check(str_obj_in, &str_len); + size_t str_len; const byte *str_data = mp_obj_str_get_data_no_check(str_obj_in, &str_len); #else #define GET_STR_DATA_LEN(str_obj_in, str_data, str_len) \ - const byte *str_data; mp_uint_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \ + const byte *str_data; size_t str_len; if (MP_OBJ_IS_QSTR(str_obj_in)) \ { str_data = qstr_data(MP_OBJ_QSTR_VALUE(str_obj_in), &str_len); } \ else { str_len = ((mp_obj_str_t*)str_obj_in)->len; str_data = ((mp_obj_str_t*)str_obj_in)->data; } #endif diff --git a/py/qstr.c b/py/qstr.c index 43f5ab5b23..090be64ad1 100644 --- a/py/qstr.c +++ b/py/qstr.c @@ -73,7 +73,7 @@ #endif // this must match the equivalent function in makeqstrdata.py -mp_uint_t qstr_compute_hash(const byte *data, mp_uint_t len) { +mp_uint_t qstr_compute_hash(const byte *data, size_t len) { // djb2 algorithm; see http://www.cse.yorku.ca/~oz/hash.html mp_uint_t hash = 5381; for (const byte *top = data + len; data < top; data++) { @@ -137,7 +137,7 @@ STATIC qstr qstr_add(const byte *q_ptr) { return MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len - 1; } -qstr qstr_find_strn(const char *str, mp_uint_t str_len) { +qstr qstr_find_strn(const char *str, size_t str_len) { // work out hash of str mp_uint_t str_hash = qstr_compute_hash((const byte*)str, str_len); @@ -158,7 +158,7 @@ qstr qstr_from_str(const char *str) { return qstr_from_strn(str, strlen(str)); } -qstr qstr_from_strn(const char *str, mp_uint_t len) { +qstr qstr_from_strn(const char *str, size_t len) { assert(len < (1 << (8 * MICROPY_QSTR_BYTES_IN_LEN))); qstr q = qstr_find_strn(str, len); if (q == 0) { @@ -182,7 +182,7 @@ qstr qstr_from_strn(const char *str, mp_uint_t len) { if (MP_STATE_VM(qstr_last_chunk) == NULL) { // no existing memory for the interned string so allocate a new chunk - mp_uint_t al = n_bytes; + size_t al = n_bytes; if (al < MICROPY_ALLOC_QSTR_CHUNK_INIT) { al = MICROPY_ALLOC_QSTR_CHUNK_INIT; } @@ -211,7 +211,7 @@ qstr qstr_from_strn(const char *str, mp_uint_t len) { return q; } -byte *qstr_build_start(mp_uint_t len, byte **q_ptr) { +byte *qstr_build_start(size_t len, byte **q_ptr) { assert(len < (1 << (8 * MICROPY_QSTR_BYTES_IN_LEN))); *q_ptr = m_new(byte, MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len + 1); Q_SET_LENGTH(*q_ptr, len); @@ -236,7 +236,7 @@ mp_uint_t qstr_hash(qstr q) { return Q_GET_HASH(find_qstr(q)); } -mp_uint_t qstr_len(qstr q) { +size_t qstr_len(qstr q) { const byte *qd = find_qstr(q); return Q_GET_LENGTH(qd); } @@ -247,7 +247,7 @@ const char *qstr_str(qstr q) { return (const char*)Q_GET_DATA(qd); } -const byte *qstr_data(qstr q, mp_uint_t *len) { +const byte *qstr_data(qstr q, size_t *len) { const byte *qd = find_qstr(q); *len = Q_GET_LENGTH(qd); return Q_GET_DATA(qd); diff --git a/py/qstr.h b/py/qstr.h index 04ef4c3bf3..333c60f80a 100644 --- a/py/qstr.h +++ b/py/qstr.h @@ -57,19 +57,19 @@ typedef struct _qstr_pool_t { void qstr_init(void); -mp_uint_t qstr_compute_hash(const byte *data, mp_uint_t len); -qstr qstr_find_strn(const char *str, mp_uint_t str_len); // returns MP_QSTR_NULL if not found +mp_uint_t qstr_compute_hash(const byte *data, size_t len); +qstr qstr_find_strn(const char *str, size_t str_len); // returns MP_QSTR_NULL if not found qstr qstr_from_str(const char *str); -qstr qstr_from_strn(const char *str, mp_uint_t len); +qstr qstr_from_strn(const char *str, size_t len); -byte *qstr_build_start(mp_uint_t len, byte **q_ptr); +byte *qstr_build_start(size_t len, byte **q_ptr); qstr qstr_build_end(byte *q_ptr); mp_uint_t qstr_hash(qstr q); const char *qstr_str(qstr q); -mp_uint_t qstr_len(qstr q); -const byte *qstr_data(qstr q, mp_uint_t *len); +size_t qstr_len(qstr q); +const byte *qstr_data(qstr q, size_t *len); 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); void qstr_dump_data(void);