diff --git a/third_party/nix/src/libexpr/eval.cc b/third_party/nix/src/libexpr/eval.cc index 28ae46bdf..2a0aba1a4 100644 --- a/third_party/nix/src/libexpr/eval.cc +++ b/third_party/nix/src/libexpr/eval.cc @@ -598,15 +598,15 @@ Env& EvalState::allocEnv(size_t size) { return *env; } -void EvalState::mkList(Value& v, NixList* list) { +void EvalState::mkList(Value& v, std::shared_ptr list) { + nrListElems += list->size(); clearValue(v); v.type = tList; v.list = list; - nrListElems += list->size(); } void EvalState::mkList(Value& v, size_t size) { - EvalState::mkList(v, new NixList(size)); + EvalState::mkList(v, std::make_shared(size)); } unsigned long nrThunks = 0; @@ -1224,7 +1224,7 @@ void ExprOpConcatLists::eval(EvalState& state, Env& env, Value& v) { void EvalState::concatLists(Value& v, const NixList& lists, const Pos& pos) { nrListConcats++; - auto outlist = new NixList(); + auto outlist = std::make_shared(); for (Value* list : lists) { forceList(*list, pos); @@ -1816,8 +1816,8 @@ size_t valueSize(const Value& v) { } break; case tList: - if (seenLists.find(v.list) == seenLists.end()) { - seenLists.insert(v.list); + if (seenLists.find(v.list.get()) == seenLists.end()) { + seenLists.insert(v.list.get()); sz += v.listSize() * sizeof(Value*); for (const Value* v : *v.list) { sz += doValue(*v); diff --git a/third_party/nix/src/libexpr/eval.hh b/third_party/nix/src/libexpr/eval.hh index f36d11b92..0352a89a2 100644 --- a/third_party/nix/src/libexpr/eval.hh +++ b/third_party/nix/src/libexpr/eval.hh @@ -258,7 +258,7 @@ class EvalState { Value* allocAttr(Value& vAttrs, const Symbol& name); // Create a list value from the specified vector. - void mkList(Value& v, NixList* list); + void mkList(Value& v, std::shared_ptr list); // Create a list value, allocating as many elements as specified in // size. This is used for the many cases in this codebase where diff --git a/third_party/nix/src/libexpr/primops.cc b/third_party/nix/src/libexpr/primops.cc index dd8a509df..761ff954a 100644 --- a/third_party/nix/src/libexpr/primops.cc +++ b/third_party/nix/src/libexpr/primops.cc @@ -1603,7 +1603,7 @@ static void prim_sort(EvalState& state, const Pos& pos, Value** args, // Copy of the input list which can be sorted in place. v.type = tList; - v.list = new NixList(*args[1]->list); + v.list = std::make_shared(*args[1]->list); std::for_each(v.list->begin(), v.list->end(), [&](Value* val) { state.forceValue(*val); }); @@ -1633,8 +1633,8 @@ static void prim_partition(EvalState& state, const Pos& pos, Value** args, state.forceFunction(*args[0], pos); state.forceList(*args[1], pos); - NixList* right = new NixList(); - NixList* wrong = new NixList(); + std::shared_ptr right = std::make_shared(); + std::shared_ptr wrong = std::make_shared(); for (Value* elem : *args[1]->list) { state.forceValue(*elem, pos); @@ -1664,7 +1664,7 @@ static void prim_concatMap(EvalState& state, const Pos& pos, Value** args, state.forceFunction(*args[0], pos); state.forceList(*args[1], pos); - NixList* outlist = new NixList; + std::shared_ptr outlist = std::make_shared(); for (Value* elem : *args[1]->list) { auto out = state.allocValue(); diff --git a/third_party/nix/src/libexpr/value.hh b/third_party/nix/src/libexpr/value.hh index 82360c566..b5a1a33cb 100644 --- a/third_party/nix/src/libexpr/value.hh +++ b/third_party/nix/src/libexpr/value.hh @@ -96,7 +96,7 @@ struct Value { NixString string; const char* path; std::shared_ptr attrs; - NixList* list; + std::shared_ptr list; NixThunk thunk; NixApp app; // TODO(tazjin): "app"? NixLambda lambda;