bug-bison
[Top][All Lists]
Advanced

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

patch submission: free memory on errors


From: Keith Reynolds
Subject: patch submission: free memory on errors
Date: Mon, 25 Jun 2001 20:49:54 -0700

I have a parser that builds a parse tree for later use, calling 
malloc() to create the nodes of the tree as it goes.  Unfortunately, 
there is no way for me to provide a function that gets called when a 
parse error is encountered, and no way for me to access bison's 
internal value stack to free the memory.

So, I made the following changes to bison.simple: If a macro YYFREE 
is defined, it is called with the current yylval when an error is 
encountered, and with each element of the value stack as it unwinds 
in search of a rule that handles the error token.  In order to avoid 
double YYFREE() calls, I had to NULL yylval after it gets added to 
the value stack in a couple places.

This code is working quite well for my parser, but I'd be quite 
willing to believe that there are other cases that are broken by 
this; I'm much more of a networking programmer than a compiler 
writer.  All new code is under #ifdef YYFREE, so parsers that don't 
define that should be unaffected.  Comments and suggestions welcome.

Keith R.

PS: Thank you, whomever, for providing the BISON_SIMPLE environment 
variable, so I can put the modified version into my source tree, 
enabling the other developers on the project to compile the parser on 
their machines without modifying bison's system files.

Attachment: bison.simple.diffs
Description: Text document


reply via email to

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