help-bison
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: %destructor and stack overflow


From: Marcus Holland-Moritz
Subject: Re: %destructor and stack overflow
Date: Sun, 1 May 2005 16:36:06 +0200

On 2005-05-01, at 06:28:46 -0700, Paul Eggert wrote:

> Thanks for the patch, but I suspect the code patch isn't quite general
> enough, since a similar problem occurs if the user invokes YYACCEPT or
> YYABORT.  How about this patch instead?

Yes, that's a lot better. My patch rather only fixed the stack
overflow case (plus, it added redundancy). I never looked at the
skeleton code before I noticed this particular problem, so I'm
not too familiar with it. :-)

Does the test part of my patch make any sense?

Thanks,
Marcus

> 2005-05-01  Paul Eggert  <address@hidden>
> 
>       * data/yacc.c (yyerrlab): Move the code that destroys the stack
>       from here....
>       (yyreturn): to here.  That way, destructors are called properly
>       even if the stack overflows, or the user calls YYACCEPT or
>       YYABORT.  Stack-overflow problem reported by Marcus Holland-Moritz.
>       (yyoverflowlab): Destroy the lookahead.
> 
> --- yacc.c.~1.86.~    2005-04-24 20:13:06 -0700
> +++ yacc.c    2005-05-01 06:12:32 -0700
> @@ -1203,15 +1203,7 @@ yyerrlab:
>            /* If at end of input, pop the error token,
>            then the rest of the stack, then return failure.  */
>         if (yychar == YYEOF)
> -          for (;;)
> -            {
> -]b4_location_if([[                 yyerror_range[0] = *yylsp;]])[
> -              YYPOPSTACK;
> -              if (yyssp == yyss)
> -                YYABORT;
> -              yydestruct (_("Error: popping"),
> -                             yystos[*yyssp], yyvsp]b4_location_if([, 
> yylsp])[);
> -            }
> +         YYABORT;
>          }
>        else
>       {
> @@ -1316,11 +1308,23 @@ yyabortlab:
>  `----------------------------------------------*/
>  yyoverflowlab:
>    yyerror (]b4_yyerror_args[_("parser stack overflow"));
> +  yydestruct (_("Error: discarding lookahead"),
> +           yytoken, &yylval]b4_location_if([, &yylloc])[);
>    yyresult = 2;
>    /* Fall through.  */
>  #endif
>  
>  yyreturn:
> +  if (yyssp != yyss)
> +    for (;;)
> +      {
> +]b4_location_if([[   yyerror_range[0] = *yylsp;]])[
> +     YYPOPSTACK;
> +     if (yyssp == yyss)
> +       break;
> +     yydestruct (_("Error: popping"),
> +                 yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
> +      }
>  #ifndef yyoverflow
>    if (yyss != yyssa)
>      YYSTACK_FREE (yyss);




reply via email to

[Prev in Thread] Current Thread [Next in Thread]