aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-12-11 14:53:30 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-12-11 14:53:30 +0100
commitecb3a1afa2395c46c4ba2ec9da550f45414dbe6d (patch)
tree6d1038ee909bd1ba69948a0bc326cd5ba6824e01 /src/libexpr/eval.cc
parentab88f4bbd4117db458a79f0a02a4de7bf7931f4c (diff)
parentf800d450b78091835ab7ca67847d76e75d877a24 (diff)
Merge remote-tracking branch 'origin/master' into flakes
Diffstat (limited to 'src/libexpr/eval.cc')
-rw-r--r--src/libexpr/eval.cc49
1 files changed, 32 insertions, 17 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index ff7bce45e..cddbce20d 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -44,6 +44,19 @@ static char * dupString(const char * s)
}
+static char * dupStringWithLen(const char * s, size_t size)
+{
+ char * t;
+#if HAVE_BOEHMGC
+ t = GC_STRNDUP(s, size);
+#else
+ t = strndup(s, size);
+#endif
+ if (!t) throw std::bad_alloc();
+ return t;
+}
+
+
static void printValue(std::ostream & str, std::set<const Value *> & active, const Value & v)
{
checkInterrupt();
@@ -358,10 +371,10 @@ EvalState::EvalState(const Strings & _searchPath, ref<Store> store)
auto path = r.second;
if (store->isInStore(r.second)) {
- PathSet closure;
- store->computeFSClosure(store->toStorePath(r.second), closure);
+ StorePathSet closure;
+ store->computeFSClosure(store->parseStorePath(store->toStorePath(r.second)), closure);
for (auto & path : closure)
- allowedPaths->insert(path);
+ allowedPaths->insert(store->printStorePath(path));
} else
allowedPaths->insert(r.second);
}
@@ -585,9 +598,11 @@ void mkString(Value & v, const char * s)
}
-Value & mkString(Value & v, const string & s, const PathSet & context)
+Value & mkString(Value & v, std::string_view s, const PathSet & context)
{
- mkString(v, s.c_str());
+ v.type = tString;
+ v.string.s = dupStringWithLen(s.data(), s.size());
+ v.string.context = 0;
if (!context.empty()) {
size_t n = 0;
v.string.context = (const char * *)
@@ -1131,10 +1146,9 @@ void EvalState::callPrimOp(Value & fun, Value & arg, Value & v, const Pos & pos)
void EvalState::callFunction(Value & fun, Value & arg, Value & v, const Pos & pos)
{
- std::optional<FunctionCallTrace> trace;
- if (evalSettings.traceFunctionCalls) {
- trace.emplace(pos);
- }
+ std::unique_ptr<FunctionCallTrace> trace;
+ if (evalSettings.traceFunctionCalls)
+ trace = std::make_unique<FunctionCallTrace>(pos);
forceValue(fun, pos);
@@ -1680,15 +1694,16 @@ string EvalState::copyPathToStore(PathSet & context, const Path & path)
throwEvalError("file names are not allowed to end in '%1%'", drvExtension);
Path dstPath;
- if (srcToStore[path] != "")
- dstPath = srcToStore[path];
+ auto i = srcToStore.find(path);
+ if (i != srcToStore.end())
+ dstPath = store->printStorePath(i->second);
else {
- dstPath = settings.readOnlyMode
- ? store->computeStorePathForPath(baseNameOf(path), checkSourcePath(path)).first
- : store->addToStore(baseNameOf(path), checkSourcePath(path), true, htSHA256, defaultPathFilter, repair);
- srcToStore[path] = dstPath;
- printMsg(lvlChatty, format("copied source '%1%' -> '%2%'")
- % path % dstPath);
+ auto p = settings.readOnlyMode
+ ? store->computeStorePathForPath(std::string(baseNameOf(path)), checkSourcePath(path)).first
+ : store->addToStore(std::string(baseNameOf(path)), checkSourcePath(path), true, htSHA256, defaultPathFilter, repair);
+ dstPath = store->printStorePath(p);
+ srcToStore.insert_or_assign(path, std::move(p));
+ printMsg(lvlChatty, "copied source '%1%' -> '%2%'", path, dstPath);
}
context.insert(dstPath);