libexpr: Convert Value::mkStringMove to a constructor

The pseudo-constructor `Value::mkStringMove` would previously be called
on a default-constructed (under-initialized) `Value` to create a
properly initialized `Value` that represents a string, reusing an
existing GC allocated Str. This change turns that method into a proper
constructor

Change-Id: I8d7a97e2afce231a04ecf56fdd6d22d06a6a6964
This commit is contained in:
skye
2026-02-23 11:40:02 -05:00
parent 6b9a121637
commit 492d7bbe1f
3 changed files with 8 additions and 4 deletions
+1 -1
View File
@@ -541,7 +541,7 @@ void ExprConcatStrings::eval(EvalState & state, Env & env, Value & v)
}
v = {NewValueAs::path, CanonPath(canonPath(str()))};
} else {
v.mkStringMove(gcStr(), context);
v = {NewValueAs::string, gcStr(), context};
}
}
+1 -1
View File
@@ -74,7 +74,7 @@ void Value::mkString(std::string_view s, const NixStringContext & context)
copyContextToValue(*untag<String *>(), context);
}
void Value::mkStringMove(Str * s, const NixStringContext & context)
Value::Value(string_t, Str * s, const NixStringContext & context)
{
auto block = gcAllocType<String>();
*block = {.content = s, .context = nullptr};
+6 -2
View File
@@ -447,6 +447,12 @@ public:
raw = tag(tString, block);
}
/// Constructs a nix language value of type "string", with the value of the
/// C-string pointed to by @ref s, and context from @ref context.
///
/// The C-string is not copied but the data from context is
Value(string_t, Str * s, const NixStringContext & context);
Value(string_t, const String * str) : raw(tag(tString, str)) {}
/// Constructx a nix language value of type "string", with a copy of the
@@ -784,8 +790,6 @@ public:
void mkString(std::string_view s, const NixStringContext & context);
void mkStringMove(Str * s, const NixStringContext & context);
inline void mkNull()
{
*this = {NewValueAs::null};