diff options
author | Romain Goyet <romain.goyet@numworks.com> | 2020-04-10 16:09:29 -0400 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2020-04-13 22:27:27 +1000 |
commit | bd63c26dd5560e1037fa06e79f99627de5772da5 (patch) | |
tree | 6b51ba215f13e6e8288c2ddc0b4753239179a4a2 /py/scope.c | |
parent | 7654907e1e4dfce096091f61cbdf4bb898225ab0 (diff) |
py/scope: Add assert to check that low numbered qstrs do fit in uint8_t.
Diffstat (limited to 'py/scope.c')
-rw-r--r-- | py/scope.c | 10 |
1 files changed, 9 insertions, 1 deletions
diff --git a/py/scope.c b/py/scope.c index 1e45139b0..073c2a38c 100644 --- a/py/scope.c +++ b/py/scope.c @@ -30,7 +30,7 @@ #if MICROPY_ENABLE_COMPILER -// these low numbered qstrs should fit in 8 bits +// These low numbered qstrs should fit in 8 bits. See assertions below. STATIC const uint8_t scope_simple_name_table[] = { [SCOPE_MODULE] = MP_QSTR__lt_module_gt_, [SCOPE_LAMBDA] = MP_QSTR__lt_lambda_gt_, @@ -41,6 +41,14 @@ STATIC const uint8_t scope_simple_name_table[] = { }; scope_t *scope_new(scope_kind_t kind, mp_parse_node_t pn, qstr source_file, mp_uint_t emit_options) { + // Make sure those qstrs indeed fit in an uint8_t. + MP_STATIC_ASSERT(MP_QSTR__lt_module_gt_ <= UINT8_MAX); + MP_STATIC_ASSERT(MP_QSTR__lt_lambda_gt_ <= UINT8_MAX); + MP_STATIC_ASSERT(MP_QSTR__lt_listcomp_gt_ <= UINT8_MAX); + MP_STATIC_ASSERT(MP_QSTR__lt_dictcomp_gt_ <= UINT8_MAX); + MP_STATIC_ASSERT(MP_QSTR__lt_setcomp_gt_ <= UINT8_MAX); + MP_STATIC_ASSERT(MP_QSTR__lt_genexpr_gt_ <= UINT8_MAX); + scope_t *scope = m_new0(scope_t, 1); scope->kind = kind; scope->pn = pn; |