py: Change qstr_* functions to use size_t as the type for str len arg.

This commit is contained in:
Damien George 2015-11-27 12:23:18 +00:00
parent 4e7107a572
commit c3f64d9799
9 changed files with 25 additions and 25 deletions

View File

@ -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;
}

View File

@ -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));
}

View File

@ -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);

View File

@ -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

View File

@ -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;

View File

@ -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 {

View File

@ -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

View File

@ -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);

View File

@ -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);