diff options
author | Damien George <damien.p.george@gmail.com> | 2014-09-23 15:31:56 +0000 |
---|---|---|
committer | Damien George <damien.p.george@gmail.com> | 2014-09-23 15:31:56 +0000 |
commit | 52b5d76a6b0c5e4c779211fdf7bca56d87a2f83e (patch) | |
tree | ea4bae0dd4ba80e80ec8e540882c97df1988ce67 /py/parse.c | |
parent | d6230f62c785c6c1ef1797500617c33e24607980 (diff) | |
download | micropython-52b5d76a6b0c5e4c779211fdf7bca56d87a2f83e.tar.gz micropython-52b5d76a6b0c5e4c779211fdf7bca56d87a2f83e.zip |
py: Free non-interned strings in the parser when not needed.
mp_parse_node_free now frees the memory associated with non-interned
strings. And the parser calls mp_parse_node_free when discarding a
non-used node (such as a doc string).
Also, the compiler now frees the parse tree explicitly just before it
exits (as opposed to relying on the caller to do this).
Addresses issue #708 as best we can.
Diffstat (limited to 'py/parse.c')
-rw-r--r-- | py/parse.c | 5 |
1 files changed, 3 insertions, 2 deletions
diff --git a/py/parse.c b/py/parse.c index 26713dfe71..9508b82a02 100644 --- a/py/parse.c +++ b/py/parse.c @@ -179,6 +179,7 @@ void mp_parse_node_free(mp_parse_node_t pn) { mp_uint_t n = MP_PARSE_NODE_STRUCT_NUM_NODES(pns); mp_uint_t rule_id = MP_PARSE_NODE_STRUCT_KIND(pns); if (rule_id == RULE_string) { + m_del(char, (char*)pns->nodes[0], (mp_uint_t)pns->nodes[1]); return; } bool adjust = ADD_BLANK_NODE(rule_id); @@ -562,8 +563,8 @@ mp_parse_node_t mp_parse(mp_lexer_t *lex, mp_parse_input_kind_t input_kind, mp_p if (input_kind != MP_PARSE_SINGLE_INPUT && rule->rule_id == RULE_expr_stmt && peek_result(&parser, 0) == MP_PARSE_NODE_NULL) { mp_parse_node_t p = peek_result(&parser, 1); if ((MP_PARSE_NODE_IS_LEAF(p) && !MP_PARSE_NODE_IS_ID(p)) || MP_PARSE_NODE_IS_STRUCT_KIND(p, RULE_string)) { - pop_result(&parser); - pop_result(&parser); + pop_result(&parser); // MP_PARSE_NODE_NULL + mp_parse_node_free(pop_result(&parser)); // RULE_string push_result_rule(&parser, rule_src_line, rules[RULE_pass_stmt], 0); break; } |