From 9411299875cb8e49289500df64a568050bbf5dca Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Thu, 12 May 2022 20:37:18 +0200 Subject: [PATCH] Fix GC bug in ExprPath --- src/libexpr/eval.cc | 5 +---- src/libexpr/eval.hh | 10 +++++----- src/libexpr/nixexpr.cc | 2 +- src/libexpr/nixexpr.hh | 8 ++++---- src/libexpr/value.hh | 8 ++++++++ 5 files changed, 19 insertions(+), 14 deletions(-) diff --git a/src/libexpr/eval.cc b/src/libexpr/eval.cc index 2c1b64d7f..4e1de843c 100644 --- a/src/libexpr/eval.cc +++ b/src/libexpr/eval.cc @@ -890,10 +890,7 @@ void Value::mkStringMove(const char * s, const PathSet & context) void Value::mkPath(const SourcePath & path) { - clearValue(); - internalType = tPath; - _path.accessor = &path.accessor; - _path.path = makeImmutableString(path.path); + mkPath(&path.accessor, makeImmutableString(path.path)); } diff --git a/src/libexpr/eval.hh b/src/libexpr/eval.hh index 7d4d870f7..505f6e538 100644 --- a/src/libexpr/eval.hh +++ b/src/libexpr/eval.hh @@ -50,16 +50,16 @@ struct Env void copyContext(const Value & v, PathSet & context); -// FIXME: maybe change this to an std::variant. -typedef std::pair SearchPathElem; -typedef std::list SearchPath; - - std::ostream & printValue(const EvalState & state, std::ostream & str, const Value & v); std::string printValue(const EvalState & state, const Value & v); std::ostream & operator << (std::ostream & os, const ValueType t); +// FIXME: maybe change this to an std::variant. +typedef std::pair SearchPathElem; +typedef std::list SearchPath; + + /* Initialise the Boehm GC, if applicable. */ void initGC(); diff --git a/src/libexpr/nixexpr.cc b/src/libexpr/nixexpr.cc index c529fdc89..788859d2e 100644 --- a/src/libexpr/nixexpr.cc +++ b/src/libexpr/nixexpr.cc @@ -73,7 +73,7 @@ void ExprString::show(const SymbolTable & symbols, std::ostream & str) const void ExprPath::show(const SymbolTable & symbols, std::ostream & str) const { - str << s; + str << path; } void ExprVar::show(const SymbolTable & symbols, std::ostream & str) const diff --git a/src/libexpr/nixexpr.hh b/src/libexpr/nixexpr.hh index 953e97419..2cb2aca3a 100644 --- a/src/libexpr/nixexpr.hh +++ b/src/libexpr/nixexpr.hh @@ -183,12 +183,12 @@ struct ExprString : Expr struct ExprPath : Expr { - std::string s; // FIXME: remove + const SourcePath path; Value v; - ExprPath(SourcePath && path) - : s(path.path) + ExprPath(SourcePath && _path) + : path(_path) { - v.mkPath(std::move(path)); + v.mkPath(&path.accessor, path.path.c_str()); } COMMON_METHODS Value * maybeThunk(EvalState & state, Env & env); diff --git a/src/libexpr/value.hh b/src/libexpr/value.hh index 9050a30ab..fb1139647 100644 --- a/src/libexpr/value.hh +++ b/src/libexpr/value.hh @@ -263,6 +263,14 @@ public: void mkPath(const SourcePath & path); + inline void mkPath(InputAccessor * accessor, const char * path) + { + clearValue(); + internalType = tPath; + _path.accessor = accessor; + _path.path = path; + } + inline void mkNull() { clearValue();