This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Fix type mismatches in x2p's safe{alloc,realloc,free}.
[perl5.git] / perly.c.diff
CommitLineData
55497cff 1Index: perly.c
93a17b20 2***************
55497cff 3*** 12,83 ****
a0d0e21e
LW
4 deprecate("\"do\" to call subroutines");
5 }
6
748a9306 7- #line 29 "perly.y"
a0d0e21e
LW
8- typedef union {
9- I32 ival;
10- char *pval;
11- OP *opval;
12- GV *gvval;
13- } YYSTYPE;
14- #line 23 "y.tab.c"
15- #define WORD 257
16- #define METHOD 258
17- #define FUNCMETH 259
18- #define THING 260
19- #define PMFUNC 261
20- #define PRIVATEREF 262
4633a7c4
LW
21- #define FUNC0SUB 263
22- #define UNIOPSUB 264
23- #define LSTOPSUB 265
24- #define LABEL 266
25- #define FORMAT 267
26- #define SUB 268
27- #define ANONSUB 269
28- #define PACKAGE 270
29- #define USE 271
30- #define WHILE 272
31- #define UNTIL 273
32- #define IF 274
33- #define UNLESS 275
34- #define ELSE 276
35- #define ELSIF 277
36- #define CONTINUE 278
37- #define FOR 279
38- #define LOOPEX 280
39- #define DOTDOT 281
40- #define FUNC0 282
41- #define FUNC1 283
42- #define FUNC 284
43- #define RELOP 285
44- #define EQOP 286
45- #define MULOP 287
46- #define ADDOP 288
47- #define DOLSHARP 289
48- #define DO 290
55497cff 49- #define HASHBRACK 291
50- #define NOAMP 292
51- #define LOCAL 293
52- #define MY 294
53- #define OROP 295
54- #define ANDOP 296
55- #define NOTOP 297
56- #define LSTOP 298
57- #define ASSIGNOP 299
58- #define OROR 300
59- #define ANDAND 301
60- #define BITOROP 302
61- #define BITANDOP 303
62- #define UNIOP 304
63- #define SHIFTOP 305
64- #define MATCHOP 306
65- #define UMINUS 307
66- #define REFGEN 308
67- #define POWOP 309
68- #define PREINC 310
69- #define PREDEC 311
70- #define POSTINC 312
71- #define POSTDEC 313
72- #define ARROW 314
a0d0e21e
LW
73 #define YYERRCODE 256
74 short yylhs[] = { -1,
55497cff 75 40, 0, 7, 5, 8, 9, 6, 10, 10, 10,
a0d0e21e
LW
76--- 12,17 ----
77***************
55497cff 78*** 1316,1342 ****
93a17b20
LW
79 int yynerrs;
80 int yyerrflag;
81 int yychar;
82- short *yyssp;
83- YYSTYPE *yyvsp;
84 YYSTYPE yyval;
85 YYSTYPE yylval;
86- short yyss[YYSTACKSIZE];
87- YYSTYPE yyvs[YYSTACKSIZE];
88- #define yystacksize YYSTACKSIZE
55497cff 89 #line 631 "perly.y"
93a17b20 90 /* PROGRAM */
55497cff 91 #line 1329 "y.tab.c"
92 #define YYABORT goto yyabort
93 #define YYACCEPT goto yyaccept
94 #define YYERROR goto yyerrlab
95 int
96 yyparse()
97 {
98 register int yym, yyn, yystate;
99 #if YYDEBUG
100 register char *yys;
101 extern char *getenv();
102
103 if (yys = getenv("YYDEBUG"))
104 {
105 yyn = *yys;
106--- 1250,1316 ----
107 int yynerrs;
108 int yyerrflag;
109 int yychar;
110 YYSTYPE yyval;
111 YYSTYPE yylval;
112 #line 631 "perly.y"
113 /* PROGRAM */
114 #line 1329 "y.tab.c"
a0d0e21e
LW
115 #define YYABORT goto yyabort
116 #define YYACCEPT goto yyaccept
117 #define YYERROR goto yyerrlab
118+
119+ struct ysv {
120+ short* yyss;
121+ YYSTYPE* yyvs;
122+ int oldyydebug;
123+ int oldyynerrs;
124+ int oldyyerrflag;
125+ int oldyychar;
126+ YYSTYPE oldyyval;
127+ YYSTYPE oldyylval;
128+ };
129+
130+ void
131+ yydestruct(ptr)
132+ void* ptr;
133+ {
134+ struct ysv* ysave = (struct ysv*)ptr;
489bbe73 135+ if (ysave->yyss) Safefree(ysave->yyss);
136+ if (ysave->yyvs) Safefree(ysave->yyvs);
a0d0e21e
LW
137+ yydebug = ysave->oldyydebug;
138+ yynerrs = ysave->oldyynerrs;
139+ yyerrflag = ysave->oldyyerrflag;
140+ yychar = ysave->oldyychar;
141+ yyval = ysave->oldyyval;
142+ yylval = ysave->oldyylval;
489bbe73 143+ Safefree(ysave);
a0d0e21e
LW
144+ }
145+
146 int
93a17b20
LW
147 yyparse()
148 {
149 register int yym, yyn, yystate;
150+ register short *yyssp;
151+ register YYSTYPE *yyvsp;
152+ short* yyss;
153+ YYSTYPE* yyvs;
154+ unsigned yystacksize = YYSTACKSIZE;
93a17b20 155+ int retval = 0;
93a17b20
LW
156 #if YYDEBUG
157 register char *yys;
158 extern char *getenv();
a0d0e21e 159+ #endif
55497cff 160+
a0d0e21e
LW
161+ struct ysv *ysave = (struct ysv*)safemalloc(sizeof(struct ysv));
162+ SAVEDESTRUCTOR(yydestruct, ysave);
163+ ysave->oldyydebug = yydebug;
164+ ysave->oldyynerrs = yynerrs;
165+ ysave->oldyyerrflag = yyerrflag;
166+ ysave->oldyychar = yychar;
167+ ysave->oldyyval = yyval;
168+ ysave->oldyylval = yylval;
55497cff 169
a0d0e21e
LW
170+ #if YYDEBUG
171 if (yys = getenv("YYDEBUG"))
172 {
173 yyn = *yys;
93a17b20 174***************
55497cff 175*** 1349,1354 ****
176--- 1323,1336 ----
93a17b20
LW
177 yyerrflag = 0;
178 yychar = (-1);
179
180+ /*
181+ ** Initialize private stacks (yyparse may be called from an action)
182+ */
a0d0e21e
LW
183+ ysave->yyss = yyss = (short*)safemalloc(yystacksize*sizeof(short));
184+ ysave->yyvs = yyvs = (YYSTYPE*)safemalloc(yystacksize*sizeof(YYSTYPE));
93a17b20
LW
185+ if (!yyvs || !yyss)
186+ goto yyoverflow;
187+
188 yyssp = yyss;
189 yyvsp = yyvs;
190 *yyssp = yystate = 0;
191***************
55497cff 192*** 1364,1370 ****
ed6116ce
LW
193 yys = 0;
194 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
195 if (!yys) yys = "illegal-symbol";
196! printf("yydebug: state %d, reading %d (%s)\n", yystate,
197 yychar, yys);
198 }
199 #endif
55497cff 200--- 1346,1352 ----
ed6116ce
LW
201 yys = 0;
202 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
203 if (!yys) yys = "illegal-symbol";
204! fprintf(stderr, "yydebug: state %d, reading %d (%s)\n", yystate,
205 yychar, yys);
206 }
207 #endif
208***************
55497cff 209*** 1374,1385 ****
ed6116ce
LW
210 {
211 #if YYDEBUG
212 if (yydebug)
213! printf("yydebug: state %d, shifting to state %d\n",
214 yystate, yytable[yyn]);
93a17b20
LW
215 #endif
216 if (yyssp >= yyss + yystacksize - 1)
217 {
218! goto yyoverflow;
219 }
220 *++yyssp = yystate = yytable[yyn];
221 *++yyvsp = yylval;
55497cff 222--- 1356,1381 ----
ed6116ce
LW
223 {
224 #if YYDEBUG
225 if (yydebug)
226! fprintf(stderr, "yydebug: state %d, shifting to state %d\n",
227 yystate, yytable[yyn]);
93a17b20
LW
228 #endif
229 if (yyssp >= yyss + yystacksize - 1)
230 {
231! /*
232! ** reallocate and recover. Note that pointers
233! ** have to be reset, or bad things will happen
234! */
235! int yyps_index = (yyssp - yyss);
236! int yypv_index = (yyvsp - yyvs);
237! yystacksize += YYSTACKSIZE;
a0d0e21e
LW
238! ysave->yyvs = yyvs =
239! (YYSTYPE*)realloc((char*)yyvs,yystacksize * sizeof(YYSTYPE));
240! ysave->yyss = yyss =
241! (short*)realloc((char*)yyss,yystacksize * sizeof(short));
93a17b20
LW
242! if (!yyvs || !yyss)
243! goto yyoverflow;
244! yyssp = yyss + yyps_index;
245! yyvsp = yyvs + yypv_index;
246 }
247 *++yyssp = yystate = yytable[yyn];
248 *++yyvsp = yylval;
249***************
55497cff 250*** 1415,1426 ****
ed6116ce
LW
251 {
252 #if YYDEBUG
253 if (yydebug)
254! printf("yydebug: state %d, error recovery shifting\
255! to state %d\n", *yyssp, yytable[yyn]);
93a17b20
LW
256 #endif
257 if (yyssp >= yyss + yystacksize - 1)
258 {
259! goto yyoverflow;
260 }
261 *++yyssp = yystate = yytable[yyn];
262 *++yyvsp = yylval;
55497cff 263--- 1411,1437 ----
ed6116ce
LW
264 {
265 #if YYDEBUG
266 if (yydebug)
267! fprintf(stderr,
268! "yydebug: state %d, error recovery shifting to state %d\n",
269! *yyssp, yytable[yyn]);
93a17b20
LW
270 #endif
271 if (yyssp >= yyss + yystacksize - 1)
272 {
273! /*
274! ** reallocate and recover. Note that pointers
275! ** have to be reset, or bad things will happen
276! */
277! int yyps_index = (yyssp - yyss);
278! int yypv_index = (yyvsp - yyvs);
279! yystacksize += YYSTACKSIZE;
a0d0e21e 280! ysave->yyvs = yyvs = (YYSTYPE*)realloc((char*)yyvs,
93a17b20 281! yystacksize * sizeof(YYSTYPE));
a0d0e21e 282! ysave->yyss = yyss = (short*)realloc((char*)yyss,
93a17b20
LW
283! yystacksize * sizeof(short));
284! if (!yyvs || !yyss)
285! goto yyoverflow;
286! yyssp = yyss + yyps_index;
287! yyvsp = yyvs + yypv_index;
288 }
289 *++yyssp = yystate = yytable[yyn];
290 *++yyvsp = yylval;
291***************
55497cff 292*** 1430,1437 ****
ed6116ce
LW
293 {
294 #if YYDEBUG
295 if (yydebug)
296! printf("yydebug: error recovery discarding state %d\n",
297! *yyssp);
298 #endif
299 if (yyssp <= yyss) goto yyabort;
300 --yyssp;
55497cff 301--- 1441,1449 ----
ed6116ce
LW
302 {
303 #if YYDEBUG
304 if (yydebug)
305! fprintf(stderr,
306! "yydebug: error recovery discarding state %d\n",
307! *yyssp);
308 #endif
309 if (yyssp <= yyss) goto yyabort;
310 --yyssp;
311***************
55497cff 312*** 1448,1455 ****
ed6116ce
LW
313 yys = 0;
314 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
315 if (!yys) yys = "illegal-symbol";
316! printf("yydebug: state %d, error recovery discards token %d (%s)\n",
317! yystate, yychar, yys);
318 }
319 #endif
320 yychar = (-1);
55497cff 321--- 1460,1468 ----
ed6116ce
LW
322 yys = 0;
323 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
324 if (!yys) yys = "illegal-symbol";
325! fprintf(stderr,
326! "yydebug: state %d, error recovery discards token %d (%s)\n",
327! yystate, yychar, yys);
328 }
329 #endif
330 yychar = (-1);
331***************
55497cff 332*** 1458,1464 ****
ed6116ce
LW
333 yyreduce:
334 #if YYDEBUG
335 if (yydebug)
336! printf("yydebug: state %d, reducing by rule %d (%s)\n",
337 yystate, yyn, yyrule[yyn]);
338 #endif
339 yym = yylen[yyn];
55497cff 340--- 1471,1477 ----
ed6116ce
LW
341 yyreduce:
342 #if YYDEBUG
343 if (yydebug)
344! fprintf(stderr, "yydebug: state %d, reducing by rule %d (%s)\n",
345 yystate, yyn, yyrule[yyn]);
346 #endif
347 yym = yylen[yyn];
348***************
55497cff 349*** 2246,2253 ****
ed6116ce
LW
350 {
351 #if YYDEBUG
352 if (yydebug)
353! printf("yydebug: after reduction, shifting from state 0 to\
354! state %d\n", YYFINAL);
355 #endif
356 yystate = YYFINAL;
357 *++yyssp = YYFINAL;
55497cff 358--- 2259,2267 ----
ed6116ce
LW
359 {
360 #if YYDEBUG
361 if (yydebug)
362! fprintf(stderr,
363! "yydebug: after reduction, shifting from state 0 to state %d\n",
364! YYFINAL);
365 #endif
366 yystate = YYFINAL;
367 *++yyssp = YYFINAL;
368***************
55497cff 369*** 2261,2267 ****
ed6116ce
LW
370 yys = 0;
371 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
372 if (!yys) yys = "illegal-symbol";
373! printf("yydebug: state %d, reading %d (%s)\n",
374 YYFINAL, yychar, yys);
375 }
376 #endif
55497cff 377--- 2275,2281 ----
ed6116ce
LW
378 yys = 0;
379 if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
380 if (!yys) yys = "illegal-symbol";
381! fprintf(stderr, "yydebug: state %d, reading %d (%s)\n",
382 YYFINAL, yychar, yys);
383 }
384 #endif
385***************
55497cff 386*** 2276,2295 ****
ed6116ce
LW
387 yystate = yydgoto[yym];
388 #if YYDEBUG
389 if (yydebug)
390! printf("yydebug: after reduction, shifting from state %d \
391! to state %d\n", *yyssp, yystate);
93a17b20
LW
392 #endif
393 if (yyssp >= yyss + yystacksize - 1)
394 {
395! goto yyoverflow;
396 }
397 *++yyssp = yystate;
398 *++yyvsp = yyval;
399 goto yyloop;
400 yyoverflow:
401! yyerror("yacc stack overflow");
402 yyabort:
403! return (1);
404 yyaccept:
405! return (0);
406 }
55497cff 407--- 2290,2324 ----
ed6116ce
LW
408 yystate = yydgoto[yym];
409 #if YYDEBUG
410 if (yydebug)
411! fprintf(stderr,
412! "yydebug: after reduction, shifting from state %d to state %d\n",
413! *yyssp, yystate);
93a17b20
LW
414 #endif
415 if (yyssp >= yyss + yystacksize - 1)
416 {
417! /*
418! ** reallocate and recover. Note that pointers
419! ** have to be reset, or bad things will happen
420! */
421! int yyps_index = (yyssp - yyss);
422! int yypv_index = (yyvsp - yyvs);
423! yystacksize += YYSTACKSIZE;
a0d0e21e
LW
424! ysave->yyvs = yyvs =
425! (YYSTYPE*)realloc((char*)yyvs,yystacksize * sizeof(YYSTYPE));
426! ysave->yyss = yyss =
427! (short*)realloc((char*)yyss,yystacksize * sizeof(short));
93a17b20
LW
428! if (!yyvs || !yyss)
429! goto yyoverflow;
430! yyssp = yyss + yyps_index;
431! yyvsp = yyvs + yypv_index;
432 }
433 *++yyssp = yystate;
434 *++yyvsp = yyval;
435 goto yyloop;
436 yyoverflow:
437! yyerror("Out of memory for yacc stack");
438 yyabort:
439! retval = 1;
440 yyaccept:
93a17b20
LW
441! return retval;
442 }