2014-05-03 23:27:38 +01:00
|
|
|
/*
|
2017-06-30 08:22:17 +01:00
|
|
|
* This file is part of the MicroPython project, http://micropython.org/
|
2014-05-03 23:27:38 +01:00
|
|
|
*
|
|
|
|
* The MIT License (MIT)
|
|
|
|
*
|
|
|
|
* Copyright (c) 2013, 2014 Damien P. George
|
|
|
|
*
|
|
|
|
* Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
|
|
* of this software and associated documentation files (the "Software"), to deal
|
|
|
|
* in the Software without restriction, including without limitation the rights
|
|
|
|
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
|
|
* copies of the Software, and to permit persons to whom the Software is
|
|
|
|
* furnished to do so, subject to the following conditions:
|
|
|
|
*
|
|
|
|
* The above copyright notice and this permission notice shall be included in
|
|
|
|
* all copies or substantial portions of the Software.
|
|
|
|
*
|
|
|
|
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
|
|
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
|
|
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
|
|
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
|
|
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
|
|
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
|
|
* THE SOFTWARE.
|
|
|
|
*/
|
|
|
|
|
2013-10-04 19:53:11 +01:00
|
|
|
#include <assert.h>
|
|
|
|
#include <string.h>
|
2015-02-10 11:02:28 +00:00
|
|
|
#include <stdio.h>
|
2013-10-04 19:53:11 +01:00
|
|
|
|
2015-01-01 23:30:53 +00:00
|
|
|
#include "py/mpstate.h"
|
2015-01-01 20:27:54 +00:00
|
|
|
#include "py/qstr.h"
|
|
|
|
#include "py/gc.h"
|
2013-10-04 19:53:11 +01:00
|
|
|
|
2014-01-04 15:57:35 +00:00
|
|
|
// NOTE: we are using linear arrays to store and search for qstr's (unique strings, interned strings)
|
|
|
|
// ultimately we will replace this with a static hash table of some kind
|
|
|
|
// also probably need to include the length in the string data, to allow null bytes in the string
|
|
|
|
|
2017-07-24 17:55:14 +01:00
|
|
|
#if MICROPY_DEBUG_VERBOSE // print debugging info
|
2014-02-16 16:11:42 +00:00
|
|
|
#define DEBUG_printf DEBUG_printf
|
2014-01-04 15:57:35 +00:00
|
|
|
#else // don't print debugging info
|
2014-02-26 16:57:08 +00:00
|
|
|
#define DEBUG_printf(...) (void)0
|
2014-01-04 15:57:35 +00:00
|
|
|
#endif
|
|
|
|
|
2014-01-21 21:40:13 +00:00
|
|
|
// A qstr is an index into the qstr pool.
|
2015-07-20 12:03:13 +01:00
|
|
|
// The data for a qstr contains (hash, length, data):
|
|
|
|
// - hash (configurable number of bytes)
|
|
|
|
// - length (configurable number of bytes)
|
|
|
|
// - data ("length" number of bytes)
|
|
|
|
// - \0 terminated (so they can be printed using printf)
|
|
|
|
|
|
|
|
#if MICROPY_QSTR_BYTES_IN_HASH == 1
|
|
|
|
#define Q_HASH_MASK (0xff)
|
|
|
|
#define Q_GET_HASH(q) ((mp_uint_t)(q)[0])
|
|
|
|
#define Q_SET_HASH(q, hash) do { (q)[0] = (hash); } while (0)
|
|
|
|
#elif MICROPY_QSTR_BYTES_IN_HASH == 2
|
|
|
|
#define Q_HASH_MASK (0xffff)
|
|
|
|
#define Q_GET_HASH(q) ((mp_uint_t)(q)[0] | ((mp_uint_t)(q)[1] << 8))
|
|
|
|
#define Q_SET_HASH(q, hash) do { (q)[0] = (hash); (q)[1] = (hash) >> 8; } while (0)
|
|
|
|
#else
|
|
|
|
#error unimplemented qstr hash decoding
|
|
|
|
#endif
|
|
|
|
#define Q_GET_ALLOC(q) (MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + Q_GET_LENGTH(q) + 1)
|
|
|
|
#define Q_GET_DATA(q) ((q) + MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN)
|
2015-01-11 22:27:30 +00:00
|
|
|
#if MICROPY_QSTR_BYTES_IN_LEN == 1
|
2015-07-20 12:03:13 +01:00
|
|
|
#define Q_GET_LENGTH(q) ((q)[MICROPY_QSTR_BYTES_IN_HASH])
|
|
|
|
#define Q_SET_LENGTH(q, len) do { (q)[MICROPY_QSTR_BYTES_IN_HASH] = (len); } while (0)
|
2015-01-11 22:27:30 +00:00
|
|
|
#elif MICROPY_QSTR_BYTES_IN_LEN == 2
|
2015-07-20 12:03:13 +01:00
|
|
|
#define Q_GET_LENGTH(q) ((q)[MICROPY_QSTR_BYTES_IN_HASH] | ((q)[MICROPY_QSTR_BYTES_IN_HASH + 1] << 8))
|
|
|
|
#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)
|
2015-01-11 22:27:30 +00:00
|
|
|
#else
|
|
|
|
#error unimplemented qstr length decoding
|
|
|
|
#endif
|
2014-01-21 21:40:13 +00:00
|
|
|
|
2016-05-26 11:53:34 +01:00
|
|
|
#if MICROPY_PY_THREAD && !MICROPY_PY_THREAD_GIL
|
2016-05-26 10:06:46 +01:00
|
|
|
#define QSTR_ENTER() mp_thread_mutex_lock(&MP_STATE_VM(qstr_mutex), 1)
|
|
|
|
#define QSTR_EXIT() mp_thread_mutex_unlock(&MP_STATE_VM(qstr_mutex))
|
|
|
|
#else
|
|
|
|
#define QSTR_ENTER()
|
|
|
|
#define QSTR_EXIT()
|
|
|
|
#endif
|
|
|
|
|
2018-12-13 06:08:26 +00:00
|
|
|
// Initial number of entries for qstr pool, set so that the first dynamically
|
|
|
|
// allocated pool is twice this size. The value here must be <= MP_QSTRnumber_of.
|
|
|
|
#define MICROPY_ALLOC_QSTR_ENTRIES_INIT (10)
|
|
|
|
|
2014-03-25 15:27:15 +00:00
|
|
|
// this must match the equivalent function in makeqstrdata.py
|
2015-11-27 12:23:18 +00:00
|
|
|
mp_uint_t qstr_compute_hash(const byte *data, size_t len) {
|
2014-03-25 15:27:15 +00:00
|
|
|
// djb2 algorithm; see http://www.cse.yorku.ca/~oz/hash.html
|
2014-07-03 13:25:24 +01:00
|
|
|
mp_uint_t hash = 5381;
|
2014-01-21 21:40:13 +00:00
|
|
|
for (const byte *top = data + len; data < top; data++) {
|
2014-03-25 15:27:15 +00:00
|
|
|
hash = ((hash << 5) + hash) ^ (*data); // hash * 33 ^ data
|
2014-01-21 21:40:13 +00:00
|
|
|
}
|
2015-07-20 12:03:13 +01:00
|
|
|
hash &= Q_HASH_MASK;
|
2014-04-13 23:43:01 +01:00
|
|
|
// Make sure that valid hash is never zero, zero means "hash not computed"
|
|
|
|
if (hash == 0) {
|
|
|
|
hash++;
|
|
|
|
}
|
|
|
|
return hash;
|
2014-01-21 21:40:13 +00:00
|
|
|
}
|
|
|
|
|
2016-01-31 22:24:16 +00:00
|
|
|
const qstr_pool_t mp_qstr_const_pool = {
|
2014-01-04 15:57:35 +00:00
|
|
|
NULL, // no previous pool
|
|
|
|
0, // no previous pool
|
2018-12-13 06:08:26 +00:00
|
|
|
MICROPY_ALLOC_QSTR_ENTRIES_INIT,
|
2016-01-31 22:24:16 +00:00
|
|
|
MP_QSTRnumber_of, // corresponds to number of strings in array just below
|
2014-01-04 15:57:35 +00:00
|
|
|
{
|
2016-06-15 23:40:31 +01:00
|
|
|
#ifndef NO_QSTR
|
2015-01-11 17:52:45 +00:00
|
|
|
#define QDEF(id, str) str,
|
2014-04-17 18:03:27 +01:00
|
|
|
#include "genhdr/qstrdefs.generated.h"
|
2015-01-11 17:52:45 +00:00
|
|
|
#undef QDEF
|
2016-04-19 09:30:06 +01:00
|
|
|
#endif
|
2014-01-04 15:57:35 +00:00
|
|
|
},
|
|
|
|
};
|
|
|
|
|
2016-01-31 22:24:16 +00:00
|
|
|
#ifdef MICROPY_QSTR_EXTRA_POOL
|
|
|
|
extern const qstr_pool_t MICROPY_QSTR_EXTRA_POOL;
|
|
|
|
#define CONST_POOL MICROPY_QSTR_EXTRA_POOL
|
|
|
|
#else
|
|
|
|
#define CONST_POOL mp_qstr_const_pool
|
|
|
|
#endif
|
|
|
|
|
2013-10-23 20:20:17 +01:00
|
|
|
void qstr_init(void) {
|
2016-01-31 22:24:16 +00:00
|
|
|
MP_STATE_VM(last_pool) = (qstr_pool_t*)&CONST_POOL; // we won't modify the const_pool since it has no allocated room left
|
2015-06-13 21:53:22 +01:00
|
|
|
MP_STATE_VM(qstr_last_chunk) = NULL;
|
2016-05-26 10:06:46 +01:00
|
|
|
|
|
|
|
#if MICROPY_PY_THREAD
|
|
|
|
mp_thread_mutex_init(&MP_STATE_VM(qstr_mutex));
|
|
|
|
#endif
|
2013-10-04 19:53:11 +01:00
|
|
|
}
|
|
|
|
|
2014-02-12 16:31:30 +00:00
|
|
|
STATIC const byte *find_qstr(qstr q) {
|
2014-01-21 21:40:13 +00:00
|
|
|
// search pool for this qstr
|
2017-11-29 05:58:27 +00:00
|
|
|
// total_prev_len==0 in the final pool, so the loop will always terminate
|
|
|
|
qstr_pool_t *pool = MP_STATE_VM(last_pool);
|
|
|
|
while (q < pool->total_prev_len) {
|
|
|
|
pool = pool->prev;
|
2014-01-21 21:40:13 +00:00
|
|
|
}
|
2017-11-29 05:58:27 +00:00
|
|
|
return pool->qstrs[q - pool->total_prev_len];
|
2014-01-21 21:40:13 +00:00
|
|
|
}
|
|
|
|
|
2016-05-26 10:06:46 +01:00
|
|
|
// qstr_mutex must be taken while in this function
|
2014-02-12 16:31:30 +00:00
|
|
|
STATIC qstr qstr_add(const byte *q_ptr) {
|
2014-01-21 21:40:13 +00:00
|
|
|
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));
|
2014-01-04 15:57:35 +00:00
|
|
|
|
|
|
|
// make sure we have room in the pool for a new qstr
|
2015-01-01 23:30:53 +00:00
|
|
|
if (MP_STATE_VM(last_pool)->len >= MP_STATE_VM(last_pool)->alloc) {
|
2018-12-13 06:08:26 +00:00
|
|
|
size_t new_alloc = MP_STATE_VM(last_pool)->alloc * 2;
|
|
|
|
#ifdef MICROPY_QSTR_EXTRA_POOL
|
|
|
|
// Put a lower bound on the allocation size in case the extra qstr pool has few entries
|
|
|
|
new_alloc = MAX(MICROPY_ALLOC_QSTR_ENTRIES_INIT, new_alloc);
|
|
|
|
#endif
|
|
|
|
qstr_pool_t *pool = m_new_obj_var_maybe(qstr_pool_t, const char*, new_alloc);
|
2016-05-26 10:06:46 +01:00
|
|
|
if (pool == NULL) {
|
|
|
|
QSTR_EXIT();
|
2018-12-13 06:08:26 +00:00
|
|
|
m_malloc_fail(new_alloc);
|
2016-05-26 10:06:46 +01:00
|
|
|
}
|
2015-01-01 23:30:53 +00:00
|
|
|
pool->prev = MP_STATE_VM(last_pool);
|
|
|
|
pool->total_prev_len = MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len;
|
2018-12-13 06:08:26 +00:00
|
|
|
pool->alloc = new_alloc;
|
2014-01-04 15:57:35 +00:00
|
|
|
pool->len = 0;
|
2015-01-01 23:30:53 +00:00
|
|
|
MP_STATE_VM(last_pool) = pool;
|
|
|
|
DEBUG_printf("QSTR: allocate new pool of size %d\n", MP_STATE_VM(last_pool)->alloc);
|
2013-10-04 19:53:11 +01:00
|
|
|
}
|
2014-01-04 15:57:35 +00:00
|
|
|
|
|
|
|
// add the new qstr
|
2015-01-01 23:30:53 +00:00
|
|
|
MP_STATE_VM(last_pool)->qstrs[MP_STATE_VM(last_pool)->len++] = q_ptr;
|
2014-01-04 15:57:35 +00:00
|
|
|
|
|
|
|
// return id for the newly-added qstr
|
2015-01-01 23:30:53 +00:00
|
|
|
return MP_STATE_VM(last_pool)->total_prev_len + MP_STATE_VM(last_pool)->len - 1;
|
2013-10-04 19:53:11 +01:00
|
|
|
}
|
|
|
|
|
2015-11-27 12:23:18 +00:00
|
|
|
qstr qstr_find_strn(const char *str, size_t str_len) {
|
2014-01-21 21:40:13 +00:00
|
|
|
// work out hash of str
|
2014-07-03 13:25:24 +01:00
|
|
|
mp_uint_t str_hash = qstr_compute_hash((const byte*)str, str_len);
|
2014-01-21 21:40:13 +00:00
|
|
|
|
|
|
|
// search pools for the data
|
2015-01-01 23:30:53 +00:00
|
|
|
for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL; pool = pool->prev) {
|
2014-01-21 21:40:13 +00:00
|
|
|
for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
|
2014-01-23 18:27:51 +00:00
|
|
|
if (Q_GET_HASH(*q) == str_hash && Q_GET_LENGTH(*q) == str_len && memcmp(Q_GET_DATA(*q), str, str_len) == 0) {
|
2014-01-21 21:40:13 +00:00
|
|
|
return pool->total_prev_len + (q - pool->qstrs);
|
2014-01-04 15:57:35 +00:00
|
|
|
}
|
2013-10-04 19:53:11 +01:00
|
|
|
}
|
|
|
|
}
|
2014-01-21 21:40:13 +00:00
|
|
|
|
|
|
|
// not found; return null qstr
|
|
|
|
return 0;
|
2013-10-04 19:53:11 +01:00
|
|
|
}
|
|
|
|
|
2014-01-21 21:40:13 +00:00
|
|
|
qstr qstr_from_str(const char *str) {
|
|
|
|
return qstr_from_strn(str, strlen(str));
|
2013-10-04 19:53:11 +01:00
|
|
|
}
|
|
|
|
|
2015-11-27 12:23:18 +00:00
|
|
|
qstr qstr_from_strn(const char *str, size_t len) {
|
2015-01-13 16:21:23 +00:00
|
|
|
assert(len < (1 << (8 * MICROPY_QSTR_BYTES_IN_LEN)));
|
2016-05-26 10:06:46 +01:00
|
|
|
QSTR_ENTER();
|
2014-05-25 22:27:57 +01:00
|
|
|
qstr q = qstr_find_strn(str, len);
|
2014-01-21 21:40:13 +00:00
|
|
|
if (q == 0) {
|
2015-06-13 21:53:22 +01:00
|
|
|
// qstr does not exist in interned pool so need to add it
|
|
|
|
|
|
|
|
// compute number of bytes needed to intern this string
|
2015-12-17 12:41:40 +00:00
|
|
|
size_t n_bytes = MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len + 1;
|
2015-06-13 21:53:22 +01:00
|
|
|
|
|
|
|
if (MP_STATE_VM(qstr_last_chunk) != NULL && MP_STATE_VM(qstr_last_used) + n_bytes > MP_STATE_VM(qstr_last_alloc)) {
|
|
|
|
// not enough room at end of previously interned string so try to grow
|
|
|
|
byte *new_p = m_renew_maybe(byte, MP_STATE_VM(qstr_last_chunk), MP_STATE_VM(qstr_last_alloc), MP_STATE_VM(qstr_last_alloc) + n_bytes, false);
|
|
|
|
if (new_p == NULL) {
|
|
|
|
// could not grow existing memory; shrink it to fit previous
|
2016-10-31 14:05:56 +00:00
|
|
|
(void)m_renew_maybe(byte, MP_STATE_VM(qstr_last_chunk), MP_STATE_VM(qstr_last_alloc), MP_STATE_VM(qstr_last_used), false);
|
2015-06-13 21:53:22 +01:00
|
|
|
MP_STATE_VM(qstr_last_chunk) = NULL;
|
|
|
|
} else {
|
|
|
|
// could grow existing memory
|
|
|
|
MP_STATE_VM(qstr_last_alloc) += n_bytes;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
if (MP_STATE_VM(qstr_last_chunk) == NULL) {
|
|
|
|
// no existing memory for the interned string so allocate a new chunk
|
2015-11-27 12:23:18 +00:00
|
|
|
size_t al = n_bytes;
|
2015-06-13 21:53:22 +01:00
|
|
|
if (al < MICROPY_ALLOC_QSTR_CHUNK_INIT) {
|
|
|
|
al = MICROPY_ALLOC_QSTR_CHUNK_INIT;
|
|
|
|
}
|
|
|
|
MP_STATE_VM(qstr_last_chunk) = m_new_maybe(byte, al);
|
|
|
|
if (MP_STATE_VM(qstr_last_chunk) == NULL) {
|
|
|
|
// failed to allocate a large chunk so try with exact size
|
2016-05-26 10:06:46 +01:00
|
|
|
MP_STATE_VM(qstr_last_chunk) = m_new_maybe(byte, n_bytes);
|
|
|
|
if (MP_STATE_VM(qstr_last_chunk) == NULL) {
|
|
|
|
QSTR_EXIT();
|
|
|
|
m_malloc_fail(n_bytes);
|
|
|
|
}
|
2015-06-13 21:53:22 +01:00
|
|
|
al = n_bytes;
|
|
|
|
}
|
|
|
|
MP_STATE_VM(qstr_last_alloc) = al;
|
|
|
|
MP_STATE_VM(qstr_last_used) = 0;
|
|
|
|
}
|
|
|
|
|
|
|
|
// allocate memory from the chunk for this new interned string's data
|
|
|
|
byte *q_ptr = MP_STATE_VM(qstr_last_chunk) + MP_STATE_VM(qstr_last_used);
|
|
|
|
MP_STATE_VM(qstr_last_used) += n_bytes;
|
|
|
|
|
|
|
|
// store the interned strings' data
|
2014-07-03 13:25:24 +01:00
|
|
|
mp_uint_t hash = qstr_compute_hash((const byte*)str, len);
|
2015-07-20 12:03:13 +01:00
|
|
|
Q_SET_HASH(q_ptr, hash);
|
2015-01-11 22:27:30 +00:00
|
|
|
Q_SET_LENGTH(q_ptr, len);
|
2015-07-20 12:03:13 +01:00
|
|
|
memcpy(q_ptr + MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN, str, len);
|
|
|
|
q_ptr[MICROPY_QSTR_BYTES_IN_HASH + MICROPY_QSTR_BYTES_IN_LEN + len] = '\0';
|
2014-01-21 21:40:13 +00:00
|
|
|
q = qstr_add(q_ptr);
|
2013-10-04 19:53:11 +01:00
|
|
|
}
|
2016-05-26 10:06:46 +01:00
|
|
|
QSTR_EXIT();
|
2014-01-21 21:40:13 +00:00
|
|
|
return q;
|
2013-10-04 19:53:11 +01:00
|
|
|
}
|
|
|
|
|
2014-07-03 13:25:24 +01:00
|
|
|
mp_uint_t qstr_hash(qstr q) {
|
2019-02-19 12:44:01 +00:00
|
|
|
const byte *qd = find_qstr(q);
|
|
|
|
return Q_GET_HASH(qd);
|
2014-01-21 21:40:13 +00:00
|
|
|
}
|
|
|
|
|
2015-11-27 12:23:18 +00:00
|
|
|
size_t qstr_len(qstr q) {
|
2014-01-21 21:40:13 +00:00
|
|
|
const byte *qd = find_qstr(q);
|
|
|
|
return Q_GET_LENGTH(qd);
|
|
|
|
}
|
|
|
|
|
|
|
|
const char *qstr_str(qstr q) {
|
|
|
|
const byte *qd = find_qstr(q);
|
|
|
|
return (const char*)Q_GET_DATA(qd);
|
|
|
|
}
|
2014-01-04 15:57:35 +00:00
|
|
|
|
2015-11-27 12:23:18 +00:00
|
|
|
const byte *qstr_data(qstr q, size_t *len) {
|
2014-01-21 21:40:13 +00:00
|
|
|
const byte *qd = find_qstr(q);
|
|
|
|
*len = Q_GET_LENGTH(qd);
|
|
|
|
return Q_GET_DATA(qd);
|
2013-10-04 19:53:11 +01:00
|
|
|
}
|
2014-01-29 18:56:46 +00:00
|
|
|
|
2015-12-17 12:41:40 +00:00
|
|
|
void qstr_pool_info(size_t *n_pool, size_t *n_qstr, size_t *n_str_data_bytes, size_t *n_total_bytes) {
|
2016-05-26 10:06:46 +01:00
|
|
|
QSTR_ENTER();
|
2014-01-29 18:56:46 +00:00
|
|
|
*n_pool = 0;
|
|
|
|
*n_qstr = 0;
|
|
|
|
*n_str_data_bytes = 0;
|
|
|
|
*n_total_bytes = 0;
|
2016-01-31 22:24:16 +00:00
|
|
|
for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
|
2014-01-29 18:56:46 +00:00
|
|
|
*n_pool += 1;
|
|
|
|
*n_qstr += pool->len;
|
|
|
|
for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
|
|
|
|
*n_str_data_bytes += Q_GET_ALLOC(*q);
|
|
|
|
}
|
2014-10-24 23:12:25 +01:00
|
|
|
#if MICROPY_ENABLE_GC
|
|
|
|
*n_total_bytes += gc_nbytes(pool); // this counts actual bytes used in heap
|
|
|
|
#else
|
2014-01-29 18:56:46 +00:00
|
|
|
*n_total_bytes += sizeof(qstr_pool_t) + sizeof(qstr) * pool->alloc;
|
2014-10-24 23:12:25 +01:00
|
|
|
#endif
|
2014-01-29 18:56:46 +00:00
|
|
|
}
|
|
|
|
*n_total_bytes += *n_str_data_bytes;
|
2016-05-26 10:06:46 +01:00
|
|
|
QSTR_EXIT();
|
2014-01-29 18:56:46 +00:00
|
|
|
}
|
2015-02-10 11:02:28 +00:00
|
|
|
|
|
|
|
#if MICROPY_PY_MICROPYTHON_MEM_INFO
|
|
|
|
void qstr_dump_data(void) {
|
2016-05-26 10:06:46 +01:00
|
|
|
QSTR_ENTER();
|
2016-01-31 22:24:16 +00:00
|
|
|
for (qstr_pool_t *pool = MP_STATE_VM(last_pool); pool != NULL && pool != &CONST_POOL; pool = pool->prev) {
|
2015-02-10 11:02:28 +00:00
|
|
|
for (const byte **q = pool->qstrs, **q_top = pool->qstrs + pool->len; q < q_top; q++) {
|
2015-04-11 12:15:47 +01:00
|
|
|
mp_printf(&mp_plat_print, "Q(%s)\n", Q_GET_DATA(*q));
|
2015-02-10 11:02:28 +00:00
|
|
|
}
|
|
|
|
}
|
2016-05-26 10:06:46 +01:00
|
|
|
QSTR_EXIT();
|
2015-02-10 11:02:28 +00:00
|
|
|
}
|
|
|
|
#endif
|