diff options
Diffstat (limited to 'third_party/nix/src/libexpr')
-rw-r--r-- | third_party/nix/src/libexpr/attr-path.cc | 2 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/eval.cc | 55 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/get-drvs.cc | 7 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/names.cc | 4 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/names.hh | 2 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/nixexpr.cc | 14 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/parser.cc | 19 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops.cc | 45 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops/context.cc | 13 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops/fetchGit.cc | 32 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops/fetchMercurial.cc | 20 | ||||
-rw-r--r-- | third_party/nix/src/libexpr/primops/fromTOML.cc | 26 |
12 files changed, 106 insertions, 133 deletions
diff --git a/third_party/nix/src/libexpr/attr-path.cc b/third_party/nix/src/libexpr/attr-path.cc index 07ffebff1ad3..a267e82b6ebe 100644 --- a/third_party/nix/src/libexpr/attr-path.cc +++ b/third_party/nix/src/libexpr/attr-path.cc @@ -51,7 +51,7 @@ Value* findAlongAttrPath(EvalState& state, const std::string& attrPath, for (auto& attr : tokens) { /* Is i an index (integer) or a normal attribute name? */ enum { apAttr, apIndex } apType = apAttr; - unsigned int attrIndex = 0; + unsigned int attrIndex; if (absl::SimpleAtoi(attr, &attrIndex)) { apType = apIndex; } diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc index 6195b30be741..0afa7567bbda 100644 --- a/third_party/nix/src/libexpr/eval.cc +++ b/third_party/nix/src/libexpr/eval.cc @@ -36,7 +36,7 @@ namespace nix { static char* dupString(const char* s) { - char* t = nullptr; + char* t; t = GC_STRDUP(s); if (t == nullptr) { throw std::bad_alloc(); @@ -199,7 +199,7 @@ static Symbol getName(const AttrName& name, EvalState& state, Env& env) { return std::visit( util::overloaded{[&](const Symbol& name) -> Symbol { return name; }, [&](Expr* expr) -> Symbol { - Value nameValue{}; + Value nameValue; expr->eval(state, env, nameValue); state.forceStringNoCtx(nameValue); return state.symbols.Create(nameValue.string.s); @@ -478,7 +478,7 @@ Value* EvalState::addConstant(const std::string& name, Value& v) { Value* EvalState::addPrimOp(const std::string& name, size_t arity, PrimOpFun primOp) { if (arity == 0) { - Value v{}; + Value v; primOp(*this, noPos, nullptr, v); return addConstant(name, v); } @@ -577,8 +577,8 @@ Value& mkString(Value& v, const std::string& s, const PathSet& context) { mkString(v, s.c_str()); if (!context.empty()) { size_t n = 0; - v.string.context = static_cast<const char**>( - allocBytes((context.size() + 1) * sizeof(char*))); + v.string.context = + (const char**)allocBytes((context.size() + 1) * sizeof(char*)); for (auto& i : context) { v.string.context[n++] = dupString(i.c_str()); } @@ -772,7 +772,7 @@ void EvalState::resetFileCache() { void EvalState::eval(Expr* e, Value& v) { e->eval(*this, baseEnv, v); } inline bool EvalState::evalBool(Env& env, Expr* e) { - Value v{}; + Value v; e->eval(*this, env, v); if (v.type != tBool) { throwTypeError("value is %1% while a Boolean was expected", v); @@ -781,7 +781,7 @@ inline bool EvalState::evalBool(Env& env, Expr* e) { } inline bool EvalState::evalBool(Env& env, Expr* e, const Pos& pos) { - Value v{}; + Value v; e->eval(*this, env, v); if (v.type != tBool) { throwTypeError("value is %1% while a Boolean was expected, at %2%", v, pos); @@ -822,7 +822,7 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& value) { in the original environment. */ size_t displ = 0; for (auto& attr : attrs) { - Value* vAttr = nullptr; + Value* vAttr; vAttr = attr.second.e->maybeThunk(state, attr.second.inherited ? env : env2); env2.values[displ++] = vAttr; @@ -838,7 +838,7 @@ void ExprAttrs::eval(EvalState& state, Env& env, Value& value) { /* Dynamic attrs apply *after* rec. */ for (auto& i : dynamicAttrs) { - Value nameVal{}; + Value nameVal; i.nameExpr->eval(state, *dynamicEnv, nameVal); state.forceValue(nameVal, i.pos); if (nameVal.type == tNull) { @@ -906,7 +906,7 @@ static std::string showAttrPath(EvalState& state, Env& env, unsigned long nrLookups = 0; void ExprSelect::eval(EvalState& state, Env& env, Value& v) { - Value vTmp{}; + Value vTmp; Pos* pos2 = nullptr; Value* vAttrs = &vTmp; @@ -957,7 +957,7 @@ void ExprSelect::eval(EvalState& state, Env& env, Value& v) { } void ExprOpHasAttr::eval(EvalState& state, Env& env, Value& v) { - Value vTmp{}; + Value vTmp; Value* vAttrs = &vTmp; e->eval(state, env, vTmp); @@ -985,7 +985,7 @@ void ExprLambda::eval(EvalState& state, Env& env, Value& v) { void ExprApp::eval(EvalState& state, Env& env, Value& v) { /* FIXME: vFun prevents GCC from doing tail call optimisation. */ - Value vFun{}; + Value vFun; e1->eval(state, env, vFun); state.callFunction(vFun, *(e2->maybeThunk(state, env)), v, pos); } @@ -1053,7 +1053,7 @@ void EvalState::callFunction(Value& fun, Value& arg, Value& v, const Pos& pos) { auto& fun2 = *allocValue(); fun2 = fun; /* !!! Should we use the attr pos here? */ - Value v2{}; + Value v2; // functors are called with the element itself as the first // parameter, which is partially applied here callFunction(*found->second.value, fun2, v2, pos); @@ -1210,17 +1210,17 @@ void ExprOpNot::eval(EvalState& state, Env& env, Value& v) { } void ExprOpEq::eval(EvalState& state, Env& env, Value& v) { - Value v1{}; + Value v1; e1->eval(state, env, v1); - Value v2{}; + Value v2; e2->eval(state, env, v2); mkBool(v, state.eqValues(v1, v2)); } void ExprOpNEq::eval(EvalState& state, Env& env, Value& v) { - Value v1{}; + Value v1; e1->eval(state, env, v1); - Value v2{}; + Value v2; e2->eval(state, env, v2); mkBool(v, !state.eqValues(v1, v2)); } @@ -1238,8 +1238,8 @@ void ExprOpImpl::eval(EvalState& state, Env& env, Value& v) { } void ExprOpUpdate::eval(EvalState& state, Env& env, Value& dest) { - Value v1{}; - Value v2{}; + Value v1; + Value v2; state.evalAttrs(env, e1, v1); state.evalAttrs(env, e2, v2); @@ -1251,9 +1251,9 @@ void ExprOpUpdate::eval(EvalState& state, Env& env, Value& dest) { } void ExprOpConcatLists::eval(EvalState& state, Env& env, Value& v) { - Value v1{}; + Value v1; e1->eval(state, env, v1); - Value v2{}; + Value v2; e2->eval(state, env, v2); state.concatLists(v, {&v1, &v2}, pos); } @@ -1281,7 +1281,7 @@ void ExprConcatStrings::eval(EvalState& state, Env& env, Value& v) { ValueType firstType = tString; for (auto& i : *es) { - Value vTmp{}; + Value vTmp; i->eval(state, env, vTmp); /* If the first element is a path, then the result will also @@ -1488,7 +1488,7 @@ std::optional<std::string> EvalState::tryAttrsToString(const Pos& pos, Value& v, bool copyToStore) { auto i = v.attrs->find(sToString); if (i != v.attrs->end()) { - Value v1{}; + Value v1; callFunction(*i->second.value, v, v1, pos); return coerceToString(pos, v1, context, coerceMore, copyToStore); } @@ -1701,10 +1701,9 @@ bool EvalState::eqValues(Value& v1, Value& v2) { void EvalState::printStats() { bool showStats = getEnv("NIX_SHOW_STATS", "0") != "0"; - struct rusage buf {}; + struct rusage buf; getrusage(RUSAGE_SELF, &buf); - float cpuTime = buf.ru_utime.tv_sec + - (static_cast<float>(buf.ru_utime.tv_usec) / 1000000); + float cpuTime = buf.ru_utime.tv_sec + ((float)buf.ru_utime.tv_usec / 1000000); uint64_t bEnvs = nrEnvs * sizeof(Env) + nrValuesInEnvs * sizeof(Value*); uint64_t bLists = nrListElems * sizeof(Value*); @@ -1713,8 +1712,8 @@ void EvalState::printStats() { nrAttrsets * sizeof(Bindings) + nrAttrsInAttrsets * sizeof(Attr); #if HAVE_BOEHMGC - GC_word heapSize = 0; - GC_word totalBytes = 0; + GC_word heapSize; + GC_word totalBytes; GC_get_heap_usage_safe(&heapSize, nullptr, nullptr, nullptr, &totalBytes); #endif if (showStats) { diff --git a/third_party/nix/src/libexpr/get-drvs.cc b/third_party/nix/src/libexpr/get-drvs.cc index fb5ada54c860..02ddae1f886c 100644 --- a/third_party/nix/src/libexpr/get-drvs.cc +++ b/third_party/nix/src/libexpr/get-drvs.cc @@ -6,7 +6,6 @@ #include <absl/strings/numbers.h> #include <glog/logging.h> -#include <math.h> #include "libexpr/eval-inline.hh" #include "libstore/derivations.hh" @@ -244,7 +243,7 @@ NixInt DrvInfo::queryMetaInt(const std::string& name, NixInt def) { if (v->type == tString) { /* Backwards compatibility with before we had support for integer meta fields. */ - NixInt n = 0; + NixInt n; if (absl::SimpleAtoi(v->string.s, &n)) { return n; } @@ -263,7 +262,7 @@ NixFloat DrvInfo::queryMetaFloat(const std::string& name, NixFloat def) { if (v->type == tString) { /* Backwards compatibility with before we had support for float meta fields. */ - NixFloat n = NAN; + NixFloat n; if (string2Float(v->string.s, n)) { return n; } @@ -368,7 +367,7 @@ static void getDerivations(EvalState& state, Value& vIn, const std::string& pathPrefix, Bindings& autoArgs, DrvInfos& drvs, Done& done, bool ignoreAssertionFailures) { - Value v{}; + Value v; state.autoCallFunction(autoArgs, vIn, v); /* Process the expression. */ diff --git a/third_party/nix/src/libexpr/names.cc b/third_party/nix/src/libexpr/names.cc index 84329d7c02c0..1e9c2f2f4aac 100644 --- a/third_party/nix/src/libexpr/names.cc +++ b/third_party/nix/src/libexpr/names.cc @@ -68,8 +68,8 @@ std::string nextComponent(std::string::const_iterator& p, } static bool componentsLT(const std::string& c1, const std::string& c2) { - int n1 = 0; - int n2 = 0; + int n1; + int n2; bool c1Num = absl::SimpleAtoi(c1, &n1); bool c2Num = absl::SimpleAtoi(c2, &n2); diff --git a/third_party/nix/src/libexpr/names.hh b/third_party/nix/src/libexpr/names.hh index e820995b84a6..061388d517cd 100644 --- a/third_party/nix/src/libexpr/names.hh +++ b/third_party/nix/src/libexpr/names.hh @@ -11,7 +11,7 @@ struct DrvName { std::string fullName; std::string name; std::string version; - unsigned int hits{}; + unsigned int hits; DrvName(); DrvName(const std::string& s); diff --git a/third_party/nix/src/libexpr/nixexpr.cc b/third_party/nix/src/libexpr/nixexpr.cc index faf1020f8573..94e7d335cff0 100644 --- a/third_party/nix/src/libexpr/nixexpr.cc +++ b/third_party/nix/src/libexpr/nixexpr.cc @@ -18,7 +18,7 @@ std::ostream& operator<<(std::ostream& str, const Expr& e) { static void showString(std::ostream& str, const std::string& s) { str << '"'; - for (auto c : std::string(s)) { + for (auto c : (std::string)s) { if (c == '"' || c == '\\' || c == '$') { str << "\\" << c; } else if (c == '\n') { @@ -191,7 +191,7 @@ std::ostream& operator<<(std::ostream& str, const Pos& pos) { str << "undefined position"; } else { str << (format(ANSI_BOLD "%1%" ANSI_NORMAL ":%2%:%3%") % - std::string(pos.file.value()) % pos.line % pos.column) + (std::string)pos.file.value() % pos.line % pos.column) .str(); } return str; @@ -232,8 +232,8 @@ void ExprPath::bindVars(const StaticEnv& env) {} void ExprVar::bindVars(const StaticEnv& env) { /* Check whether the variable appears in the environment. If so, set its level and displacement. */ - const StaticEnv* curEnv = nullptr; - unsigned int level = 0; + const StaticEnv* curEnv; + unsigned int level; int withLevel = -1; for (curEnv = &env, level = 0; curEnv != nullptr; curEnv = curEnv->up, level++) { @@ -363,8 +363,8 @@ void ExprWith::bindVars(const StaticEnv& env) { /* Does this `with' have an enclosing `with'? If so, record its level so that `lookupVar' can look up variables in the previous `with' if this one doesn't contain the desired attribute. */ - const StaticEnv* curEnv = nullptr; - unsigned int level = 0; + const StaticEnv* curEnv; + unsigned int level; prevWith = 0; for (curEnv = &env, level = 1; curEnv != nullptr; curEnv = curEnv->up, level++) { @@ -405,7 +405,7 @@ void ExprLambda::setName(Symbol& name) { this->name = name; } std::string ExprLambda::showNamePos() const { return (format("%1% at %2%") % - (name.has_value() ? "'" + std::string(name.value()) + "'" + (name.has_value() ? "'" + (std::string)name.value() + "'" : "anonymous function") % pos) .str(); diff --git a/third_party/nix/src/libexpr/parser.cc b/third_party/nix/src/libexpr/parser.cc index 7b477f3eae0a..a96d345cc126 100644 --- a/third_party/nix/src/libexpr/parser.cc +++ b/third_party/nix/src/libexpr/parser.cc @@ -85,10 +85,9 @@ void addAttr(ExprAttrs* attrs, AttrPath& attrPath, Expr* e, const Pos& pos) { } void addFormal(const Pos& pos, Formals* formals, const Formal& formal) { - if (formals->argNames.find(formal.name) != formals->argNames.end()) { + if (formals->argNames.find(formal.name) != formals->argNames.end()) throw ParseError(format("duplicate formal function argument '%1%' at %2%") % formal.name % pos); - } formals->formals.push_front(formal); formals->argNames.insert(formal.name); } @@ -119,9 +118,9 @@ Expr* stripIndentation(const Pos& pos, SymbolTable& symbols, } for (size_t j = 0; j < e->s.size(); ++j) { if (atStartOfLine) { - if (e->s[j] == ' ') { + if (e->s[j] == ' ') curIndent++; - } else if (e->s[j] == '\n') { + else if (e->s[j] == '\n') { /* Empty line, doesn't influence minimum indentation. */ curIndent = 0; @@ -197,11 +196,10 @@ Path resolveExprPath(Path path) { /* If `path' is a symlink, follow it. This is so that relative path references work. */ - struct stat st {}; + struct stat st; while (true) { - if (lstat(path.c_str(), &st)) { + if (lstat(path.c_str(), &st)) throw SysError(format("getting status of '%1%'") % path); - } if (!S_ISLNK(st.st_mode)) { break; } @@ -262,14 +260,13 @@ Path EvalState::findFile(SearchPath& searchPath, const std::string& path, const Pos& pos) { for (auto& i : searchPath) { std::string suffix; - if (i.first.empty()) { + if (i.first.empty()) suffix = "/" + path; - } else { + else { auto s = i.first.size(); if (path.compare(0, s, i.first) != 0 || - (path.size() > s && path[s] != '/')) { + (path.size() > s && path[s] != '/')) continue; - } suffix = path.size() == s ? "" : "/" + std::string(path, s); } auto r = resolveSearchPathElem(i); diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index 053565f4807c..a1c1f2517969 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -86,8 +86,8 @@ void EvalState::realiseContext(const PathSet& context) { PathSet willBuild; PathSet willSubstitute; PathSet unknown; - unsigned long long downloadSize = 0; - unsigned long long narSize = 0; + unsigned long long downloadSize; + unsigned long long narSize; store->queryMissing(drvs, willBuild, willSubstitute, unknown, downloadSize, narSize); store->buildPaths(drvs); @@ -130,7 +130,7 @@ static void prim_scopedImport(EvalState& state, const Pos& pos, Value** args, mkString(*((*outputsVal->list)[outputs_index++]), o.first); } - Value fun{}; + Value fun; state.evalFile( settings.nixDataDir + "/nix/corepkgs/imported-drv-to-derivation.nix", fun); @@ -213,7 +213,7 @@ static void prim_isNull(EvalState& state, const Pos& pos, Value** args, static void prim_isFunction(EvalState& state, const Pos& pos, Value** args, Value& v) { state.forceValue(*args[0]); - bool res = 0; + bool res; switch (args[0]->type) { case tLambda: case tPrimOp: @@ -347,7 +347,7 @@ static void prim_genericClosure(EvalState& state, const Pos& pos, Value** args, res.push_back(e); /* Call the `operator' function with `e' as argument. */ - Value call{}; + Value call; mkApp(call, *op->second.value, *e); state.forceList(call, pos); @@ -875,7 +875,7 @@ static void prim_readFile(EvalState& state, const Pos& pos, Value** args, } std::string s = readFile(state.checkSourcePath(state.toRealPath(path, context))); - if (s.find('\0') != std::string::npos) { + if (s.find((char)0) != std::string::npos) { throw Error(format("the contents of the file '%1%' cannot be represented " "as a Nix string") % path); @@ -1048,13 +1048,13 @@ static void addPath(EvalState& state, const Pos& pos, const std::string& name, /* Call the filter function. The first argument is the path, the second is a string indicating the type of the file. */ - Value arg1{}; + Value arg1; mkString(arg1, path); - Value fun2{}; + Value fun2; state.callFunction(*filterFun, arg1, fun2, noPos); - Value arg2{}; + Value arg2; mkString(arg2, S_ISREG(st.st_mode) ? "regular" : S_ISDIR(st.st_mode) @@ -1063,7 +1063,7 @@ static void addPath(EvalState& state, const Pos& pos, const std::string& name, ? "symlink" : "unknown" /* not supported, will fail! */); - Value res{}; + Value res; state.callFunction(fun2, arg2, res, noPos); return state.forceBool(res, pos); @@ -1420,7 +1420,7 @@ static void prim_isList(EvalState& state, const Pos& pos, Value** args, static void elemAt(EvalState& state, const Pos& pos, Value& list, int n, Value& v) { state.forceList(list, pos); - if (n < 0 || static_cast<unsigned int>(n) >= list.listSize()) { + if (n < 0 || (unsigned int)n >= list.listSize()) { throw Error(format("list index %1% is out of bounds, at %2%") % n % pos); } state.forceValue(*(*list.list)[n]); @@ -1479,7 +1479,7 @@ static void prim_filter(EvalState& state, const Pos& pos, Value** args, bool same = true; for (unsigned int n = 0; n < args[1]->listSize(); ++n) { - Value res{}; + Value res; state.callFunction(*args[0], *(*args[1]->list)[n], res, noPos); if (state.forceBool(res, pos)) { vs[k++] = (*args[1]->list)[n]; @@ -1537,7 +1537,7 @@ static void prim_foldlStrict(EvalState& state, const Pos& pos, Value** args, Value* vCur = args[1]; for (unsigned int n = 0; n < args[2]->listSize(); ++n) { - Value vTmp{}; + Value vTmp; state.callFunction(*args[0], *vCur, vTmp, pos); vCur = n == args[2]->listSize() - 1 ? &v : state.allocValue(); state.callFunction(vTmp, *(*args[2]->list)[n], *vCur, pos); @@ -1554,7 +1554,7 @@ static void anyOrAll(bool any, EvalState& state, const Pos& pos, Value** args, state.forceFunction(*args[0], pos); state.forceList(*args[1], pos); - Value vTmp{}; + Value vTmp; for (unsigned int n = 0; n < args[1]->listSize(); ++n) { state.callFunction(*args[0], *(*args[1]->list)[n], vTmp, pos); bool res = state.forceBool(vTmp, pos); @@ -1586,7 +1586,7 @@ static void prim_genList(EvalState& state, const Pos& pos, Value** args, state.mkList(v, len); - for (unsigned int n = 0; n < static_cast<unsigned int>(len); ++n) { + for (unsigned int n = 0; n < (unsigned int)len; ++n) { Value* arg = state.allocValue(); mkInt(*arg, n); mkApp(*((*v.list)[n] = state.allocValue()), *args[0], *arg); @@ -1614,8 +1614,8 @@ static void prim_sort(EvalState& state, const Pos& pos, Value** args, return CompareValues()(a, b); } - Value vTmp1{}; - Value vTmp2{}; + Value vTmp1; + Value vTmp2; state.callFunction(*args[0], *a, vTmp1, pos); state.callFunction(vTmp1, *b, vTmp2, pos); return state.forceBool(vTmp2, pos); @@ -1638,7 +1638,7 @@ static void prim_partition(EvalState& state, const Pos& pos, Value** args, for (Value* elem : *args[1]->list) { state.forceValue(*elem, pos); - Value res{}; + Value res; state.callFunction(*args[0], *elem, res, pos); if (state.forceBool(res, pos)) { right->push_back(elem); @@ -1789,10 +1789,7 @@ static void prim_substring(EvalState& state, const Pos& pos, Value** args, pos); } - mkString(v, - static_cast<unsigned int>(start) >= s.size() - ? "" - : std::string(s, start, len), + mkString(v, (unsigned int)start >= s.size() ? "" : std::string(s, start, len), context); } @@ -1877,7 +1874,7 @@ static void prim_split(EvalState& state, const Pos& pos, Value** args, const size_t len = std::distance(begin, end); state.mkList(v, 2 * len + 1); size_t idx = 0; - Value* elem = nullptr; + Value* elem; if (len == 0) { (*v.list)[idx++] = args[1]; @@ -2141,7 +2138,7 @@ void EvalState::createBaseEnv() { baseEnv.up = nullptr; /* Add global constants such as `true' to the base environment. */ - Value v{}; + Value v; /* `builtins' must be first! */ mkAttrs(v, 128); diff --git a/third_party/nix/src/libexpr/primops/context.cc b/third_party/nix/src/libexpr/primops/context.cc index fb8879ead16d..841a45c61c03 100644 --- a/third_party/nix/src/libexpr/primops/context.cc +++ b/third_party/nix/src/libexpr/primops/context.cc @@ -97,13 +97,12 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args, ContextInfo{isPath, isAllOutputs, output.empty() ? Strings{} : Strings{std::move(output)}}); } else { - if (isPath) { + if (isPath) iter->second.path = true; - } else if (isAllOutputs) { + else if (isAllOutputs) iter->second.allOutputs = true; - } else { + else iter->second.outputs.emplace_back(std::move(output)); - } } } @@ -117,9 +116,8 @@ static void prim_getContext(EvalState& state, const Pos& pos, Value** args, if (info.second.path) { mkBool(*state.allocAttr(infoVal, sPath), true); } - if (info.second.allOutputs) { + if (info.second.allOutputs) mkBool(*state.allocAttr(infoVal, sAllOutputs), true); - } if (!info.second.outputs.empty()) { auto& outputsVal = *state.allocAttr(infoVal, state.sOutputs); state.mkList(outputsVal, info.second.outputs.size()); @@ -149,10 +147,9 @@ static void prim_appendContext(EvalState& state, const Pos& pos, Value** args, auto sAllOutputs = state.symbols.Create("allOutputs"); for (const auto& attr_iter : *args[1]->attrs) { const Attr* i = &attr_iter.second; // TODO(tazjin): get rid of this - if (!state.store->isStorePath(i->name)) { + if (!state.store->isStorePath(i->name)) throw EvalError("Context key '%s' is not a store path, at %s", i->name, i->pos); - } if (!settings.readOnlyMode) { state.store->ensurePath(i->name); } diff --git a/third_party/nix/src/libexpr/primops/fetchGit.cc b/third_party/nix/src/libexpr/primops/fetchGit.cc index 839094b72b53..7262a291559f 100644 --- a/third_party/nix/src/libexpr/primops/fetchGit.cc +++ b/third_party/nix/src/libexpr/primops/fetchGit.cc @@ -30,9 +30,8 @@ std::regex revRegex("^[0-9a-fA-F]{40}$"); GitInfo exportGit(ref<Store> store, const std::string& uri, std::optional<std::string> ref, std::string rev, const std::string& name) { - if (evalSettings.pureEval && rev == "") { + if (evalSettings.pureEval && rev == "") throw Error("in pure evaluation mode, 'fetchGit' requires a Git revision"); - } if (!ref && rev == "" && absl::StartsWith(uri, "/") && pathExists(uri + "/.git")) { @@ -91,9 +90,8 @@ GitInfo exportGit(ref<Store> store, const std::string& uri, ref = "HEAD"s; } - if (rev != "" && !std::regex_match(rev, revRegex)) { + if (rev != "" && !std::regex_match(rev, revRegex)) throw Error("invalid Git revision '%s'", rev); - } deletePath(getCacheDir() + "/nix/git"); @@ -106,13 +104,12 @@ GitInfo exportGit(ref<Store> store, const std::string& uri, } Path localRefFile; - if (ref->compare(0, 5, "refs/") == 0) { + if (ref->compare(0, 5, "refs/") == 0) localRefFile = cacheDir + "/" + *ref; - } else { + else localRefFile = cacheDir + "/refs/heads/" + *ref; - } - bool doFetch = 0; + bool doFetch; time_t now = time(0); /* If a rev was specified, we need to fetch if it's not in the repo. */ @@ -130,10 +127,9 @@ GitInfo exportGit(ref<Store> store, const std::string& uri, } else { /* If the local ref is older than ‘tarball-ttl’ seconds, do a git fetch to update the local ref to the remote ref. */ - struct stat st {}; + struct stat st; doFetch = stat(localRefFile.c_str(), &st) != 0 || - static_cast<uint64_t>(st.st_mtime) + settings.tarballTtl <= - static_cast<uint64_t>(now); + (uint64_t)st.st_mtime + settings.tarballTtl <= (uint64_t)now; } if (doFetch) { DLOG(INFO) << "fetching Git repository '" << uri << "'"; @@ -229,24 +225,22 @@ static void prim_fetchGit(EvalState& state, const Pos& pos, Value** args, for (auto& attr_iter : *args[0]->attrs) { auto& attr = attr_iter.second; std::string n(attr.name); - if (n == "url") { + if (n == "url") url = state.coerceToString(*attr.pos, *attr.value, context, false, false); - } else if (n == "ref") { + else if (n == "ref") ref = state.forceStringNoCtx(*attr.value, *attr.pos); - } else if (n == "rev") { + else if (n == "rev") rev = state.forceStringNoCtx(*attr.value, *attr.pos); - } else if (n == "name") { + else if (n == "name") name = state.forceStringNoCtx(*attr.value, *attr.pos); - } else { + else throw EvalError("unsupported argument '%s' to 'fetchGit', at %s", attr.name, *attr.pos); - } } - if (url.empty()) { + if (url.empty()) throw EvalError(format("'url' argument required, at %1%") % pos); - } } else { url = state.coerceToString(pos, *args[0], context, false, false); diff --git a/third_party/nix/src/libexpr/primops/fetchMercurial.cc b/third_party/nix/src/libexpr/primops/fetchMercurial.cc index 05a3d66ae7ca..3ece094e6a8d 100644 --- a/third_party/nix/src/libexpr/primops/fetchMercurial.cc +++ b/third_party/nix/src/libexpr/primops/fetchMercurial.cc @@ -28,11 +28,10 @@ std::regex commitHashRegex("^[0-9a-fA-F]{40}$"); HgInfo exportMercurial(ref<Store> store, const std::string& uri, std::string rev, const std::string& name) { - if (evalSettings.pureEval && rev == "") { + if (evalSettings.pureEval && rev == "") throw Error( "in pure evaluation mode, 'fetchMercurial' requires a Mercurial " "revision"); - } if (rev == "" && absl::StartsWith(uri, "/") && pathExists(uri + "/.hg")) { bool clean = runProgram("hg", true, @@ -91,10 +90,9 @@ HgInfo exportMercurial(ref<Store> store, const std::string& uri, /* If we haven't pulled this repo less than ‘tarball-ttl’ seconds, do so now. */ time_t now = time(0); - struct stat st {}; + struct stat st; if (stat(stampFile.c_str(), &st) != 0 || - static_cast<uint64_t>(st.st_mtime) + settings.tarballTtl <= - static_cast<uint64_t>(now)) { + (uint64_t)st.st_mtime + settings.tarballTtl <= (uint64_t)now) { /* Except that if this is a commit hash that we already have, we don't have to pull again. */ if (!(std::regex_match(rev, commitHashRegex) && pathExists(cacheDir) && @@ -200,22 +198,20 @@ static void prim_fetchMercurial(EvalState& state, const Pos& pos, Value** args, for (auto& attr_iter : *args[0]->attrs) { auto& attr = attr_iter.second; std::string n(attr.name); - if (n == "url") { + if (n == "url") url = state.coerceToString(*attr.pos, *attr.value, context, false, false); - } else if (n == "rev") { + else if (n == "rev") rev = state.forceStringNoCtx(*attr.value, *attr.pos); - } else if (n == "name") { + else if (n == "name") name = state.forceStringNoCtx(*attr.value, *attr.pos); - } else { + else throw EvalError("unsupported argument '%s' to 'fetchMercurial', at %s", attr.name, *attr.pos); - } } - if (url.empty()) { + if (url.empty()) throw EvalError(format("'url' argument required, at %1%") % pos); - } } else { url = state.coerceToString(pos, *args[0], context, false, false); diff --git a/third_party/nix/src/libexpr/primops/fromTOML.cc b/third_party/nix/src/libexpr/primops/fromTOML.cc index e3d2a4940769..389ac080677a 100644 --- a/third_party/nix/src/libexpr/primops/fromTOML.cc +++ b/third_party/nix/src/libexpr/primops/fromTOML.cc @@ -30,12 +30,10 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args, if (auto i2 = i.second->as_table_array()) { size_t size2 = i2->get().size(); state.mkList(v2, size2); - for (size_t j = 0; j < size2; ++j) { + for (size_t j = 0; j < size2; ++j) visit(*((*v2.list)[j] = state.allocValue()), i2->get()[j]); - } - } else { + } else visit(v2, i.second); - } } } @@ -44,9 +42,8 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args, state.mkList(v, size); - for (size_t i = 0; i < size; ++i) { + for (size_t i = 0; i < size; ++i) visit(*((*v.list)[i] = state.allocValue()), t2->get()[i]); - } } // Handle cases like 'a = [[{ a = true }]]', which IMHO should be @@ -58,28 +55,25 @@ static void prim_fromTOML(EvalState& state, const Pos& pos, Value** args, state.mkList(v, size); - for (size_t j = 0; j < size; ++j) { + for (size_t j = 0; j < size; ++j) visit(*((*v.list)[j] = state.allocValue()), t2->get()[j]); - } } else if (t->is_value()) { - if (auto val = t->as<int64_t>()) { + if (auto val = t->as<int64_t>()) mkInt(v, val->get()); - } else if (auto val = t->as<NixFloat>()) { + else if (auto val = t->as<NixFloat>()) mkFloat(v, val->get()); - } else if (auto val = t->as<bool>()) { + else if (auto val = t->as<bool>()) mkBool(v, val->get()); - } else if (auto val = t->as<std::string>()) { + else if (auto val = t->as<std::string>()) mkString(v, val->get()); - } else { + else throw EvalError("unsupported value type in TOML"); - } } - else { + else abort(); - } }; try { |