Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
9ac11a75
Commit
9ac11a75
authored
Sep 18, 2016
by
Benjamin Peterson
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
properly free memory in pgen
parent
254ad58c
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
35 additions
and
2 deletions
+35
-2
Include/grammar.h
Include/grammar.h
+1
-0
Parser/grammar.c
Parser/grammar.c
+17
-0
Parser/pgen.c
Parser/pgen.c
+16
-2
Parser/pgenmain.c
Parser/pgenmain.c
+1
-0
No files found.
Include/grammar.h
View file @
9ac11a75
...
@@ -69,6 +69,7 @@ typedef struct {
...
@@ -69,6 +69,7 @@ typedef struct {
/* FUNCTIONS */
/* FUNCTIONS */
grammar
*
newgrammar
(
int
start
);
grammar
*
newgrammar
(
int
start
);
void
freegrammar
(
grammar
*
g
);
dfa
*
adddfa
(
grammar
*
g
,
int
type
,
const
char
*
name
);
dfa
*
adddfa
(
grammar
*
g
,
int
type
,
const
char
*
name
);
int
addstate
(
dfa
*
d
);
int
addstate
(
dfa
*
d
);
void
addarc
(
dfa
*
d
,
int
from
,
int
to
,
int
lbl
);
void
addarc
(
dfa
*
d
,
int
from
,
int
to
,
int
lbl
);
...
...
Parser/grammar.c
View file @
9ac11a75
...
@@ -28,6 +28,23 @@ newgrammar(int start)
...
@@ -28,6 +28,23 @@ newgrammar(int start)
return
g
;
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
*
dfa
*
adddfa
(
grammar
*
g
,
int
type
,
const
char
*
name
)
adddfa
(
grammar
*
g
,
int
type
,
const
char
*
name
)
{
{
...
...
Parser/pgen.c
View file @
9ac11a75
...
@@ -117,6 +117,16 @@ newnfagrammar(void)
...
@@ -117,6 +117,16 @@ newnfagrammar(void)
return
gr
;
return
gr
;
}
}
static
void
freenfagrammar
(
nfagrammar
*
gr
)
{
for
(
int
i
=
0
;
i
<
gr
->
gr_nnfas
;
i
++
)
{
PyObject_FREE
(
gr
->
gr_nfa
[
i
]
->
nf_state
);
}
PyObject_FREE
(
gr
->
gr_nfa
);
PyObject_FREE
(
gr
);
}
static
nfa
*
static
nfa
*
addnfa
(
nfagrammar
*
gr
,
char
*
name
)
addnfa
(
nfagrammar
*
gr
,
char
*
name
)
{
{
...
@@ -488,7 +498,11 @@ makedfa(nfagrammar *gr, nfa *nf, dfa *d)
...
@@ -488,7 +498,11 @@ makedfa(nfagrammar *gr, nfa *nf, dfa *d)
convert
(
d
,
xx_nstates
,
xx_state
);
convert
(
d
,
xx_nstates
,
xx_state
);
/* XXX cleanup */
for
(
int
i
=
0
;
i
<
xx_nstates
;
i
++
)
{
for
(
int
j
=
0
;
j
<
xx_state
[
i
].
ss_narcs
;
j
++
)
delbitset
(
xx_state
[
i
].
ss_arc
[
j
].
sa_bitset
);
PyObject_FREE
(
xx_state
[
i
].
ss_arc
);
}
PyObject_FREE
(
xx_state
);
PyObject_FREE
(
xx_state
);
}
}
...
@@ -669,7 +683,7 @@ pgen(node *n)
...
@@ -669,7 +683,7 @@ pgen(node *n)
g
=
maketables
(
gr
);
g
=
maketables
(
gr
);
translatelabels
(
g
);
translatelabels
(
g
);
addfirstsets
(
g
);
addfirstsets
(
g
);
PyObject_FREE
(
gr
);
freenfagrammar
(
gr
);
return
g
;
return
g
;
}
}
...
...
Parser/pgenmain.c
View file @
9ac11a75
...
@@ -80,6 +80,7 @@ main(int argc, char **argv)
...
@@ -80,6 +80,7 @@ main(int argc, char **argv)
printf
(
"Writing %s ...
\n
"
,
graminit_h
);
printf
(
"Writing %s ...
\n
"
,
graminit_h
);
printnonterminals
(
g
,
fp
);
printnonterminals
(
g
,
fp
);
fclose
(
fp
);
fclose
(
fp
);
freegrammar
(
g
);
Py_Exit
(
0
);
Py_Exit
(
0
);
return
0
;
/* Make gcc -Wall happy */
return
0
;
/* Make gcc -Wall happy */
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment