[antlr-interest] Updates for release 3.2 of the C Target
David-Sarah Hopwood
david-sarah at jacaranda.org
Wed Sep 23 17:31:49 PDT 2009
Jim Idle wrote:
> The following should be read carefully before upgrading to release 3.2
> of the C target:
[...]
> * finally - this code is executed whether the rule parses
> successfully or not. This is probably where you should free
> allocations, but you should guard against uninitialized elements,
> which may not have been created on a parse error.
Are such elements (not variables that you declare yourself) guaranteed
to be NULL?
> * Because you can end up executing both @after and finally code, use
> safe programming patterns (you should be anyway ;-, and assign
> NULL to anything after declaring it and immediately before freeing
> it.
You mean immediately after freeing it :-)
(i.e. "free(foo); foo = NULL;")
> Also, guard against free(NULL) unless the semantics of your
> system specify that free(NULL) is allowed.
"free(NULL)" is defined to be a no-op by the C standard. A libc
implementation that got this wrong would be badly broken, and AFAIK all
the commonly used platforms get it right.
--
David-Sarah Hopwood ⚥ http://davidsarah.livejournal.com
More information about the antlr-interest
mailing list