diff options
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/Makefile | 20 | ||||
-rw-r--r-- | src/libexpr/eval.cc | 23 | ||||
-rw-r--r-- | src/libexpr/primops.cc | 1 |
3 files changed, 41 insertions, 3 deletions
diff --git a/src/libexpr/Makefile b/src/libexpr/Makefile new file mode 100644 index 000000000000..de276aa65296 --- /dev/null +++ b/src/libexpr/Makefile @@ -0,0 +1,20 @@ +LIBS += libexpr + +libexpr_NAME = libnixexpr + +libexpr_DIR := $(d) + +libexpr_SOURCES := $(wildcard $(d)/*.cc) $(d)/lexer-tab.cc $(d)/parser-tab.cc + +libexpr_LIBS = libutil libstore libformat + +# The dependency on libgc must be propagated (i.e. meaning that +# programs/libraries that use libexpr must explicitly pass -lgc), +# because inline functions in libexpr's header files call libgc. +libexpr_LDFLAGS_PROPAGATED = $(BDW_GC_LIBS) + +$(d)/parser-tab.cc $(d)/parser-tab.hh: $(d)/parser.y + bison -v -o $(libexpr_DIR)/parser-tab.cc $< -d + +$(d)/lexer-tab.cc $(d)/lexer-tab.hh: $(d)/lexer.l + flex --outfile $(libexpr_DIR)/lexer-tab.cc --header-file=$(libexpr_DIR)/lexer-tab.hh $< diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 3d8ee9934016..2087c7c43ffb 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -129,7 +129,15 @@ string showType(const Value & v) } -Symbol getName(const AttrName & name, EvalState & state, Env & env) { +/* Called when the Boehm GC runs out of memory. */ +static void * oomHandler(size_t requested) +{ + /* Convert this to a proper C++ exception. */ + throw std::bad_alloc(); +} + + +static Symbol getName(const AttrName & name, EvalState & state, Env & env) { if (name.symbol.set()) { return name.symbol; } else { @@ -168,8 +176,16 @@ EvalState::EvalState() countCalls = getEnv("NIX_COUNT_CALLS", "0") != "0"; #if HAVE_BOEHMGC - static bool gcInitialised = true; - if (gcInitialised) { + static bool gcInitialised = false; + if (!gcInitialised) { + + /* Initialise the Boehm garbage collector. This isn't + necessary on most platforms, but for portability we do it + anyway. */ + GC_INIT(); + + GC_oom_fn = oomHandler; + /* Set the initial heap size to something fairly big (25% of physical RAM, up to a maximum of 384 MiB) so that in most cases we don't need to garbage collect at all. (Collection @@ -193,6 +209,7 @@ EvalState::EvalState() debug(format("setting initial heap size to %1% bytes") % size); GC_expand_hp(size); } + gcInitialised = true; } #endif diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 4f836e279425..ca316f08af13 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -1322,6 +1322,7 @@ void EvalState::createBaseEnv() /* Add a wrapper around the derivation primop that computes the `drvPath' and `outPath' attributes lazily. */ string path = findFile("nix/derivation.nix"); + assert(!path.empty()); sDerivationNix = symbols.create(path); evalFile(path, v); addConstant("derivation", v); |