39 #if MICROPY_DEBUG_VERBOSE // print debugging info 40 #define DEBUG_printf DEBUG_printf 41 #else // don't print debugging info 42 #define DEBUG_printf(...) (void)0 52 #if MICROPY_QSTR_BYTES_IN_HASH == 1 53 #define Q_HASH_MASK (0xff) 54 #define Q_GET_HASH(q) ((mp_uint_t)(q)[0]) 55 #define Q_SET_HASH(q, hash) do { (q)[0] = (hash); } while (0) 56 #elif MICROPY_QSTR_BYTES_IN_HASH == 2 57 #define Q_HASH_MASK (0xffff) 58 #define Q_GET_HASH(q) ((mp_uint_t)(q)[0] | ((mp_uint_t)(q)[1] << 8)) 59 #define Q_SET_HASH(q, hash) do { (q)[0] = (hash); (q)[1] = (hash) >> 8; } while (0) 61 #error unimplemented qstr hash decoding 63 #define Q_GET_ALLOC(q) (MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + Q_GET_LENGTH(q) + 1) 64 #define Q_GET_DATA(q) ((q) + MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN) 65 #if MICROPY_QSTR_BYTES_IN_LEN == 1 66 #define Q_GET_LENGTH(q) ((q)[MICROPY_QSTR_BYTES_IN_HASH]) 67 #define Q_SET_LENGTH(q, len) do { (q)[MICROPY_QSTR_BYTES_IN_HASH] = (len); } while (0) 68 #elif MICROPY_QSTR_BYTES_IN_LEN == 2 69 #define Q_GET_LENGTH(q) ((q)[MICROPY_QSTR_BYTES_IN_HASH] | ((q)[MICROPY_QSTR_BYTES_IN_HASH + 1] << 8)) 70 #define Q_SET_LENGTH(q, len) do { (q)[MICROPY_QSTR_BYTES_IN_HASH] = (len); (q)[MICROPY_QSTR_BYTES_IN_HASH + 1] = (len) >> 8; } while (0) 72 #error unimplemented qstr length decoding 75 #if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL 76 #define QSTR_ENTER() mp_thread_mutex_lock(&MP_STATE_VM(qstr_mutex), 1) 77 #define QSTR_EXIT() mp_thread_mutex_unlock(&MP_STATE_VM(qstr_mutex)) 88 hash = ((hash << 5) + hash) ^ (*data);
105 #define QDEF(id, str) str, 106 #include "genhdr/qstrdefs.generated.h" 112 #ifdef MICROPY_QSTR_EXTRA_POOL 114 #define CONST_POOL MICROPY_QSTR_EXTRA_POOL 116 #define CONST_POOL mp_qstr_const_pool 123 #if MICROPY_PY_THREAD 131 if (q >= pool->total_prev_len) {
132 return pool->qstrs[q - pool->total_prev_len];
142 DEBUG_printf(
"QSTR: add hash=%d len=%d data=%.*s\n", Q_GET_HASH(q_ptr), Q_GET_LENGTH(q_ptr), Q_GET_LENGTH(q_ptr),
Q_GET_DATA(q_ptr));
172 for (
const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
173 if (Q_GET_HASH(*q) == str_hash && Q_GET_LENGTH(*q) == str_len &&
memcmp(
Q_GET_DATA(*q), str, str_len) == 0) {
174 return pool->total_prev_len + (q - pool->qstrs);
236 Q_SET_HASH(q_ptr, hash);
237 Q_SET_LENGTH(q_ptr, len);
249 Q_SET_LENGTH(*q_ptr, len);
257 size_t len = Q_GET_LENGTH(q_ptr);
259 Q_SET_HASH(q_ptr, hash);
275 return Q_GET_LENGTH(qd);
285 *len = Q_GET_LENGTH(qd);
289 void qstr_pool_info(
size_t *n_pool,
size_t *n_qstr,
size_t *n_str_data_bytes,
size_t *n_total_bytes) {
293 *n_str_data_bytes = 0;
297 *n_qstr += pool->len;
298 for (
const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
301 #if MICROPY_ENABLE_GC 307 *n_total_bytes += *n_str_data_bytes;
311 #if MICROPY_PY_MICROPYTHON_MEM_INFO 315 for (
const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
const mp_print_t mp_plat_print
#define m_renew_maybe(type, ptr, old_num, new_num, allow_move)
struct _qstr_pool_t * prev
qstr qstr_from_strn(const char *str, size_t len)
STATIC qstr qstr_add(const byte *q_ptr)
const char * qstr_str(qstr q)
#define m_del(type, ptr, num)
STATIC const byte * find_qstr(qstr q)
qstr qstr_from_str(const char *str)
qstr qstr_find_strn(const char *str, size_t str_len)
struct _qstr_pool_t qstr_pool_t
mp_uint_t qstr_hash(qstr q)
#define MICROPY_ALLOC_QSTR_CHUNK_INIT
size_t strlen(const char *s)
#define m_new_maybe(type, num)
#define MICROPY_QSTR_BYTES_IN_LEN
const qstr_pool_t mp_qstr_const_pool
#define MICROPY_QSTR_BYTES_IN_HASH
#define DEBUG_printf(...)
const byte * qstr_data(qstr q, size_t *len)
NORETURN void m_malloc_fail(size_t num_bytes)
mp_uint_t qstr_compute_hash(const byte *data, size_t len)
byte * qstr_build_start(size_t len, byte **q_ptr)
qstr qstr_build_end(byte *q_ptr)
void qstr_dump_data(void)
LIBA_BEGIN_DECLS int memcmp(const void *s1, const void *s2, size_t n)
int mp_printf(const mp_print_t *print, const char *fmt,...)
size_t gc_nbytes(const void *ptr)
void * memcpy(void *dst, const void *src, size_t n)
#define m_new_obj_var_maybe(obj_type, var_type, var_num)
void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes)