aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEelco Dolstra <e.dolstra@tudelft.nl>2010-04-22 09:54:11 +0000
committerEelco Dolstra <e.dolstra@tudelft.nl>2010-04-22 09:54:11 +0000
commit2d7636529f782b552b634497fd8ac876aae72fcc (patch)
treea0f86d9ea99c7cd3aa5e3bbc567baca96f3f2c8a
parent6bbfe95e3012effa0df79066ae129ce9828a8ff2 (diff)
* String equality tests should take the context into account. All the
evaluation test cases now succeed.
-rw-r--r--src/libexpr/eval.cc14
-rw-r--r--src/libexpr/eval.hh2
2 files changed, 12 insertions, 4 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 0e4f2519a..9acd42310 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -1019,9 +1019,17 @@ bool EvalState::eqValues(Value & v1, Value & v2)
case tBool:
return v1.boolean == v2.boolean;
- case tString:
- /* !!! contexts */
- return strcmp(v1.string.s, v2.string.s) == 0;
+ case tString: {
+ /* Compare both the string and its context. */
+ if (strcmp(v1.string.s, v2.string.s) != 0) return false;
+ const char * * p = v1.string.context, * * q = v2.string.context;
+ if (!p && !q) return true;
+ if (!p || !q) return false;
+ for ( ; *p && *q; ++p, ++q)
+ if (strcmp(*p, *q) != 0) return false;
+ if (*p || *q) return false;
+ return true;
+ }
case tPath:
return strcmp(v1.path, v2.path) == 0;
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index aff68ea2a..2726fd971 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -69,7 +69,7 @@ struct Value
For canonicity, the store paths should be in sorted order. */
struct {
const char * s;
- const char * * context;
+ const char * * context; // must be in sorted order
} string;
const char * path;