summaryrefslogtreecommitdiffstats
path: root/Parser/grammar.c
diff options
context:
space:
mode:
authorBenjamin Peterson <benjamin@python.org>2016-09-19 01:00:25 (GMT)
committerBenjamin Peterson <benjamin@python.org>2016-09-19 01:00:25 (GMT)
commit9ac11a752a19c3b8607582a3d5ccb615c467124b (patch)
treefbc0b8a54aed12fcbbfb7e4c11c8d8d1e4ca14dc /Parser/grammar.c
parent254ad58c0790f3bcf4ca510ba0e8a7c0f1546301 (diff)
downloadcpython-9ac11a752a19c3b8607582a3d5ccb615c467124b.zip
cpython-9ac11a752a19c3b8607582a3d5ccb615c467124b.tar.gz
cpython-9ac11a752a19c3b8607582a3d5ccb615c467124b.tar.bz2
properly free memory in pgen
Diffstat (limited to 'Parser/grammar.c')
-rw-r--r--Parser/grammar.c17
1 files changed, 17 insertions, 0 deletions
diff --git a/Parser/grammar.c b/Parser/grammar.c
index 84223c6..75fd5b9 100644
--- a/Parser/grammar.c
+++ b/Parser/grammar.c
@@ -28,6 +28,23 @@ newgrammar(int start)
return g;
}
+void
+freegrammar(grammar *g)
+{
+ int i;
+ for (i = 0; i < g->g_ndfas; i++) {
+ free(g->g_dfa[i].d_name);
+ for (int j = 0; j < g->g_dfa[i].d_nstates; j++)
+ PyObject_FREE(g->g_dfa[i].d_state[j].s_arc);
+ PyObject_FREE(g->g_dfa[i].d_state);
+ }
+ PyObject_FREE(g->g_dfa);
+ for (i = 0; i < g->g_ll.ll_nlabels; i++)
+ free(g->g_ll.ll_label[i].lb_str);
+ PyObject_FREE(g->g_ll.ll_label);
+ PyObject_FREE(g);
+}
+
dfa *
adddfa(grammar *g, int type, const char *name)
{