glcpp: Check version_resolved in the proper place.
authorMatt Turner <mattst88@gmail.com>
Sat, 25 Jan 2014 19:57:02 +0000 (11:57 -0800)
committerMatt Turner <mattst88@gmail.com>
Tue, 28 Jan 2014 05:15:35 +0000 (21:15 -0800)
The check was in the wrong place, such that if a shader incorrectly put
a preprocessor token before the #version declaration, the version would
be resolved twice, leading to a segmentation fault when attempting to
redefine the __VERSION__ macro.

 #extension GL_ARB_sample_shading: require
 #version 130
 void main() {}

Also, rename glcpp_parser_resolve_version to
             glcpp_parser_resolve_implicit_version to avoid confusion.

Reviewed-by: Jordan Justen <jordan.l.justen@intel.com>
Reviewed-by: Carl Worth <cworth@cworth.org>
Reviewed-by: Ian Romanick <ian.d.romanick@intel.com>
src/glsl/glcpp/glcpp-parse.y
src/glsl/glcpp/glcpp.h
src/glsl/glcpp/pp.c

index 8b486d21805949ade0cf975989bc574ab3c27356..2084c44e39401217559d8863ca5b9f7f8226e058 100644 (file)
@@ -194,7 +194,7 @@ line:
                ralloc_asprintf_rewrite_tail (&parser->output, &parser->output_length, "\n");
        }
 |      HASH_LINE {
-               glcpp_parser_resolve_version(parser);
+               glcpp_parser_resolve_implicit_version(parser);
        } pp_tokens NEWLINE {
 
                if (parser->skip_stack == NULL ||
@@ -254,10 +254,10 @@ define:
 
 control_line:
        HASH_DEFINE {
-               glcpp_parser_resolve_version(parser);
+               glcpp_parser_resolve_implicit_version(parser);
        } define
 |      HASH_UNDEF {
-               glcpp_parser_resolve_version(parser);
+               glcpp_parser_resolve_implicit_version(parser);
        } IDENTIFIER NEWLINE {
                macro_t *macro = hash_table_find (parser->defines, $3);
                if (macro) {
@@ -267,7 +267,7 @@ control_line:
                ralloc_free ($3);
        }
 |      HASH_IF {
-               glcpp_parser_resolve_version(parser);
+               glcpp_parser_resolve_implicit_version(parser);
        } conditional_tokens NEWLINE {
                /* Be careful to only evaluate the 'if' expression if
                 * we are not skipping. When we are skipping, we
@@ -299,14 +299,14 @@ control_line:
                _glcpp_parser_skip_stack_push_if (parser, & @1, 0);
        }
 |      HASH_IFDEF {
-               glcpp_parser_resolve_version(parser);
+               glcpp_parser_resolve_implicit_version(parser);
        } IDENTIFIER junk NEWLINE {
                macro_t *macro = hash_table_find (parser->defines, $3);
                ralloc_free ($3);
                _glcpp_parser_skip_stack_push_if (parser, & @1, macro != NULL);
        }
 |      HASH_IFNDEF {
-               glcpp_parser_resolve_version(parser);
+               glcpp_parser_resolve_implicit_version(parser);
        } IDENTIFIER junk NEWLINE {
                macro_t *macro = hash_table_find (parser->defines, $3);
                ralloc_free ($3);
@@ -380,7 +380,7 @@ control_line:
                _glcpp_parser_handle_version_declaration(parser, $2, $3, true);
        }
 |      HASH NEWLINE {
-               glcpp_parser_resolve_version(parser);
+               glcpp_parser_resolve_implicit_version(parser);
        }
 ;
 
@@ -2024,6 +2024,9 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
 {
        const struct gl_extensions *extensions = parser->extensions;
 
+       if (parser->version_resolved)
+               return;
+
        parser->version_resolved = true;
 
        add_builtin_define (parser, "__VERSION__", version);
@@ -2143,11 +2146,8 @@ _glcpp_parser_handle_version_declaration(glcpp_parser_t *parser, intmax_t versio
 #define IMPLICIT_GLSL_VERSION 110
 
 void
-glcpp_parser_resolve_version(glcpp_parser_t *parser)
+glcpp_parser_resolve_implicit_version(glcpp_parser_t *parser)
 {
-       if (parser->version_resolved)
-               return;
-
        _glcpp_parser_handle_version_declaration(parser, IMPLICIT_GLSL_VERSION,
                                                 NULL, false);
 }
index 4aa200a635dea457e3f4d30bc00fcdac26031e24..9d85c163f265a23a3385f37220c5e69fa7dfa433 100644 (file)
@@ -203,7 +203,7 @@ void
 glcpp_parser_destroy (glcpp_parser_t *parser);
 
 void
-glcpp_parser_resolve_version(glcpp_parser_t *parser);
+glcpp_parser_resolve_implicit_version(glcpp_parser_t *parser);
 
 int
 glcpp_preprocess(void *ralloc_ctx, const char **shader, char **info_log,
index 637a58f9cc391b2a4fdb10c7e8c28550f52bdae6..fc645f7a195ba02978f9034fb473ef60ee3725a6 100644 (file)
@@ -151,7 +151,7 @@ glcpp_preprocess(void *ralloc_ctx, const char **shader, char **info_log,
        if (parser->skip_stack)
                glcpp_error (&parser->skip_stack->loc, parser, "Unterminated #if\n");
 
-       glcpp_parser_resolve_version(parser);
+       glcpp_parser_resolve_implicit_version(parser);
 
        ralloc_strcat(info_log, parser->info_log);