libexpr: use MaintainCount for call depth

This was duplicate code.

Change-Id: I40697da80c3b8123c9cc3f10e5be5cc49c35629d
This commit is contained in:
Jade Lovelace
2025-12-23 14:18:11 -08:00
committed by Rebecca Turner
parent c0f177081b
commit b2feecf7e7
+1 -16
View File
@@ -1532,21 +1532,6 @@ void ExprLambda::eval(EvalState & state, Env & env, Value & v)
v = {NewValueAs::lambda, state.ctx.mem, env, *this};
}
namespace {
/** Increments a count on construction and decrements on destruction.
*/
class CallDepth {
size_t & count;
public:
CallDepth(size_t & count) : count(count) {
++count;
}
~CallDepth() {
--count;
}
};
};
struct FormalsMatch
{
std::vector<SymbolStr> missing;
@@ -1686,7 +1671,7 @@ void EvalState::callFunction(Value & fun, std::span<Value> args, Value & vRes, c
{
if (callDepth > evalSettings.maxCallDepth)
ctx.errors.make<EvalError>("stack overflow; max-call-depth exceeded").atPos(pos).debugThrow();
CallDepth _level(callDepth);
MaintainCount _level(callDepth);
auto trace = evalSettings.traceFunctionCalls
? std::make_unique<FunctionCallTrace>(ctx.positions[pos])