From 492d7bbe1f3cbaa4a6ebc6d0fb6ebd1b50253701 Mon Sep 17 00:00:00 2001 From: skye Date: Thu, 19 Feb 2026 18:44:29 -0500 Subject: [PATCH] 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 --- lix/libexpr/eval-expr.cc | 2 +- lix/libexpr/value.cc | 2 +- lix/libexpr/value.hh | 8 ++++++-- 3 files changed, 8 insertions(+), 4 deletions(-) diff --git a/lix/libexpr/eval-expr.cc b/lix/libexpr/eval-expr.cc index 11566d8c2..414bb297c 100644 --- a/lix/libexpr/eval-expr.cc +++ b/lix/libexpr/eval-expr.cc @@ -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}; } } diff --git a/lix/libexpr/value.cc b/lix/libexpr/value.cc index 420fd5b22..c720ea1bc 100644 --- a/lix/libexpr/value.cc +++ b/lix/libexpr/value.cc @@ -74,7 +74,7 @@ void Value::mkString(std::string_view s, const NixStringContext & context) copyContextToValue(*untag(), context); } -void Value::mkStringMove(Str * s, const NixStringContext & context) +Value::Value(string_t, Str * s, const NixStringContext & context) { auto block = gcAllocType(); *block = {.content = s, .context = nullptr}; diff --git a/lix/libexpr/value.hh b/lix/libexpr/value.hh index 1b443e9bb..4a35abf41 100644 --- a/lix/libexpr/value.hh +++ b/lix/libexpr/value.hh @@ -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};