]> git.saurik.com Git - bison.git/blob - tests/push.at
In impure push mode, don't allow more than one yypstate to be allocated
[bison.git] / tests / push.at
1 # Checking Push Parsing. -*- Autotest -*-
2 # Copyright (C) 2007 Free Software Foundation, Inc.
3
4 # This program is free software: you can redistribute it and/or modify
5 # it under the terms of the GNU General Public License as published by
6 # the Free Software Foundation, either version 3 of the License, or
7 # (at your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful,
10 # but WITHOUT ANY WARRANTY; without even the implied warranty of
11 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 # GNU General Public License for more details.
13 #
14 # You should have received a copy of the GNU General Public License
15 # along with this program. If not, see <http://www.gnu.org/licenses/>.
16
17 AT_BANNER([[Push Parsing Tests]])
18
19 ## ---------------------------------------------- ##
20 ## Push Parsing: Memory Leak for Early Deletion. ##
21 ## ---------------------------------------------- ##
22
23 AT_SETUP([[Push Parsing: Memory Leak for Early Deletion]])
24
25 # Requires Valgrind.
26
27 AT_DATA_GRAMMAR([[input.y]],
28 [[
29 %{
30 #include <assert.h>
31 #include <stdio.h>
32 #define YYINITDEPTH 1
33 void yyerror (char const *msg);
34 %}
35
36 %pure-parser %push-parser
37
38 %%
39
40 start: 'a' 'b' 'c' ;
41
42 %%
43
44 void
45 yyerror (char const *msg)
46 {
47 fprintf (stderr, "%s\n", msg);
48 }
49
50 int
51 main (void)
52 {
53 yypstate *ps;
54
55 /* Make sure we don't try to free ps->yyss in this case. */
56 ps = yypstate_new ();
57 yypstate_delete (ps);
58
59 /* yypstate_delete used to leak ps->yyss if the stack was reallocated but the
60 parse did not return on success, syntax error, or memory exhaustion. */
61 ps = yypstate_new ();
62 assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
63 yypstate_delete (ps);
64
65 ps = yypstate_new ();
66 assert (yypush_parse (ps, 'a', NULL) == YYPUSH_MORE);
67 assert (yypush_parse (ps, 'b', NULL) == YYPUSH_MORE);
68 yypstate_delete (ps);
69
70 return 0;
71 }
72 ]])
73
74 AT_CHECK([[bison -o input.c input.y]])
75 AT_COMPILE([[input]])
76 AT_PARSER_CHECK([[./input]])
77
78 AT_CLEANUP
79
80
81 ## ----------------------------------------- ##
82 ## Push Parsing: Multiple impure instances. ##
83 ## ----------------------------------------- ##
84
85 AT_SETUP([[Push Parsing: Multiple impure instances]])
86
87 AT_DATA_GRAMMAR([[input.y]],
88 [[
89 %{
90 #include <assert.h>
91 #include <stdio.h>
92 void yyerror (char const *msg);
93 int yylex (void);
94 %}
95
96 %push-pull-parser
97
98 %%
99
100 start: ;
101
102 %%
103
104 void
105 yyerror (char const *msg)
106 {
107 fprintf (stderr, "%s\n", msg);
108 }
109
110 int
111 yylex (void)
112 {
113 return 0;
114 }
115
116 int
117 main (void)
118 {
119 yypstate *ps;
120 int i;
121
122 for (i = 0; i < 2; ++i)
123 {
124 ps = yypstate_new ();
125 assert (ps);
126 assert (yypstate_new () == NULL);
127 assert (yyparse () == 2);
128 yychar = 0;
129 assert (yypush_parse (ps) == 0);
130 assert (yypstate_new () == NULL);
131 assert (yyparse () == 2);
132 yypstate_delete (ps);
133 }
134
135 return 0;
136 }
137 ]])
138
139 AT_CHECK([[bison -o input.c input.y]])
140 AT_COMPILE([[input]])
141 AT_PARSER_CHECK([[./input]], 0, [],
142 [[cannot allocate multiple impure push-parser instances
143 cannot allocate multiple impure push-parser instances
144 cannot allocate multiple impure push-parser instances
145 cannot allocate multiple impure push-parser instances
146 cannot allocate multiple impure push-parser instances
147 cannot allocate multiple impure push-parser instances
148 cannot allocate multiple impure push-parser instances
149 cannot allocate multiple impure push-parser instances
150 ]])
151
152 AT_CLEANUP