From 52b5d76a6b0c5e4c779211fdf7bca56d87a2f83e Mon Sep 17 00:00:00 2001 From: Damien George Date: Tue, 23 Sep 2014 15:31:56 +0000 Subject: 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. --- py/parse.c | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) (limited to 'py/parse.c') 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; } -- cgit v1.2.3