Skip to content

Commit 2d73ba2

Browse files
committed
qstr: Use const consistently to avoid a cast.
1 parent f5f18b2 commit 2d73ba2

File tree

3 files changed

+7
-7
lines changed

3 files changed

+7
-7
lines changed

py/qstr.c

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -123,7 +123,7 @@ void qstr_init(void) {
123123
STATIC const char *find_qstr(qstr q, qstr_attr_t *attr) {
124124
// search pool for this qstr
125125
// total_prev_len==0 in the final pool, so the loop will always terminate
126-
qstr_pool_t *pool = MP_STATE_VM(last_pool);
126+
const qstr_pool_t *pool = MP_STATE_VM(last_pool);
127127
while (q < pool->total_prev_len) {
128128
pool = pool->prev;
129129
}
@@ -181,7 +181,7 @@ qstr qstr_find_strn(const char *str, size_t str_len) {
181181
mp_uint_t str_hash = qstr_compute_hash((const byte *)str, str_len);
182182

183183
// search pools for the data
184-
for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) {
184+
for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) {
185185
qstr_attr_t *attrs = pool->attrs;
186186
for (mp_uint_t at = 0, top = pool->len; at < top; at++) {
187187
if (attrs[at].hash == str_hash && attrs[at].len == str_len && memcmp(pool->qstrs[at], str, str_len) == 0) {
@@ -290,7 +290,7 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si
290290
*n_qstr = 0;
291291
*n_str_data_bytes = 0;
292292
*n_total_bytes = 0;
293-
for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
293+
for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
294294
*n_pool += 1;
295295
*n_qstr += pool->len;
296296
for (const qstr_attr_t *q = pool->attrs, *q_top = pool->attrs + pool->len; q < q_top; q++) {
@@ -310,8 +310,8 @@ void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, si
310310
#if MICROPY_PY_MICROPYTHON_MEM_INFO
311311
void qstr_dump_data(void) {
312312
QSTR_ENTER();
313-
for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
314-
for (const char **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
313+
for (const qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
314+
for (const char *const *q = pool->qstrs, *const *q_top = pool->qstrs + pool->len; q < q_top; q++) {
315315
mp_printf(&mp_plat_print, "Q(%s)\n", *q);
316316
}
317317
}

py/qstr.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -65,7 +65,7 @@ typedef struct _qstr_attr_t {
6565
} qstr_attr_t;
6666

6767
typedef struct _qstr_pool_t {
68-
struct _qstr_pool_t *prev;
68+
const struct _qstr_pool_t *prev;
6969
size_t total_prev_len;
7070
size_t alloc;
7171
size_t len;

tools/mpy-tool.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -878,7 +878,7 @@ def freeze_mpy(base_qstrs, raw_codes):
878878
print()
879879
print("extern const qstr_pool_t mp_qstr_const_pool;")
880880
print("const qstr_pool_t mp_qstr_frozen_const_pool = {")
881-
print(" (qstr_pool_t*)&mp_qstr_const_pool, // previous pool")
881+
print(" &mp_qstr_const_pool, // previous pool")
882882
print(" MP_QSTRnumber_of, // previous pool size")
883883
print(" %u, // allocated entries" % qstr_pool_alloc)
884884
print(" %u, // used entries" % len(new))

0 commit comments

Comments
 (0)