mirror of
https://github.com/NixOS/nix
synced 2025-06-24 22:11:15 +02:00
Mark Value pointers in Value::elems as const
This catches modification of finalized values (e.g. in prim_sort).
This commit is contained in:
parent
fecff520d7
commit
3e6730ee62
4 changed files with 7 additions and 6 deletions
|
@ -3372,7 +3372,6 @@ static void prim_sort(EvalState & state, const PosIdx pos, Value * * args, Value
|
|||
auto list = state.buildList(len);
|
||||
for (const auto & [n, v] : enumerate(list))
|
||||
state.forceValue(*(v = args[1]->listElems()[n]), pos);
|
||||
v.mkList(list);
|
||||
|
||||
auto comparator = [&](Value * a, Value * b) {
|
||||
/* Optimization: if the comparator is lessThan, bypass
|
||||
|
@ -3391,7 +3390,9 @@ static void prim_sort(EvalState & state, const PosIdx pos, Value * * args, Value
|
|||
/* FIXME: std::sort can segfault if the comparator is not a strict
|
||||
weak ordering. What to do? std::stable_sort() seems more
|
||||
resilient, but no guarantees... */
|
||||
std::stable_sort(v.listElems(), v.listElems() + len, comparator);
|
||||
std::stable_sort(list.begin(), list.end(), comparator);
|
||||
|
||||
v.mkList(list);
|
||||
}
|
||||
|
||||
static RegisterPrimOp primop_sort({
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue