aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2019-11-22 16:06:44 +0100
committerEelco Dolstra <edolstra@gmail.com>2019-11-22 16:18:13 +0100
commitba87b08f8529e4d9f8c58d8c625152058ceadb75 (patch)
treec78196cbeb52273c3d5b99ff8dee314108940b9a /src/libexpr
parentfd900c45b5ff9c6dc7f3ec814eca4ad603720899 (diff)
getEnv(): Return std::optional
This allows distinguishing between an empty value and no value.
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/eval.cc12
-rw-r--r--src/libexpr/primops.cc2
2 files changed, 7 insertions, 7 deletions
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 3c3d1a324..bb6b23ff1 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -217,7 +217,7 @@ void initGC()
that GC_expand_hp() causes a lot of virtual, but not physical
(resident) memory to be allocated. This might be a problem on
systems that don't overcommit. */
- if (!getenv("GC_INITIAL_HEAP_SIZE")) {
+ if (!getEnv("GC_INITIAL_HEAP_SIZE")) {
size_t size = 32 * 1024 * 1024;
#if HAVE_SYSCONF && defined(_SC_PAGESIZE) && defined(_SC_PHYS_PAGES)
size_t maxSize = 384 * 1024 * 1024;
@@ -306,7 +306,7 @@ EvalState::EvalState(const Strings & _searchPath, ref<Store> store)
, baseEnv(allocEnv(128))
, staticBaseEnv(false, 0)
{
- countCalls = getEnv("NIX_COUNT_CALLS", "0") != "0";
+ countCalls = getEnv("NIX_COUNT_CALLS").value_or("0") != "0";
assert(gcInitialised);
@@ -314,7 +314,7 @@ EvalState::EvalState(const Strings & _searchPath, ref<Store> store)
/* Initialise the Nix expression search path. */
if (!evalSettings.pureEval) {
- Strings paths = parseNixPath(getEnv("NIX_PATH", ""));
+ Strings paths = parseNixPath(getEnv("NIX_PATH").value_or(""));
for (auto & i : _searchPath) addToSearchPath(i);
for (auto & i : paths) addToSearchPath(i);
}
@@ -1753,7 +1753,7 @@ bool EvalState::eqValues(Value & v1, Value & v2)
void EvalState::printStats()
{
- bool showStats = getEnv("NIX_SHOW_STATS", "0") != "0";
+ bool showStats = getEnv("NIX_SHOW_STATS").value_or("0") != "0";
struct rusage buf;
getrusage(RUSAGE_SELF, &buf);
@@ -1769,7 +1769,7 @@ void EvalState::printStats()
GC_get_heap_usage_safe(&heapSize, 0, 0, 0, &totalBytes);
#endif
if (showStats) {
- auto outPath = getEnv("NIX_SHOW_STATS_PATH","-");
+ auto outPath = getEnv("NIX_SHOW_STATS_PATH").value_or("-");
std::fstream fs;
if (outPath != "-")
fs.open(outPath, std::fstream::out);
@@ -1861,7 +1861,7 @@ void EvalState::printStats()
}
}
- if (getEnv("NIX_SHOW_SYMBOLS", "0") != "0") {
+ if (getEnv("NIX_SHOW_SYMBOLS").value_or("0") != "0") {
auto list = topObj.list("symbols");
symbols.dump([&](const std::string & s) { list.elem(s); });
}
diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc
index deaffa605..2cc03fe61 100644
--- a/src/libexpr/primops.cc
+++ b/src/libexpr/primops.cc
@@ -469,7 +469,7 @@ static void prim_tryEval(EvalState & state, const Pos & pos, Value * * args, Val
static void prim_getEnv(EvalState & state, const Pos & pos, Value * * args, Value & v)
{
string name = state.forceStringNoCtx(*args[0], pos);
- mkString(v, evalSettings.restrictEval || evalSettings.pureEval ? "" : getEnv(name));
+ mkString(v, evalSettings.restrictEval || evalSettings.pureEval ? "" : getEnv(name).value_or(""));
}