[Top][All Lists]

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

Re: [Question / Bison 1.875c]: %destructorS not being called at all?

From: Jeannot_Langlois
Subject: Re: [Question / Bison 1.875c]: %destructorS not being called at all?
Date: Thu, 04 Mar 2004 20:02:17 -0500
User-agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.0.2) Gecko/20030208 Netscape/7.02

Tim Van Holder wrote:
Jeannot_Langlois wrote:

Shouldn't these "%destructor"s be called automatically?  Or am I doing something wrong (or misunderstanding anything)?  In either case, has anybody seen this behavior before, and how can I ensure that memory allocated by "malloc" in semantic actions gets properly freed by "%destructor"s ?

As I understand it, the %destructors are only called if the parser needs
to throw away a token.  If your parser didn't have an error condition,
or a parser split in the case of GLR, the parser will probably have
successfully passed the tokens to the actions you defined.  As such, it
didn't throw any tokens away and didn't call %destructor.  The moment
tokens reach action code (even the default action) it becomes your job
to clean them up (typically you will place token values in a parse tree
of some sort, and you don't want bison to deallocate parts of it behind
your back).
Also see the 'Destructor Decl' topic in the bison info file.

Hmmm, okay !  That makes sense too.

I just thought that the tokens would need to be COPIED (that is, reallocated when inserted) in an AST (and would be freed in my semantic analyzer's address space later when no longer needed), so bison would need to free them up to avoid memory leaks.  

Now I realize that I didn't got it the right way.  Then I'll just need to make sure they are freed when the AST gets destroyed later.

Thanks for your explanations on this,

Jeannot Langlois - Signature Jeannot Langlois
B. Sc.  Computer Science / B. Sc.  Informatique
Software Developer / Programmeur-Analyste
System/Network Administrator / Administrateur Système/Réseau


reply via email to

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