From 770034042a3e7cb7f3a9f7a271ab45e44b0d006c Mon Sep 17 00:00:00 2001 From: Kane York Date: Fri, 31 Jul 2020 15:12:11 -0700 Subject: fix(3p/nix): Use a proper pointer in Env to carry with-attrs This eliminates the value-smuggling that would trip up the GC. Change-Id: I8057df78cf0bf6bea9faf1b44233aa9820ae44f5 Reviewed-on: https://cl.tvl.fyi/c/depot/+/1504 Tested-by: BuildkiteCI Reviewed-by: glittershark Reviewed-by: tazjin --- third_party/nix/src/libexpr/eval.cc | 13 ++++++++----- third_party/nix/src/libexpr/eval.hh | 1 + 2 files changed, 9 insertions(+), 5 deletions(-) (limited to 'third_party/nix/src') diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc index 3d134be19e29..e04bf7fc4918 100644 --- a/third_party/nix/src/libexpr/eval.cc +++ b/third_party/nix/src/libexpr/eval.cc @@ -600,10 +600,13 @@ inline Value* EvalState::lookupVar(Env* env, const ExprVar& var, bool noEval) { if (noEval) { return nullptr; } + if (!env->withAttrsExpr) { + CHECK(false) << "HasWithExpr evaluated twice"; + } Value* v = allocValue(); - // TODO(kanepyork): Here's the other end of the cast smuggle. - evalAttrs(*env->up, reinterpret_cast(env->values[0]), *v); + evalAttrs(*env->up, env->withAttrsExpr, *v); env->values[0] = v; + env->withAttrsExpr = nullptr; env->type = Env::HasWithAttrs; } Bindings::iterator j = env->values[0]->attrs->find(var.name); @@ -1179,9 +1182,9 @@ void ExprWith::eval(EvalState& state, Env& env, Value& v) { env2.up = &env; env2.prevWith = prevWith; env2.type = Env::HasWithExpr; - // TODO(kanepyork): Figure out what's going on here. `Expr* attrs` is not - // layout-compatible with Value*. - env2.values[0] = reinterpret_cast(attrs); + /* placeholder for result of attrs */ + env2.values[0] = nullptr; + env2.withAttrsExpr = this->attrs; body->eval(state, env2, v); } diff --git a/third_party/nix/src/libexpr/eval.hh b/third_party/nix/src/libexpr/eval.hh index 199253bc451b..2c285ed5c111 100644 --- a/third_party/nix/src/libexpr/eval.hh +++ b/third_party/nix/src/libexpr/eval.hh @@ -42,6 +42,7 @@ struct Env : public gc { unsigned short prevWith : 14; // nr of levels up to next `with' environment enum { Plain = 0, HasWithExpr, HasWithAttrs } type : 2; std::vector> values; + Expr* withAttrsExpr = nullptr; }; Value& mkString(Value& v, const std::string& s, -- cgit 1.4.1