This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Avoid a SEGV in DBI's test suite, discovered by Andreas.
[perl5.git] / perly_c.diff
1 --- perly.c.orig        Wed May 10 18:57:57 2006
2 +++ perly.c     Wed May 10 18:57:57 2006
3 @@ -1,5 +1,5 @@
4  #ifndef lint
5 -static char yysccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/91";
6 +/* static char yysccsid[] = "@(#)yaccpar 1.8 (Berkeley) 01/20/91"; */
7  #endif
8  #define YYBYACC 1
9  #line 25 "perly.y"
10 @@ -9,7 +9,7 @@
11  #ifdef EBCDIC
12  #undef YYDEBUG
13  #endif
14 -#define dep() deprecate("\"do\" to call subroutines")
15 +#define dep() deprecate_old("\"do\" to call subroutines")
16  
17  /* stuff included here to make perly_c.diff apply better */
18  
19 @@ -50,71 +50,9 @@
20  #define yylex yylex_r
21  #endif
22  
23 -#line 54 "y.tab.c"
24 -#define WORD 257
25 -#define METHOD 258
26 -#define FUNCMETH 259
27 -#define THING 260
28 -#define PMFUNC 261
29 -#define PRIVATEREF 262
30 -#define FUNC0SUB 263
31 -#define UNIOPSUB 264
32 -#define LSTOPSUB 265
33 -#define LABEL 266
34 -#define FORMAT 267
35 -#define SUB 268
36 -#define ANONSUB 269
37 -#define PACKAGE 270
38 -#define USE 271
39 -#define WHILE 272
40 -#define UNTIL 273
41 -#define IF 274
42 -#define UNLESS 275
43 -#define ELSE 276
44 -#define ELSIF 277
45 -#define CONTINUE 278
46 -#define FOR 279
47 -#define LOOPEX 280
48 -#define DOTDOT 281
49 -#define FUNC0 282
50 -#define FUNC1 283
51 -#define FUNC 284
52 -#define UNIOP 285
53 -#define LSTOP 286
54 -#define RELOP 287
55 -#define EQOP 288
56 -#define MULOP 289
57 -#define ADDOP 290
58 -#define DOLSHARP 291
59 -#define DO 292
60 -#define HASHBRACK 293
61 -#define NOAMP 294
62 -#define LOCAL 295
63 -#define MY 296
64 -#define MYSUB 297
65 -#define REQUIRE 298
66 -#define COLONATTR 299
67 -#define PREC_LOW 300
68 -#define OROP 301
69 -#define ANDOP 302
70 -#define NOTOP 303
71 -#define ASSIGNOP 304
72 -#define OROR 305
73 -#define ANDAND 306
74 -#define BITOROP 307
75 -#define BITANDOP 308
76 -#define SHIFTOP 309
77 -#define MATCHOP 310
78 -#define UMINUS 311
79 -#define REFGEN 312
80 -#define POWOP 313
81 -#define PREINC 314
82 -#define PREDEC 315
83 -#define POSTINC 316
84 -#define POSTDEC 317
85 -#define ARROW 318
86 +#line 54 "perly.c"
87  #define YYERRCODE 256
88 -short yylhs[] = {                                        -1,
89 +static short yylhs[] = {                                        -1,
90      0,   10,    8,    7,   11,    9,   12,   12,   12,   13,
91     13,   13,   13,   26,   26,   26,   26,   26,   26,   26,
92     16,   16,   16,   15,   15,   43,   43,   14,   14,   14,
93 @@ -136,7 +74,7 @@
94     49,   49,   49,   34,   34,   35,   35,   35,   44,   25,
95     20,   21,   22,   23,   24,   36,   36,   36,   36,
96  };
97 -short yylen[] = {                                         2,
98 +static short yylen[] = {                                         2,
99      2,    4,    0,    0,    4,    0,    0,    2,    2,    2,
100      1,    2,    3,    1,    1,    3,    3,    3,    3,    3,
101      0,    2,    6,    7,    7,    0,    2,    9,    9,   10,
102 @@ -158,7 +96,7 @@
103      1,    1,    1,    0,    1,    0,    1,    2,    1,    2,
104      2,    2,    2,    2,    2,    1,    1,    1,    1,
105  };
106 -short yydefred[] = {                                      4,
107 +static short yydefred[] = {                                      4,
108      0,    7,    0,   45,   58,   56,    0,   56,   56,    8,
109     46,    9,   11,   48,    0,   47,   49,   50,    0,    0,
110      0,   70,   71,    0,   14,    3,  175,    0,    0,  154,
111 @@ -200,7 +138,7 @@
112      0,   28,   29,    0,   22,    0,    0,    0,   31,    5,
113      0,   30,    0,    0,    0,    0,   33,   23,
114  };
115 -short yydgoto[] = {                                       1,
116 +static short yydgoto[] = {                                       1,
117     10,   11,   20,  105,   19,  359,    2,   96,  373,   99,
118    362,    3,   12,   13,   71,  376,  285,   73,   74,   75,
119     76,   77,   78,   79,   80,  292,   82,  293,  283,  234,
120 @@ -208,7 +146,7 @@
121    196,  328,  158,  290,  273,  227,   14,   84,  138,   85,
122     86,   87,   88,   15,   16,   17,   18,   94,  280,
123  };
124 -short yysindex[] = {                                      0,
125 +static short yysindex[] = {                                      0,
126      0,    0, -112,    0,    0,    0,  -47,    0,    0,    0,
127      0,    0,    0,    0,  651,    0,    0,    0, -214, -201,
128     44,    0,    0, -201,    0,    0,    0,  -13,  -13,    0,
129 @@ -250,7 +188,7 @@
130   -149,    0,    0,  591,    0, 2210, -149, 1761,    0,    0,
131    385,    0,  388,  290,  290, -124,    0,    0,
132  };
133 -short yyrindex[] = {                                      0,
134 +static short yyrindex[] = {                                      0,
135      0,    0,  466,    0,    0,    0,    0,    0,    0,    0,
136      0,    0,    0,    0,    0,    0,    0,    0,  302,    0,
137      0,    0,    0,    0,    0,    0,    0,    0,    0,    0,
138 @@ -292,7 +230,7 @@
139     71,    0,    0,  827,    0,    0,   71,  427,    0,    0,
140      0,    0,    0,    0,    0,  179,    0,    0,
141  };
142 -short yygindex[] = {                                      0,
143 +static short yygindex[] = {                                      0,
144      0,    0,  180,  444,    0, -308,    0,  -34,    0,   -6,
145   1062,  -94,    0,    0,    0, -343,  -15, 2478,    0, 2171,
146    428,  429,    0,    0,    0,  468,  423,    0,  148, -110,
147 @@ -301,7 +239,7 @@
148      0,    0,    0,    0,    0,    0,    0,    0,    0,
149  };
150  #define YYTABLESIZE 4871
151 -short yytable[] = {                                      72,
152 +static short yytable[] = {                                      72,
153     56,  199,  222,   66,   68,   54,   60,   61,   70,   69,
154     65,   22,   64,   66,  316,   60,  229,  112,  200,  377,
155    326,   62,   66,  277,  297,  230,  306,  360,   64,   15,
156 @@ -791,7 +729,7 @@
157      0,    0,    0,    0,    0,  112,  112,    0,  112,  112,
158    112,
159  };
160 -short yycheck[] = {                                      15,
161 +static short yycheck[] = {                                      15,
162     33,   96,   59,   36,   37,   38,  123,   40,   15,   42,
163     43,   59,   45,   36,   59,   59,   41,   40,  101,  363,
164     59,   59,   36,  201,   41,   93,   41,  336,   59,   41,
165 @@ -1287,7 +1225,7 @@
166  #endif
167  #define YYMAXTOKEN 318
168  #if YYDEBUG
169 -char *yyname[] = {
170 +static char *yyname[] = {
171  "end-of-file",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
172  "'!'",0,0,"'$'","'%'","'&'",0,"'('","')'","'*'","'+'","','","'-'",0,0,0,0,0,0,0,
173  0,0,0,0,0,"':'","';'",0,0,0,"'?'","'@'",0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,
174 @@ -1304,7 +1242,7 @@
175  "OROR","ANDAND","BITOROP","BITANDOP","SHIFTOP","MATCHOP","UMINUS","REFGEN",
176  "POWOP","PREINC","PREDEC","POSTINC","POSTDEC","ARROW",
177  };
178 -char *yyrule[] = {
179 +static char *yyrule[] = {
180  "$accept : prog",
181  "prog : progstart lineseq",
182  "block : '{' remember lineseq '}'",
183 @@ -1521,17 +1459,6 @@
184  #define YYMAXDEPTH 500
185  #endif
186  #endif
187 -int yydebug;
188 -int yynerrs;
189 -int yyerrflag;
190 -int yychar;
191 -short *yyssp;
192 -YYSTYPE *yyvsp;
193 -YYSTYPE yyval;
194 -YYSTYPE yylval;
195 -short yyss[YYSTACKSIZE];
196 -YYSTYPE yyvs[YYSTACKSIZE];
197 -#define yystacksize YYSTACKSIZE
198  #line 812 "perly.y"
199   /* PROGRAM */
200  
201 @@ -1542,7 +1469,7 @@
202  #endif
203  #define yyparse() Perl_yyparse(pTHX)
204  
205 -#line 1546 "y.tab.c"
206 +#line 1473 "perly.c"
207  #define YYABORT goto yyabort
208  #define YYACCEPT goto yyaccept
209  #define YYERROR goto yyerrlab
210 @@ -1550,11 +1477,31 @@
211  yyparse()
212  {
213      register int yym, yyn, yystate;
214 +    register short *yyssp;
215 +    register YYSTYPE *yyvsp;
216 +    short* yyss;
217 +    YYSTYPE* yyvs;
218 +    unsigned yystacksize = YYSTACKSIZE;
219 +    int retval = 0;
220  #if YYDEBUG
221      register char *yys;
222 -    extern char *getenv();
223 +#endif
224 +
225 +    struct ysv *ysave;
226 +#ifdef USE_ITHREADS
227 +    ENTER;                     /* force yydestruct() before we return */
228 +#endif
229 +    New(73, ysave, 1, struct ysv);
230 +    SAVEDESTRUCTOR_X(yydestruct, ysave);
231 +    ysave->oldyydebug  = yydebug;
232 +    ysave->oldyynerrs  = yynerrs;
233 +    ysave->oldyyerrflag        = yyerrflag;
234 +    ysave->oldyychar   = yychar;
235 +    ysave->oldyyval    = yyval;
236 +    ysave->oldyylval   = yylval;
237  
238 -    if (yys = getenv("YYDEBUG"))
239 +#if YYDEBUG
240 +    if ((yys = getenv("YYDEBUG")))
241      {
242          yyn = *yys;
243          if (yyn >= '0' && yyn <= '9')
244 @@ -1566,12 +1513,22 @@
245      yyerrflag = 0;
246      yychar = (-1);
247  
248 +    /*
249 +    ** Initialize private stacks (yyparse may be called from an action)
250 +    */
251 +    New(73, yyss, yystacksize, short);
252 +    New(73, yyvs, yystacksize, YYSTYPE);
253 +    ysave->yyss = yyss;
254 +    ysave->yyvs = yyvs;
255 +    if (!yyvs || !yyss)
256 +       goto yyoverflow;
257 +
258      yyssp = yyss;
259      yyvsp = yyvs;
260      *yyssp = yystate = 0;
261  
262  yyloop:
263 -    if (yyn = yydefred[yystate]) goto yyreduce;
264 +    if ((yyn = yydefred[yystate])) goto yyreduce;
265      if (yychar < 0)
266      {
267          if ((yychar = yylex()) < 0) yychar = 0;
268 @@ -1581,7 +1538,7 @@
269              yys = 0;
270              if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
271              if (!yys) yys = "illegal-symbol";
272 -            printf("yydebug: state %d, reading %d (%s)\n", yystate,
273 +            PerlIO_printf(Perl_debug_log, "yydebug: state %d, reading %d (%s)\n", yystate,
274                      yychar, yys);
275          }
276  #endif
277 @@ -1591,12 +1548,24 @@
278      {
279  #if YYDEBUG
280          if (yydebug)
281 -            printf("yydebug: state %d, shifting to state %d\n",
282 +            PerlIO_printf(Perl_debug_log, "yydebug: state %d, shifting to state %d\n",
283                      yystate, yytable[yyn]);
284  #endif
285          if (yyssp >= yyss + yystacksize - 1)
286          {
287 +           /*
288 +           ** reallocate and recover.  Note that pointers
289 +           ** have to be reset, or bad things will happen
290 +           */
291 +           int yyps_index = (yyssp - yyss);
292 +           int yypv_index = (yyvsp - yyvs);
293 +           yystacksize += YYSTACKSIZE;
294 +           ysave->yyvs = Renew(yyvs, yystacksize, YYSTYPE);
295 +           ysave->yyss = Renew(yyss, yystacksize, short);
296 +           if (!yyvs || !yyss)
297              goto yyoverflow;
298 +           yyssp = yyss + yyps_index;
299 +           yyvsp = yyvs + yypv_index;
300          }
301          *++yyssp = yystate = yytable[yyn];
302          *++yyvsp = yylval;
303 @@ -1612,14 +1581,14 @@
304      }
305      if (yyerrflag) goto yyinrecovery;
306  #ifdef lint
307 -    goto yynewerror;
308 +
309  #endif
310 -yynewerror:
311 +
312      yyerror("syntax error");
313  #ifdef lint
314 -    goto yyerrlab;
315 +
316  #endif
317 -yyerrlab:
318 +
319      ++yynerrs;
320  yyinrecovery:
321      if (yyerrflag < 3)
322 @@ -1632,12 +1601,24 @@
323              {
324  #if YYDEBUG
325                  if (yydebug)
326 -                    printf("yydebug: state %d, error recovery shifting\
327 +                    PerlIO_printf(Perl_debug_log, "yydebug: state %d, error recovery shifting\
328   to state %d\n", *yyssp, yytable[yyn]);
329  #endif
330                  if (yyssp >= yyss + yystacksize - 1)
331                  {
332 +                   /*
333 +                   ** reallocate and recover.  Note that pointers
334 +                   ** have to be reset, or bad things will happen
335 +                   */
336 +                   int yyps_index = (yyssp - yyss);
337 +                   int yypv_index = (yyvsp - yyvs);
338 +                   yystacksize += YYSTACKSIZE;
339 +                   ysave->yyvs = Renew(yyvs, yystacksize, YYSTYPE);
340 +                   ysave->yyss = Renew(yyss, yystacksize, short);
341 +                   if (!yyvs || !yyss)
342                      goto yyoverflow;
343 +                   yyssp = yyss + yyps_index;
344 +                   yyvsp = yyvs + yypv_index;
345                  }
346                  *++yyssp = yystate = yytable[yyn];
347                  *++yyvsp = yylval;
348 @@ -1647,7 +1628,7 @@
349              {
350  #if YYDEBUG
351                  if (yydebug)
352 -                    printf("yydebug: error recovery discarding state %d\n",
353 +                    PerlIO_printf(Perl_debug_log, "yydebug: error recovery discarding state %d\n",
354                              *yyssp);
355  #endif
356                  if (yyssp <= yyss) goto yyabort;
357 @@ -1665,7 +1646,7 @@
358              yys = 0;
359              if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
360              if (!yys) yys = "illegal-symbol";
361 -            printf("yydebug: state %d, error recovery discards token %d (%s)\n",
362 +            PerlIO_printf(Perl_debug_log, "yydebug: state %d, error recovery discards token %d (%s)\n",
363                      yystate, yychar, yys);
364          }
365  #endif
366 @@ -1675,7 +1656,7 @@
367  yyreduce:
368  #if YYDEBUG
369      if (yydebug)
370 -        printf("yydebug: state %d, reducing by rule %d (%s)\n",
371 +        PerlIO_printf(Perl_debug_log, "yydebug: state %d, reducing by rule %d (%s)\n",
372                  yystate, yyn, yyrule[yyn]);
373  #endif
374      yym = yylen[yyn];
375 @@ -2550,7 +2531,7 @@
376  #line 809 "perly.y"
377  { yyval.opval = yyvsp[0].opval; }
378  break;
379 -#line 2554 "y.tab.c"
380 +#line 2535 "perly.c"
381      }
382      yyssp -= yym;
383      yystate = *yyssp;
384 @@ -2560,7 +2541,7 @@
385      {
386  #if YYDEBUG
387          if (yydebug)
388 -            printf("yydebug: after reduction, shifting from state 0 to\
389 +            PerlIO_printf(Perl_debug_log, "yydebug: after reduction, shifting from state 0 to\
390   state %d\n", YYFINAL);
391  #endif
392          yystate = YYFINAL;
393 @@ -2575,7 +2556,7 @@
394                  yys = 0;
395                  if (yychar <= YYMAXTOKEN) yys = yyname[yychar];
396                  if (!yys) yys = "illegal-symbol";
397 -                printf("yydebug: state %d, reading %d (%s)\n",
398 +                PerlIO_printf(Perl_debug_log, "yydebug: state %d, reading %d (%s)\n",
399                          YYFINAL, yychar, yys);
400              }
401  #endif
402 @@ -2590,20 +2571,50 @@
403          yystate = yydgoto[yym];
404  #if YYDEBUG
405      if (yydebug)
406 -        printf("yydebug: after reduction, shifting from state %d \
407 +        PerlIO_printf(Perl_debug_log, "yydebug: after reduction, shifting from state %d \
408  to state %d\n", *yyssp, yystate);
409  #endif
410      if (yyssp >= yyss + yystacksize - 1)
411      {
412 +       /*
413 +       ** reallocate and recover.  Note that pointers
414 +       ** have to be reset, or bad things will happen
415 +       */
416 +       int yyps_index = (yyssp - yyss);
417 +       int yypv_index = (yyvsp - yyvs);
418 +       yystacksize += YYSTACKSIZE;
419 +       ysave->yyvs = Renew(yyvs, yystacksize, YYSTYPE);
420 +       ysave->yyss = Renew(yyss, yystacksize, short);
421 +       if (!yyvs || !yyss)
422          goto yyoverflow;
423 +       yyssp = yyss + yyps_index;
424 +       yyvsp = yyvs + yypv_index;
425      }
426      *++yyssp = yystate;
427      *++yyvsp = yyval;
428      goto yyloop;
429  yyoverflow:
430 -    yyerror("yacc stack overflow");
431 +    yyerror("Out of memory for yacc stack");
432  yyabort:
433 -    return (1);
434 +    retval = 1;
435  yyaccept:
436 -    return (0);
437 +#ifdef USE_ITHREADS
438 +    LEAVE;                     /* force yydestruct() before we return */
439 +#endif
440 +    return retval;
441 +}
442 +
443 +static void
444 +yydestruct(pTHX_ void *ptr)
445 +{
446 +    struct ysv* ysave = (struct ysv*)ptr;
447 +    if (ysave->yyss) Safefree(ysave->yyss);
448 +    if (ysave->yyvs) Safefree(ysave->yyvs);
449 +    yydebug    = ysave->oldyydebug;
450 +    yynerrs    = ysave->oldyynerrs;
451 +    yyerrflag  = ysave->oldyyerrflag;
452 +    yychar     = ysave->oldyychar;
453 +    yyval      = ysave->oldyyval;
454 +    yylval     = ysave->oldyylval;
455 +    Safefree(ysave);
456  }