aboutsummaryrefslogtreecommitdiff
path: root/src/libexpr/eval-inline.hh
diff options
context:
space:
mode:
authorQyriad <qyriad@qyriad.me>2024-07-15 16:18:36 -0600
committerQyriad <qyriad@qyriad.me>2024-07-20 20:20:01 +0000
commita3361557e3f4a53b90ca5067e68ba9788df20928 (patch)
tree60899a6f30348b8b919c289e06b59fa644003b9d /src/libexpr/eval-inline.hh
parent0109368c3faf5516aeddde45e8dc3c33e7163838 (diff)
libexpr: refactor gc-agnostic helpers into one place
Change-Id: Icc4b367e4f670d47256f62a3a002cd248a5c2d3b
Diffstat (limited to 'src/libexpr/eval-inline.hh')
-rw-r--r--src/libexpr/eval-inline.hh22
1 files changed, 3 insertions, 19 deletions
diff --git a/src/libexpr/eval-inline.hh b/src/libexpr/eval-inline.hh
index 94d4c55ef..4631b71eb 100644
--- a/src/libexpr/eval-inline.hh
+++ b/src/libexpr/eval-inline.hh
@@ -4,26 +4,10 @@
#include "print.hh"
#include "eval.hh"
#include "eval-error.hh"
+#include "gc-alloc.hh"
namespace nix {
-/**
- * Note: Various places expect the allocated memory to be zeroed.
- */
-[[gnu::always_inline]]
-inline void * allocBytes(size_t n)
-{
- void * p;
-#if HAVE_BOEHMGC
- p = GC_MALLOC(n);
-#else
- p = calloc(n, 1);
-#endif
- if (!p) throw std::bad_alloc();
- return p;
-}
-
-
[[gnu::always_inline]]
Value * EvalState::allocValue()
{
@@ -43,7 +27,7 @@ Value * EvalState::allocValue()
*valueAllocCache = GC_NEXT(p);
GC_NEXT(p) = nullptr;
#else
- void * p = allocBytes(sizeof(Value));
+ void * p = gcAllocBytes(sizeof(Value));
#endif
nrValues++;
@@ -73,7 +57,7 @@ Env & EvalState::allocEnv(size_t size)
env = (Env *) p;
} else
#endif
- env = (Env *) allocBytes(sizeof(Env) + size * sizeof(Value *));
+ env = (Env *) gcAllocBytes(sizeof(Env) + size * sizeof(Value *));
/* We assume that env->values has been cleared by the allocator; maybeThunk() and lookupVar fromWith expect this. */