|
29 | 29 |
|
30 | 30 | #include <cmath> |
31 | 31 |
|
32 | | - |
33 | 32 | namespace nix { |
34 | 33 |
|
35 | 34 |
|
@@ -2550,6 +2549,7 @@ static void prim_removeAttrs(EvalState & state, const PosIdx pos, Value * * args |
2550 | 2549 | /* Get the attribute names to be removed. |
2551 | 2550 | We keep them as Attrs instead of Symbols so std::set_difference |
2552 | 2551 | can be used to remove them from attrs[0]. */ |
| 2552 | + // 64: large enough to fit the attributes of a derivation |
2553 | 2553 | boost::container::small_vector<Attr, 64> names; |
2554 | 2554 | names.reserve(args[1]->listSize()); |
2555 | 2555 | for (auto elem : args[1]->listItems()) { |
@@ -2729,8 +2729,8 @@ static void prim_catAttrs(EvalState & state, const PosIdx pos, Value * * args, V |
2729 | 2729 | auto attrName = state.symbols.create(state.forceStringNoCtx(*args[0], pos, "while evaluating the first argument passed to builtins.catAttrs")); |
2730 | 2730 | state.forceList(*args[1], pos, "while evaluating the second argument passed to builtins.catAttrs"); |
2731 | 2731 |
|
2732 | | - Value * res[args[1]->listSize()]; |
2733 | | - unsigned int found = 0; |
| 2732 | + boost::container::small_vector<Value *, nonRecursiveStackReservation> res(args[1]->listSize()); |
| 2733 | + size_t found = 0; |
2734 | 2734 |
|
2735 | 2735 | for (auto v2 : args[1]->listItems()) { |
2736 | 2736 | state.forceAttrs(*v2, pos, "while evaluating an element in the list passed as second argument to builtins.catAttrs"); |
@@ -3064,9 +3064,8 @@ static void prim_filter(EvalState & state, const PosIdx pos, Value * * args, Val |
3064 | 3064 |
|
3065 | 3065 | state.forceFunction(*args[0], pos, "while evaluating the first argument passed to builtins.filter"); |
3066 | 3066 |
|
3067 | | - // FIXME: putting this on the stack is risky. |
3068 | | - Value * vs[args[1]->listSize()]; |
3069 | | - unsigned int k = 0; |
| 3067 | + boost::container::small_vector<Value *, nonRecursiveStackReservation> vs(args[1]->listSize()); |
| 3068 | + size_t k = 0; |
3070 | 3069 |
|
3071 | 3070 | bool same = true; |
3072 | 3071 | for (unsigned int n = 0; n < args[1]->listSize(); ++n) { |
@@ -3191,10 +3190,14 @@ static void anyOrAll(bool any, EvalState & state, const PosIdx pos, Value * * ar |
3191 | 3190 | state.forceFunction(*args[0], pos, std::string("while evaluating the first argument passed to builtins.") + (any ? "any" : "all")); |
3192 | 3191 | state.forceList(*args[1], pos, std::string("while evaluating the second argument passed to builtins.") + (any ? "any" : "all")); |
3193 | 3192 |
|
| 3193 | + std::string_view errorCtx = any |
| 3194 | + ? "while evaluating the return value of the function passed to builtins.any" |
| 3195 | + : "while evaluating the return value of the function passed to builtins.all"; |
| 3196 | + |
3194 | 3197 | Value vTmp; |
3195 | 3198 | for (auto elem : args[1]->listItems()) { |
3196 | 3199 | state.callFunction(*args[0], *elem, vTmp, pos); |
3197 | | - bool res = state.forceBool(vTmp, pos, std::string("while evaluating the return value of the function passed to builtins.") + (any ? "any" : "all")); |
| 3200 | + bool res = state.forceBool(vTmp, pos, errorCtx); |
3198 | 3201 | if (res == any) { |
3199 | 3202 | v.mkBool(any); |
3200 | 3203 | return; |
@@ -3450,7 +3453,7 @@ static void prim_concatMap(EvalState & state, const PosIdx pos, Value * * args, |
3450 | 3453 | state.forceList(*args[1], pos, "while evaluating the second argument passed to builtins.concatMap"); |
3451 | 3454 | auto nrLists = args[1]->listSize(); |
3452 | 3455 |
|
3453 | | - Value lists[nrLists]; |
| 3456 | + boost::container::small_vector<Value, conservativeStackReservation> lists(nrLists); |
3454 | 3457 | size_t len = 0; |
3455 | 3458 |
|
3456 | 3459 | for (unsigned int n = 0; n < nrLists; ++n) { |
|
0 commit comments