about summary refs log tree commit diff
path: root/src/libexpr
diff options
context:
space:
mode:
Diffstat (limited to 'src/libexpr')
-rw-r--r--src/libexpr/attr-set.cc10
-rw-r--r--src/libexpr/eval.cc4
-rw-r--r--src/libexpr/eval.hh4
3 files changed, 14 insertions, 4 deletions
diff --git a/src/libexpr/attr-set.cc b/src/libexpr/attr-set.cc
index 9ac5e603199a..910428c02686 100644
--- a/src/libexpr/attr-set.cc
+++ b/src/libexpr/attr-set.cc
@@ -29,13 +29,17 @@ Bindings * EvalState::allocBindings(Bindings::size_t capacity)
 }
 
 
-void EvalState::mkAttrs(Value & v, unsigned int expected)
+void EvalState::mkAttrs(Value & v, unsigned int capacity)
 {
+    if (capacity == 0) {
+        v = vEmptySet;
+        return;
+    }
     clearValue(v);
     v.type = tAttrs;
-    v.attrs = allocBindings(expected);
+    v.attrs = allocBindings(capacity);
     nrAttrsets++;
-    nrAttrsInAttrsets += expected;
+    nrAttrsInAttrsets += capacity;
 }
 
 
diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc
index 044256112d50..14169d85735e 100644
--- a/src/libexpr/eval.cc
+++ b/src/libexpr/eval.cc
@@ -281,6 +281,10 @@ EvalState::EvalState(const Strings & _searchPath)
     for (auto & i : paths) addToSearchPath(i);
     addToSearchPath("nix=" + settings.nixDataDir + "/nix/corepkgs");
 
+    clearValue(vEmptySet);
+    vEmptySet.type = tAttrs;
+    vEmptySet.attrs = allocBindings(0);
+
     createBaseEnv();
 }
 
diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh
index 1b546f89c836..80eba975e9c3 100644
--- a/src/libexpr/eval.hh
+++ b/src/libexpr/eval.hh
@@ -80,6 +80,8 @@ public:
        path or to environment variables. */
     bool restricted;
 
+    Value vEmptySet;
+
 private:
     SrcToStore srcToStore;
 
@@ -227,7 +229,7 @@ public:
     Bindings * allocBindings(Bindings::size_t capacity);
 
     void mkList(Value & v, unsigned int length);
-    void mkAttrs(Value & v, unsigned int expected);
+    void mkAttrs(Value & v, unsigned int capacity);
     void mkThunk_(Value & v, Expr * expr);
     void mkPos(Value & v, Pos * pos);