libexpr: Replace Value::mkPath with constructor calls
The pseudo-constructor `Value::mkPath` would previously be called on an default-constructed (under-initialized) `Value` to create a properly initialized `Value` that represents a path. This change removes mkPath and constructs path `Value`s directly. Change-Id: I9021de1ff59490828f9fec6866e083996a6a6964
This commit is contained in:
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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};
|
||||
|
||||
@@ -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[] =
|
||||
|
||||
+12
-9
@@ -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<String>();
|
||||
*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<String>();
|
||||
*block = {.content = Str::gcCopy(path), .context = String::path};
|
||||
raw = tag(tString, block);
|
||||
}
|
||||
|
||||
inline void mkNull()
|
||||
{
|
||||
*this = {NewValueAs::null};
|
||||
|
||||
@@ -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 */
|
||||
|
||||
@@ -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,
|
||||
|
||||
Reference in New Issue
Block a user