> On 26 Sep 2014, at 03:31, Bob Rossi <b...@brasko.net> wrote: > A secondary concern I had with %destructor is how it worked when lists > are used in the bison grammar. I'm concerned about a double free. For > instance, > result_list: { > $$ = NULL; > }; > > result_list: result_list COMMA result { > $$ = append_gdbmi_result ($1, $3); > }; > > result: variable { > $$ = gdbmi_result_alloc(); > $$->variable = $1; > }; > > variable: STRING_LITERAL { > char *text = gdbmi_get_text(yyscanner); > $$ = strdup(text); > }; > > %destructor { gdbmi_result_free($$); } result_list > %destructor { gdbmi_result_free($$); } result > %destructor { free($$); } variable > > The %destructor for result and result_list does not call free, but > instead calls gdbmi_result_free. gdbmi_result_free free's the result > (including the variable member of the result), and the result's next > pointer, and so on. > > Is it correct for me to call gdbmi_result_free($$) instead of free($$)?
The %destructor is for making C style cleanup during an error recovery: the Bison generated parser will then skip forward, bypassing any normal deallocations in the actions. So first write the parser in normal C style, with deallocators in each instance matching the allocator used in the actions. Then add %destructor if needed for the error recovery. _______________________________________________ help-bison@gnu.org https://lists.gnu.org/mailman/listinfo/help-bison