Merge pull request #3492 from andir/nix-build-gc-free

SourceExprCommand: allocate the vSourceExpr via uncollectable memory
This commit is contained in:
Eelco Dolstra 2020-04-15 13:01:04 +02:00 committed by GitHub
commit 2f9789c2e6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 10 additions and 4 deletions

View file

@ -41,7 +41,7 @@ private:
std::shared_ptr<EvalState> evalState;
Value * vSourceExpr = 0;
std::shared_ptr<Value> vSourceExpr;
};
enum RealiseMode { Build, NoBuild, DryRun };

View file

@ -8,10 +8,13 @@
#include "store-api.hh"
#include "shared.hh"
#include <gc/gc.h>
#include <regex>
namespace nix {
SourceExprCommand::SourceExprCommand()
{
mkFlag()
@ -24,11 +27,14 @@ SourceExprCommand::SourceExprCommand()
Value * SourceExprCommand::getSourceExpr(EvalState & state)
{
if (vSourceExpr) return vSourceExpr;
if (vSourceExpr) return vSourceExpr.get();
auto sToplevel = state.symbols.create("_toplevel");
vSourceExpr = state.allocValue();
// Allocate the vSourceExpr Value as uncollectable. Boehm GC doesn't
// consider the member variable "alive" during execution causing it to be
// GC'ed in the middle of evaluation.
vSourceExpr = std::allocate_shared<Value>(traceable_allocator<Value>());
if (file != "")
state.evalFile(lookupFileArg(state, file), *vSourceExpr);
@ -69,7 +75,7 @@ Value * SourceExprCommand::getSourceExpr(EvalState & state)
vSourceExpr->attrs->sort();
}
return vSourceExpr;
return vSourceExpr.get();
}
ref<EvalState> SourceExprCommand::getEvalState()