Skip to content

Commit 2578485

Browse files
committed
py/qstr: Use size_t instead of mp_uint_t when counting allocated bytes.
1 parent 1d899e1 commit 2578485

4 files changed

Lines changed: 11 additions & 11 deletions

File tree

py/modmicropython.c

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -79,9 +79,9 @@ STATIC MP_DEFINE_CONST_FUN_OBJ_VAR_BETWEEN(mp_micropython_mem_info_obj, 0, 1, mp
7979

8080
STATIC mp_obj_t mp_micropython_qstr_info(mp_uint_t n_args, const mp_obj_t *args) {
8181
(void)args;
82-
mp_uint_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
82+
size_t n_pool, n_qstr, n_str_data_bytes, n_total_bytes;
8383
qstr_pool_info(&n_pool, &n_qstr, &n_str_data_bytes, &n_total_bytes);
84-
mp_printf(&mp_plat_print, "qstr pool: n_pool=" UINT_FMT ", n_qstr=" UINT_FMT ", n_str_data_bytes=" UINT_FMT ", n_total_bytes=" UINT_FMT "\n",
84+
mp_printf(&mp_plat_print, "qstr pool: n_pool=%u, n_qstr=%u, n_str_data_bytes=%u, n_total_bytes=%u\n",
8585
n_pool, n_qstr, n_str_data_bytes, n_total_bytes);
8686
if (n_args == 1) {
8787
// arg given means dump qstr data

py/mpstate.h

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,8 +138,8 @@ typedef struct _mp_state_vm_t {
138138
// pointer and sizes to store interned string data
139139
// (qstr_last_chunk can be root pointer but is also stored in qstr pool)
140140
byte *qstr_last_chunk;
141-
mp_uint_t qstr_last_alloc;
142-
mp_uint_t qstr_last_used;
141+
size_t qstr_last_alloc;
142+
size_t qstr_last_used;
143143

144144
// Stack top at the start of program
145145
// Note: this entry is used to locate the end of the root pointer section.

py/qstr.c

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,7 @@ qstr qstr_from_strn(const char *str, size_t len) {
165165
// qstr does not exist in interned pool so need to add it
166166

167167
// compute number of bytes needed to intern this string
168-
mp_uint_t n_bytes = MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len + 1;
168+
size_t n_bytes = MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len + 1;
169169

170170
if (MP_STATE_VM(qstr_last_chunk) != NULL && MP_STATE_VM(qstr_last_used) + n_bytes > MP_STATE_VM(qstr_last_alloc)) {
171171
// not enough room at end of previously interned string so try to grow
@@ -221,7 +221,7 @@ byte *qstr_build_start(size_t len, byte **q_ptr) {
221221
qstr qstr_build_end(byte *q_ptr) {
222222
qstr q = qstr_find_strn((const char*)Q_GET_DATA(q_ptr), Q_GET_LENGTH(q_ptr));
223223
if (q == 0) {
224-
mp_uint_t len = Q_GET_LENGTH(q_ptr);
224+
size_t len = Q_GET_LENGTH(q_ptr);
225225
mp_uint_t hash = qstr_compute_hash(Q_GET_DATA(q_ptr), len);
226226
Q_SET_HASH(q_ptr, hash);
227227
q_ptr[MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len] = '\0';
@@ -253,7 +253,7 @@ const byte *qstr_data(qstr q, size_t *len) {
253253
return Q_GET_DATA(qd);
254254
}
255255

256-
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) {
256+
void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes) {
257257
*n_pool = 0;
258258
*n_qstr = 0;
259259
*n_str_data_bytes = 0;

py/qstr.h

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -47,9 +47,9 @@ typedef mp_uint_t qstr;
4747

4848
typedef struct _qstr_pool_t {
4949
struct _qstr_pool_t *prev;
50-
mp_uint_t total_prev_len;
51-
mp_uint_t alloc;
52-
mp_uint_t len;
50+
size_t total_prev_len;
51+
size_t alloc;
52+
size_t len;
5353
const byte *qstrs[];
5454
} qstr_pool_t;
5555

@@ -71,7 +71,7 @@ const char *qstr_str(qstr q);
7171
size_t qstr_len(qstr q);
7272
const byte *qstr_data(qstr q, size_t *len);
7373

74-
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);
74+
void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes);
7575
void qstr_dump_data(void);
7676

7777
#endif // __MICROPY_INCLUDED_PY_QSTR_H__

0 commit comments

Comments
 (0)