Merge pull request #15291 from roberth/fix-evalstate-shared-from-this-usage
fix(EvalState): Use make_shared for enable_shared_from_this compatibi…
This commit is contained in:
@@ -185,7 +185,9 @@ EvalState * nix_eval_state_build(nix_c_context * context, nix_eval_state_builder
|
||||
return EvalState{
|
||||
.fetchSettings = std::move(builder->fetchSettings),
|
||||
.settings = std::move(builder->settings),
|
||||
.state = nix::EvalState(builder->lookupPath, builder->store, self->fetchSettings, self->settings),
|
||||
.statePtr = std::make_shared<nix::EvalState>(
|
||||
builder->lookupPath, builder->store, self->fetchSettings, self->settings),
|
||||
.state = *self->statePtr,
|
||||
};
|
||||
});
|
||||
}
|
||||
|
||||
@@ -24,7 +24,8 @@ struct EvalState
|
||||
{
|
||||
nix::fetchers::Settings fetchSettings;
|
||||
nix::EvalSettings settings;
|
||||
nix::EvalState state;
|
||||
std::shared_ptr<nix::EvalState> statePtr;
|
||||
nix::EvalState & state;
|
||||
};
|
||||
|
||||
struct BindingsBuilder
|
||||
|
||||
@@ -37,7 +37,8 @@ static void BM_EvalDynamicAttrs(benchmark::State & state)
|
||||
EvalSettings evalSettings{readOnlyMode};
|
||||
evalSettings.nixPath = {};
|
||||
|
||||
EvalState st({}, store, fetchSettings, evalSettings, nullptr);
|
||||
auto stPtr = std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr);
|
||||
auto & st = *stPtr;
|
||||
Expr * expr = st.parseExprFromString(exprStr, st.rootPath(CanonPath::root));
|
||||
|
||||
Value v;
|
||||
|
||||
@@ -16,7 +16,8 @@ struct GetDerivationsEnv
|
||||
fetchers::Settings fetchSettings{};
|
||||
bool readOnlyMode = true;
|
||||
EvalSettings evalSettings{readOnlyMode};
|
||||
EvalState state;
|
||||
std::shared_ptr<EvalState> statePtr;
|
||||
EvalState & state;
|
||||
|
||||
Bindings * autoArgs = nullptr;
|
||||
Value attrsValue;
|
||||
@@ -27,7 +28,8 @@ struct GetDerivationsEnv
|
||||
settings.nixPath = {};
|
||||
return settings;
|
||||
}())
|
||||
, state({}, store, fetchSettings, evalSettings, nullptr)
|
||||
, statePtr(std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr))
|
||||
, state(*statePtr)
|
||||
{
|
||||
autoArgs = state.buildBindings(0).finish();
|
||||
|
||||
|
||||
@@ -27,7 +27,8 @@ static void BM_EvalManyBuiltinsMatchSameRegex(benchmark::State & state)
|
||||
EvalSettings evalSettings{readOnlyMode};
|
||||
evalSettings.nixPath = {};
|
||||
|
||||
EvalState st({}, store, fetchSettings, evalSettings, nullptr);
|
||||
auto stPtr = std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings, nullptr);
|
||||
auto & st = *stPtr;
|
||||
Expr * expr = st.parseExprFromString(std::string(exprStr), st.rootPath(CanonPath::root));
|
||||
|
||||
Value v;
|
||||
|
||||
@@ -247,11 +247,12 @@ static void showHelp(std::vector<std::string> subcommand, NixArgs & toplevel)
|
||||
|
||||
evalSettings.restrictEval = true;
|
||||
evalSettings.pureEval = true;
|
||||
EvalState state(
|
||||
{},
|
||||
auto statePtr = std::make_shared<EvalState>(
|
||||
LookupPath{},
|
||||
openStore(StoreReference{.variant = StoreReference::Specified{.scheme = "dummy"}}),
|
||||
fetchSettings,
|
||||
evalSettings);
|
||||
auto & state = *statePtr;
|
||||
|
||||
auto vGenerateManpage = state.allocValue();
|
||||
state.eval(
|
||||
@@ -454,11 +455,12 @@ void mainWrapped(int argc, char ** argv)
|
||||
Xp::FetchTree,
|
||||
};
|
||||
evalSettings.pureEval = false;
|
||||
EvalState state(
|
||||
{},
|
||||
auto statePtr = std::make_shared<EvalState>(
|
||||
LookupPath{},
|
||||
openStore(StoreReference{.variant = StoreReference::Specified{.scheme = "dummy"}}),
|
||||
fetchSettings,
|
||||
evalSettings);
|
||||
auto & state = *statePtr;
|
||||
auto builtinsJson = nlohmann::json::object();
|
||||
for (auto & builtinPtr : state.getBuiltins().attrs()->lexicographicOrder(state.symbols)) {
|
||||
auto & builtin = *builtinPtr;
|
||||
|
||||
@@ -315,7 +315,7 @@ static void main_nix_build(int argc, char ** argv)
|
||||
auto store = openStore();
|
||||
auto evalStore = myArgs.evalStoreUrl ? openStore(StoreReference{*myArgs.evalStoreUrl}) : store;
|
||||
|
||||
auto state = std::make_unique<EvalState>(myArgs.lookupPath, evalStore, fetchSettings, evalSettings, store);
|
||||
auto state = std::make_shared<EvalState>(myArgs.lookupPath, evalStore, fetchSettings, evalSettings, store);
|
||||
state->repair = myArgs.repair;
|
||||
if (myArgs.repair)
|
||||
buildMode = bmRepair;
|
||||
|
||||
@@ -169,7 +169,7 @@ static int main_nix_instantiate(int argc, char ** argv)
|
||||
auto store = openStore();
|
||||
auto evalStore = myArgs.evalStoreUrl ? openStore(StoreReference{*myArgs.evalStoreUrl}) : store;
|
||||
|
||||
auto state = std::make_unique<EvalState>(myArgs.lookupPath, evalStore, fetchSettings, evalSettings, store);
|
||||
auto state = std::make_shared<EvalState>(myArgs.lookupPath, evalStore, fetchSettings, evalSettings, store);
|
||||
state->repair = myArgs.repair;
|
||||
|
||||
Bindings & autoArgs = *myArgs.getAutoArgs(*state);
|
||||
|
||||
@@ -203,7 +203,7 @@ static int main_nix_prefetch_url(int argc, char ** argv)
|
||||
setLogFormat("bar");
|
||||
|
||||
auto store = openStore();
|
||||
auto state = std::make_unique<EvalState>(myArgs.lookupPath, store, fetchSettings, evalSettings);
|
||||
auto state = std::make_shared<EvalState>(myArgs.lookupPath, store, fetchSettings, evalSettings);
|
||||
|
||||
Bindings & autoArgs = *myArgs.getAutoArgs(*state);
|
||||
|
||||
|
||||
@@ -182,7 +182,7 @@ struct CmdUpgradeNix : MixDryRun, StoreCommand
|
||||
auto req = FileTransferRequest(parseURL(upgradeSettings.storePathUrl.get()));
|
||||
auto res = getFileTransfer()->download(req);
|
||||
|
||||
auto state = std::make_unique<EvalState>(LookupPath{}, store, fetchSettings, evalSettings);
|
||||
auto state = std::make_shared<EvalState>(LookupPath{}, store, fetchSettings, evalSettings);
|
||||
auto v = state->allocValue();
|
||||
state->eval(state->parseExprFromString(res.data, state->rootPath(CanonPath("/no-such-path"))), *v);
|
||||
Bindings & bindings = Bindings::emptyBindings;
|
||||
|
||||
Reference in New Issue
Block a user