bug-bison
[Top][All Lists]
Advanced

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

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


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

Hi there,


I am currently using Bison 1.875c (compiled cleanly with gcc 3.2.2) to implement a reentrant GLR parser in C.  I am using many "%destructor" instructions on string (char*) types, such as this example extracted from my ircparser.y file:


----[SNIP]----

...

%union  /* data types */
{
    char chr;         /* character */
    char* str;        /* string */
}

...

%type <str> R_MESSAGE

...

%destructor
{
    printf("R_MESSAGE::dtor\n");
    free ($$);
    $$ = NULL;
} R_MESSAGE

...

----[SNIP]----

I've put simple "printf" statements in all my "%destructor"s, so I can verify that they get properly called when string (char*) types need to be freed.

While my grammar successfully gets translated in C by bison, then gets compiled properly by gcc, and is then executed with *NO* apparent errors in runtime, the "printf" statements never get displayed on screen, and the parser executable terminates [normally] and I finally get my unix prompt back (as expected).

It seems to me that the "%destructor"s are *NOT* called (as I would expect) to free the malloc'ed memory at the end of the runtime.

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 ?

I'd be glad to provide information regarding this issue if required.


Regards,


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

LINUX_LOGO




reply via email to

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