summaryrefslogtreecommitdiff
path: root/glcpp-lex.l
diff options
context:
space:
mode:
authorCarl Worth <cworth@cworth.org>2010-05-12 12:45:33 -0700
committerCarl Worth <cworth@cworth.org>2010-05-12 12:47:29 -0700
commit5070a20cd1e65d52856bd74558f9a34f8dca114f (patch)
treea8cd5b178480c7b670b0a8e63ccd15dff190c7b3 /glcpp-lex.l
parent33cc400714f379ef13e876b4aedd0de8cb5d033d (diff)
Convert lexer to talloc and add xtalloc wrappers.
The lexer was previously using strdup (expecting the parser to free), but is now more consistent, easier to use, and slightly more efficent by using talloc along with the parser. Also, we add xtalloc and xtalloc_strdup wrappers around talloc and talloc_strdup to put all of the out-of-memory-checking code in one place.
Diffstat (limited to 'glcpp-lex.l')
-rw-r--r--glcpp-lex.l7
1 files changed, 4 insertions, 3 deletions
diff --git a/glcpp-lex.l b/glcpp-lex.l
index f1a3560779..ec91538a73 100644
--- a/glcpp-lex.l
+++ b/glcpp-lex.l
@@ -30,6 +30,7 @@
%}
%option reentrant noyywrap
+%option extra-type="glcpp_parser_t *"
%x ST_DEFINE
%x ST_DEFVAL
@@ -50,12 +51,12 @@ TOKEN {NONSPACE}+
}
<ST_DEFINE>{IDENTIFIER} {
- yylval.str = strdup (yytext);
+ yylval.str = xtalloc_strdup (yyextra, yytext);
return IDENTIFIER;
}
<ST_DEFINE>{TOKEN} {
- yylval.str = strdup (yytext);
+ yylval.str = xtalloc_strdup (yyextra, yytext);
return TOKEN;
}
@@ -68,7 +69,7 @@ TOKEN {NONSPACE}+
/* Anything we don't specifically recognize is a stream of tokens */
{NONSPACE}+ {
- yylval.str = strdup (yytext);
+ yylval.str = xtalloc_strdup (yyextra, yytext);
return TOKEN;
}