From 9142ade15416415f2d5eb20b093b898c649cd2bb Mon Sep 17 00:00:00 2001 From: Kenneth Graunke Date: Mon, 22 Oct 2012 10:56:46 -0700 Subject: glcpp: Don't use infinite lookhead for #define differentiation. Previously, we used lookahead patterns to differentiate: #define FOO(x) function macro #define FOO (x) object macro Unfortunately, our rule for function macros: {HASH}define{HSPACE}+/{IDENTIFIER}"(" relies on infinite lookahead, and apparently triggers a Flex bug where the generated code overflows a state buffer (see YY_STATE_BUF_SIZE). There's no need to use infinite lookahead. We can simply change state, match the identifier, and use a single character lookahead for the '('. This apparently makes Flex not generate the giant state array, which avoids the buffer overflow, and should be more efficient anyway. Fixes piglit test 17000-consecutive-chars-identifier.frag. NOTE: This is a candidate for every release branch ever. Signed-off-by: Kenneth Graunke Reviewed-by: Carl Worth --- src/glsl/glcpp/glcpp-lex.l | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) (limited to 'src/glsl/glcpp/glcpp-lex.l') diff --git a/src/glsl/glcpp/glcpp-lex.l b/src/glsl/glcpp/glcpp-lex.l index 7ab58cb288d..783c545495e 100644 --- a/src/glsl/glcpp/glcpp-lex.l +++ b/src/glsl/glcpp/glcpp-lex.l @@ -67,7 +67,7 @@ void glcpp_set_column (int column_no , yyscan_t yyscanner); %option stack %option never-interactive -%x DONE COMMENT UNREACHABLE SKIP +%x DONE COMMENT UNREACHABLE SKIP DEFINE SPACE [[:space:]] NONSPACE [^[:space:]] @@ -184,14 +184,22 @@ HEXADECIMAL_INTEGER 0[xX][0-9a-fA-F]+[uU]? glcpp_error(yylloc, yyextra, "#error%s", p); } -{HASH}define{HSPACE}+/{IDENTIFIER}"(" { +{HASH}define{HSPACE}+ { yyextra->space_tokens = 0; - return HASH_DEFINE_FUNC; + yy_push_state(DEFINE, yyscanner); + return HASH_DEFINE; } -{HASH}define { - yyextra->space_tokens = 0; - return HASH_DEFINE_OBJ; +{IDENTIFIER}/"(" { + yy_pop_state(yyscanner); + yylval->str = ralloc_strdup (yyextra, yytext); + return FUNC_IDENTIFIER; +} + +{IDENTIFIER} { + yy_pop_state(yyscanner); + yylval->str = ralloc_strdup (yyextra, yytext); + return OBJ_IDENTIFIER; } {HASH}undef { -- cgit v1.2.3