diff options
Diffstat (limited to 'src/libexpr')
-rw-r--r-- | src/libexpr/Makefile.am | 40 | ||||
-rw-r--r-- | src/libexpr/eval.cc | 23 | ||||
-rw-r--r-- | src/libexpr/eval.hh | 14 | ||||
-rw-r--r-- | src/libexpr/local.mk | 24 | ||||
-rw-r--r-- | src/libexpr/nixexpr.hh | 3 | ||||
-rw-r--r-- | src/libexpr/parser.y | 4 | ||||
-rw-r--r-- | src/libexpr/primops.cc | 1 | ||||
-rw-r--r-- | src/libexpr/value.hh | 4 |
8 files changed, 57 insertions, 56 deletions
diff --git a/src/libexpr/Makefile.am b/src/libexpr/Makefile.am deleted file mode 100644 index 7edbe77157d8..000000000000 --- a/src/libexpr/Makefile.am +++ /dev/null @@ -1,40 +0,0 @@ -pkglib_LTLIBRARIES = libexpr.la - -libexpr_la_SOURCES = \ - nixexpr.cc eval.cc primops.cc lexer-tab.cc parser-tab.cc \ - get-drvs.cc attr-path.cc value-to-xml.cc value-to-json.cc \ - common-opts.cc names.cc - -pkginclude_HEADERS = \ - nixexpr.hh eval.hh eval-inline.hh lexer-tab.hh parser-tab.hh \ - get-drvs.hh attr-path.hh value-to-xml.hh value-to-json.hh \ - common-opts.hh names.hh symbol-table.hh value.hh - -libexpr_la_LIBADD = ../libutil/libutil.la ../libstore/libstore.la \ - ../boost/format/libformat.la @BDW_GC_LIBS@ - -BUILT_SOURCES = \ - parser-tab.hh lexer-tab.hh parser-tab.cc lexer-tab.cc - -EXTRA_DIST = lexer.l parser.y - -AM_CXXFLAGS = \ - -I$(srcdir)/.. \ - -I$(srcdir)/../libutil -I$(srcdir)/../libstore - - -# Parser generation. - -parser-tab.cc parser-tab.hh: parser.y - $(bison) -v -o parser-tab.cc $(srcdir)/parser.y -d - -lexer-tab.cc lexer-tab.hh: lexer.l - $(flex) --outfile lexer-tab.cc --header-file=lexer-tab.hh $(srcdir)/lexer.l - - -# SDF stuff (not built by default). -nix.tbl: nix.sdf - sdf2table -m Nix -s -i nix.sdf -o nix.tbl - -test.ast: test.nix nix.tbl - sglri -p nix.tbl -i test.nix -o test.ast 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/eval.hh b/src/libexpr/eval.hh index 45ab423c18a1..5ae5a1e3cf24 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -82,8 +82,6 @@ void copyContext(const Value & v, PathSet & context); paths. */ typedef std::map<Path, Path> SrcToStore; -struct EvalState; - std::ostream & operator << (std::ostream & str, const Value & v); @@ -216,9 +214,9 @@ private: inline Value * lookupVar(Env * env, const ExprVar & var, bool noEval); - friend class ExprVar; - friend class ExprAttrs; - friend class ExprLet; + friend struct ExprVar; + friend struct ExprAttrs; + friend struct ExprLet; Expr * parse(const char * text, const Path & path, const Path & basePath, StaticEnv & staticEnv); @@ -278,9 +276,9 @@ private: typedef std::map<Pos, unsigned int> AttrSelects; AttrSelects attrSelects; - friend class ExprOpUpdate; - friend class ExprOpConcatLists; - friend class ExprSelect; + friend struct ExprOpUpdate; + friend struct ExprOpConcatLists; + friend struct ExprSelect; friend void prim_getAttr(EvalState & state, Value * * args, Value & v); }; diff --git a/src/libexpr/local.mk b/src/libexpr/local.mk new file mode 100644 index 000000000000..431f84b0999e --- /dev/null +++ b/src/libexpr/local.mk @@ -0,0 +1,24 @@ +libraries += 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 + $(trace-gen) bison -v -o $(libexpr_DIR)/parser-tab.cc $< -d + +$(d)/lexer-tab.cc $(d)/lexer-tab.hh: $(d)/lexer.l + $(trace-gen) flex --outfile $(libexpr_DIR)/lexer-tab.cc --header-file=$(libexpr_DIR)/lexer-tab.hh $< + +clean-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexer-tab.hh + +dist-files += $(d)/parser-tab.cc $(d)/parser-tab.hh $(d)/lexer-tab.cc $(d)/lexer-tab.hh diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index bc6993477c48..7586fffb83d4 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -48,7 +48,7 @@ std::ostream & operator << (std::ostream & str, const Pos & pos); struct Env; struct Value; -struct EvalState; +class EvalState; struct StaticEnv; struct Expr; @@ -71,6 +71,7 @@ string showAttrPath(const AttrPath & attrPath); struct Expr { + virtual ~Expr() { }; virtual void show(std::ostream & str); virtual void bindVars(const StaticEnv & env); virtual void eval(EvalState & state, Env & env, Value & v); diff --git a/src/libexpr/parser.y b/src/libexpr/parser.y index 55a42fcaba9f..8a084fea0697 100644 --- a/src/libexpr/parser.y +++ b/src/libexpr/parser.y @@ -252,7 +252,7 @@ void yyerror(YYLTYPE * loc, yyscan_t scanner, ParseData * data, const char * err nix::Formals * formals; nix::Formal * formal; nix::NixInt n; - char * id; // !!! -> Symbol + const char * id; // !!! -> Symbol char * path; char * uri; std::vector<nix::AttrName> * attrNames; @@ -414,7 +414,7 @@ expr_simple string_parts : STR | string_parts_interpolated { $$ = new ExprConcatStrings(true, $1); } - | { $$ = new ExprString(data->symbols.create("")) } + | { $$ = new ExprString(data->symbols.create("")); } ; string_parts_interpolated 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); diff --git a/src/libexpr/value.hh b/src/libexpr/value.hh index 982582793419..2feb2f9492ca 100644 --- a/src/libexpr/value.hh +++ b/src/libexpr/value.hh @@ -22,13 +22,13 @@ typedef enum { } ValueType; -struct Bindings; +class Bindings; struct Env; struct Expr; struct ExprLambda; struct PrimOp; struct PrimOp; -struct Symbol; +class Symbol; typedef long NixInt; |