diff --git a/lix/libexpr/eval-expr.cc b/lix/libexpr/eval-expr.cc index c7b87eef0..11566d8c2 100644 --- a/lix/libexpr/eval-expr.cc +++ b/lix/libexpr/eval-expr.cc @@ -539,7 +539,7 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v) .withFrame(env, *this) .debugThrow(); } - v.mkPath(CanonPath(canonPath(str()))); + v = {NewValueAs::path, CanonPath(canonPath(str()))}; } else { v.mkStringMove(gcStr(), context); } diff --git a/lix/libexpr/primops.cc b/lix/libexpr/primops.cc index 6405b6b30..8980606b1 100644 --- a/lix/libexpr/primops.cc +++ b/lix/libexpr/primops.cc @@ -1381,7 +1381,7 @@ static void prim_dirOf(EvalState & state, Value * * args, Value & v) state.forceValue(*args[0], noPos); if (args[0]->type() == nPath) { auto path = args[0]->path(); - v.mkPath(path.canonical().isRoot() ? path : path.parent()); + v = {NewValueAs::path, path.canonical().isRoot() ? path : path.parent()}; } else { NixStringContext context; auto path = state.coerceToString(noPos, *args[0], context, @@ -1479,9 +1479,12 @@ static void prim_findFile(EvalState & state, Value * * args, Value & v) auto path = state.forceStringNoCtx(*args[1], noPos, "while evaluating the second argument passed to builtins.findFile"); - v.mkPath(state.ctx.paths.checkSourcePath( - state.aio.blockOn(state.ctx.paths.findFile(searchPath, path, noPos)).unwrap() - )); + v = { + NewValueAs::path, + state.ctx.paths.checkSourcePath( + state.aio.blockOn(state.ctx.paths.findFile(searchPath, path, noPos)).unwrap() + ) + }; } /* Return the cryptographic hash of a file in base-16. */ @@ -1536,8 +1539,7 @@ static void prim_readDir(EvalState & state, Value * * args, Value & v) // Some filesystems or operating systems may not be able to return // detailed node info quickly in this case we produce a thunk to // query the file type lazily. - Value epath; - epath.mkPath(path + name); + Value epath = {NewValueAs::path, path + name}; if (!readFileType) readFileType = &state.ctx.builtins.get("readFileType"); attr = {NewValueAs::app, state.ctx.mem, *readFileType, epath}; diff --git a/lix/libexpr/value.cc b/lix/libexpr/value.cc index db5eb7729..420fd5b22 100644 --- a/lix/libexpr/value.cc +++ b/lix/libexpr/value.cc @@ -82,11 +82,6 @@ void Value::mkStringMove(Str * s, const NixStringContext & context) copyContextToValue(*block, context); } -void Value::mkPath(const SourcePath & path) -{ - *this = Value(NewValueAs::path, path); -} - #ifndef __APPLE__ [[gnu::section(".debug_gdb_scripts"), gnu::used, gnu::aligned(1)]] static const char printer_script[] = diff --git a/lix/libexpr/value.hh b/lix/libexpr/value.hh index 7ce1d9df4..1b443e9bb 100644 --- a/lix/libexpr/value.hh +++ b/lix/libexpr/value.hh @@ -489,6 +489,18 @@ public: assert(str->isPath()); } + /// Constructs a nix language value of type "path", with the value of the + /// C-string @ref path. + /// + /// The data from @ref path *is* copied, and this constructor performs a + /// dynamic (GC) allocation to do so. + Value(path_t, const char * path) + { + auto block = gcAllocType(); + *block = {.content = Str::gcCopy(path), .context = String::path}; + raw = tag(tString, block); + } + /// Constructs a nix language value of type "path", with the path /// @ref path. /// @@ -774,15 +786,6 @@ public: void mkStringMove(Str * s, const NixStringContext & context); - void mkPath(const SourcePath & path); - - inline void mkPath(const char * path) - { - auto block = gcAllocType(); - *block = {.content = Str::gcCopy(path), .context = String::path}; - raw = tag(tString, block); - } - inline void mkNull() { *this = {NewValueAs::null}; diff --git a/tests/unit/libexpr/json.cc b/tests/unit/libexpr/json.cc index 144586c49..558b0ebde 100644 --- a/tests/unit/libexpr/json.cc +++ b/tests/unit/libexpr/json.cc @@ -61,8 +61,7 @@ namespace nix { // C++ exception with description "error: operation 'addToStoreFromDump' is // not supported by store 'dummy'" thrown in the test body. TEST_F(JSONValueTest, DISABLED_Path) { - Value v; - v.mkPath("test"); + Value v = {NewValueAs::path, "test"}; ASSERT_EQ(getJSONValue(v), "\"/nix/store/g1w7hy3qg1w7hy3qg1w7hy3qg1w7hy3q-x\""); } } /* namespace nix */ diff --git a/tests/unit/libexpr/value/print.cc b/tests/unit/libexpr/value/print.cc index 99ca558d6..40c965e1f 100644 --- a/tests/unit/libexpr/value/print.cc +++ b/tests/unit/libexpr/value/print.cc @@ -45,8 +45,7 @@ TEST_F(ValuePrintingTests, tString) TEST_F(ValuePrintingTests, tPath) { - Value vPath; - vPath.mkPath("/foo"); + Value vPath = {NewValueAs::path, "/foo"}; test(vPath, "/foo"); } @@ -382,8 +381,7 @@ TEST_F(ValuePrintingTests, ansiColorsStringElided) TEST_F(ValuePrintingTests, ansiColorsPath) { - Value v; - v.mkPath(CanonPath("puppy")); + Value v = {NewValueAs::path, CanonPath("puppy")}; test(v, ANSI_GREEN "/puppy" ANSI_NORMAL,