Mesa (mesa_7_7_branch): glsl: fix preprocessor bug involving // -style comments in macro definitions
Brian Paul
brianp at kemper.freedesktop.org
Fri Jan 29 15:27:15 UTC 2010
Module: Mesa
Branch: mesa_7_7_branch
Commit: cb5447f79ca03d29407e8db84166f5bddd8d4c59
URL: http://cgit.freedesktop.org/mesa/mesa/commit/?id=cb5447f79ca03d29407e8db84166f5bddd8d4c59
Author: Brian Paul <brianp at vmware.com>
Date: Fri Jan 29 08:26:23 2010 -0700
glsl: fix preprocessor bug involving //-style comments in macro definitions
See comments for details.
---
src/mesa/shader/slang/slang_preprocess.c | 32 +++++++++++++++++++++++++++++-
1 files changed, 31 insertions(+), 1 deletions(-)
diff --git a/src/mesa/shader/slang/slang_preprocess.c b/src/mesa/shader/slang/slang_preprocess.c
index e9a24cc..ba40bad 100644
--- a/src/mesa/shader/slang/slang_preprocess.c
+++ b/src/mesa/shader/slang/slang_preprocess.c
@@ -914,6 +914,35 @@ parse_if (slang_string *output, const byte *prod, GLuint *pi, GLint *result, pp_
#define PRAGMA_PARAM 1
+/**
+ * Return the length of the given string, stopping at any C++-style comments.
+ * This step fixes bugs with macro definitions such as:
+ * #define PI 3.14159 // this is pi
+ * The preprocessor includes the comment in the definition of PI so
+ * when we plug in PI somewhere, we get the comment too.
+ * This function effectively strips of the // comment from the given string.
+ * It might also be possible to fix this in the preprocessor grammar.
+ * This bug is not present in the new Mesa 7.8 preprocessor.
+ */
+static int
+strlen_without_comments(const char *s)
+{
+ char pred = 0;
+ int len = 0;
+ while (*s) {
+ if (*s == '/' && pred == '/') {
+ return len - 1;
+ }
+ pred = *s;
+ s++;
+ len++;
+ }
+ return len;
+}
+
+
+
+
static GLboolean
preprocess_source (slang_string *output, const char *source,
grammar pid, grammar eid,
@@ -1055,11 +1084,12 @@ preprocess_source (slang_string *output, const char *source,
if (state.cond.top->effective) {
slang_string replacement;
expand_state es;
+ int idlen2 = strlen_without_comments((char*)id);
pp_annotate (output, ") %s", id);
slang_string_init(&replacement);
- slang_string_pushs(&replacement, id, idlen);
+ slang_string_pushs(&replacement, id, idlen2);
/* Expand macro replacement. */
es.output = &symbol->replacement;
More information about the mesa-commit
mailing list