use Counter class to count tryEval levels
This commit is contained in:
parent
bc0d41e9ba
commit
8cf6ae8664
|
@ -846,23 +846,31 @@ static RegisterPrimOp primop_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;},
|
||||
* else => {success=false; value=false;} */
|
||||
static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Value & v)
|
||||
{
|
||||
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;
|
||||
if (state.debugRepl)
|
||||
if (state.debugRepl && state.ignoreTry)
|
||||
{
|
||||
state.trylevel++;
|
||||
if (state.ignoreTry)
|
||||
{
|
||||
// to prevent starting the repl from exceptions withing a tryEval, null it.
|
||||
/* to prevent starting the repl from exceptions withing a tryEval, null it. */
|
||||
savedDebugRepl = state.debugRepl;
|
||||
state.debugRepl = nullptr;
|
||||
}
|
||||
}
|
||||
|
||||
try {
|
||||
state.forceValue(*args[0], pos);
|
||||
|
@ -877,9 +885,6 @@ static void prim_tryEval(EvalState & state, const PosIdx pos, Value * * args, Va
|
|||
if (savedDebugRepl)
|
||||
state.debugRepl = savedDebugRepl;
|
||||
|
||||
if (state.debugRepl)
|
||||
state.trylevel--;
|
||||
|
||||
v.mkAttrs(attrs);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue