diff options
author | Carl Worth <cworth@cworth.org> | 2010-05-10 11:52:29 -0700 |
---|---|---|
committer | Carl Worth <cworth@cworth.org> | 2010-05-10 11:52:29 -0700 |
commit | 38aa83560be3368b4e9784b3ef8f73144171ca45 (patch) | |
tree | dabb8d480013e9862396474656c008fb8b96306b | |
parent | 3a37b8701cd3e0a86fef59910b20b2af7e4573f6 (diff) |
Make the lexer reentrant (to avoid "still reachable" memory).
This allows the final program to be 100% "valgrind clean", (freeing
all memory that it allocates). This will make it much easier to ensure
that any allocation that parser actions perform are also cleaned up.
-rw-r--r-- | glcpp-lex.l | 2 | ||||
-rw-r--r-- | glcpp-parse.y | 7 | ||||
-rw-r--r-- | glcpp.c | 9 |
3 files changed, 14 insertions, 4 deletions
diff --git a/glcpp-lex.l b/glcpp-lex.l index 9779f2b92e..276f50ddfe 100644 --- a/glcpp-lex.l +++ b/glcpp-lex.l @@ -28,7 +28,7 @@ #include "glcpp-parse.h" %} -%option noyywrap +%option reentrant noyywrap %% diff --git a/glcpp-parse.y b/glcpp-parse.y index 739b2935b3..9acd549b24 100644 --- a/glcpp-parse.y +++ b/glcpp-parse.y @@ -28,10 +28,13 @@ #define YYSTYPE int void -yyerror (const char *error); +yyerror (const char *error, void *scanner); %} +%parse-param {void *scanner} +%lex-param {void *scanner} + %token TOKEN %% @@ -51,7 +54,7 @@ token: TOKEN %% void -yyerror (const char *error) +yyerror (const char *error, void *scanner) { fprintf (stderr, "Parse error: %s\n", error); } @@ -24,5 +24,12 @@ int main (void) { - return yyparse (); + int ret; + void *scanner; + + yylex_init (&scanner); + ret = yyparse (scanner); + yylex_destroy (scanner); + + return ret; } |