1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2024-09-20 11:11:03 -04:00

use Counter class to count tryEval levels

This commit is contained in:
Ben Burdette 2022-06-02 12:29:38 -06:00
parent bc0d41e9ba
commit 8cf6ae8664

View file

@ -846,22 +846,30 @@ static RegisterPrimOp primop_floor({
.fun = prim_floor, .fun = prim_floor,
}); });
class Counter
{
private:
int &counter;
public:
Counter(int &counter) :counter(counter) { counter++; }
~Counter() { counter--; }
};
/* Try evaluating the argument. Success => {success=true; value=something;}, /* Try evaluating the argument. Success => {success=true; value=something;},
* else => {success=false; value=false;} */ * else => {success=false; value=false;} */
static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Value & v) static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Value & v)
{ {
auto attrs = state.buildBindings(2); auto attrs = state.buildBindings(2);
/* increment state.trylevel, and decrement it when this function returns. */
Counter trylevel(state.trylevel);
void (* savedDebugRepl)(ref<EvalState> es, const ValMap & extraEnv) = nullptr; void (* savedDebugRepl)(ref<EvalState> es, const ValMap & extraEnv) = nullptr;
if (state.debugRepl) if (state.debugRepl && state.ignoreTry)
{ {
state.trylevel++; /* to prevent starting the repl from exceptions withing a tryEval, null it. */
if (state.ignoreTry) savedDebugRepl = state.debugRepl;
{ state.debugRepl = nullptr;
// to prevent starting the repl from exceptions withing a tryEval, null it.
savedDebugRepl = state.debugRepl;
state.debugRepl = nullptr;
}
} }
try { try {
@ -877,9 +885,6 @@ static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Va
if (savedDebugRepl) if (savedDebugRepl)
state.debugRepl = savedDebugRepl; state.debugRepl = savedDebugRepl;
if (state.debugRepl)
state.trylevel--;
v.mkAttrs(attrs); v.mkAttrs(attrs);
} }