From 7d0f6aed59b11ef1037e7b0ee4dae1c7288ebb45 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Fri, 4 Jan 2008 14:22:49 +0000 Subject: [PATCH] * New primop `unsafeDiscardStringContext' to get rid of string contexts. Needed to prevent unnecessary dependencies when building the NixOS manual. --- src/libexpr/primops.cc | 10 ++++++++++ tests/lang/eval-okay-context.exp | 1 + tests/lang/eval-okay-context.nix | 6 ++++++ 3 files changed, 17 insertions(+) create mode 100644 tests/lang/eval-okay-context.exp create mode 100644 tests/lang/eval-okay-context.nix diff --git a/src/libexpr/primops.cc b/src/libexpr/primops.cc index 9b0df9238..94410e2bd 100644 --- a/src/libexpr/primops.cc +++ b/src/libexpr/primops.cc @@ -942,6 +942,14 @@ static Expr prim_stringLength(EvalState & state, const ATermVector & args) } +static Expr prim_unsafeDiscardStringContext(EvalState & state, const ATermVector & args) +{ + PathSet context; + string s = coerceToString(state, args[0], context); + return makeStr(s, PathSet()); +} + + /************************************************************* * Primop registration *************************************************************/ @@ -1009,6 +1017,8 @@ void EvalState::addPrimOps() addPrimOp("toString", 1, prim_toString); addPrimOp("__substring", 3, prim_substring); addPrimOp("__stringLength", 1, prim_stringLength); + addPrimOp("__unsafeDiscardStringContext", 1, prim_unsafeDiscardStringContext); + } diff --git a/tests/lang/eval-okay-context.exp b/tests/lang/eval-okay-context.exp new file mode 100644 index 000000000..95a993654 --- /dev/null +++ b/tests/lang/eval-okay-context.exp @@ -0,0 +1 @@ +Str("foo eval-okay-context.nix bar",[]) diff --git a/tests/lang/eval-okay-context.nix b/tests/lang/eval-okay-context.nix new file mode 100644 index 000000000..b3f174897 --- /dev/null +++ b/tests/lang/eval-okay-context.nix @@ -0,0 +1,6 @@ +let s = "foo ${builtins.substring 33 100 (baseNameOf ./eval-okay-context.nix)} bar"; +in + if s == "foo eval-okay-context.nix bar" + then abort "context not discarded" + else builtins.unsafeDiscardStringContext s +