bison-patches
[Top][All Lists]
Advanced

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

Re: %destructor can leak the lookahead


From: Paul Eggert
Subject: Re: %destructor can leak the lookahead
Date: Thu, 02 Sep 2004 13:48:22 -0700
User-agent: Gnus/5.1006 (Gnus v5.10.6) Emacs/21.3 (gnu/linux)

Akim Demaille <address@hidden> writes:

> There is one case where %destructor is not triggered, but it should:
> when the error recovery just aborts when we were popping the stack and
> we reach its bottom.

Can you please explain this leak a bit more?  I just looked at yacc.c
and found these snippets:

                 YYPOPSTACK;
                 if (yyssp == yyss)
                   YYABORT;
                 YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
                 yydestruct (yystos[*yyssp], yyvsp]b4_location_if([, yylsp])[);
      ...
      if (yyssp == yyss)
        YYABORT;

      YYDSYMPRINTF ("Error: popping", yystos[*yyssp], yyvsp, yylsp);
      yydestruct (yystos[yystate], yyvsp]b4_location_if([, yylsp])[);

These bits of code make it look like yacc.c is destroying the stack
elements as it pops them.  What am I missing?  Is it that we need to
destroy the semantic value of the error token itself, before executing
the first code snippet quoted above?

I'm a bit rusty with this code, but I looked for other possible
places where %destructor should be triggered but isn't and found these:

* the stack overflows, and the user-defined yyoverflow macro refuses
  to extend the stack.  This does a YYABORT without invoking destructors.

* The user code invokes YYERROR.  This pops "yylen" items without
  destroying them.

> One way to fix this leak is to just add a destructor call right
> there.  Another would be to put this destructor call into yyabortlab.
> That would imply:
>
> - yydestruct can be called on EOF
>   So what?  It should not be defined, and if the user meant to define
>   it, there could be good reasons.

Sorry, I don't follow.  Why should yydestruct not be defined here?

> - yydestruct is called on the lookahead if the user explicitly calls
>   YYABORT.
>
> Because of this last reason, I'm tempted to release the lookahead at
> yyerrorlab.

Sorry, I still don't follow.  Perhaps I'm misunderstanding the meaning
of destructors in general.  From the documentation, destructors are
called for all symbols that are "discarded by the parser".  But an
ordinary reduce operation discards symbols, right?  So shouldn't
destructors be invoked every time the stack shrinks, no matter why it
shrinks?




reply via email to

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