diff --git a/cubescript.cc b/cubescript.cc index 64a0b0b8..4d145532 100644 --- a/cubescript.cc +++ b/cubescript.cc @@ -2625,14 +2625,15 @@ cleanup: } static constexpr int MaxRunDepth = 255; +static thread_local int rundepth = 0; static ostd::Uint32 const *runcode(CsState &cs, ostd::Uint32 const *code, TaggedValue &result) { result.set_null(); - if (cs.rundepth >= MaxRunDepth) { + if (rundepth >= MaxRunDepth) { cs_debug_code(cs, "exceeded recursion limit"); return skipcode(code, (&result == &no_ret) ? nullptr : &result); } - ++cs.rundepth; + ++rundepth; int numargs = 0; TaggedValue args[MaxArguments + MaxResults], *prevret = cs.result; cs.result = &result; @@ -3322,7 +3323,7 @@ noid: } exit: cs.result = prevret; - --cs.rundepth; + --rundepth; return code; } diff --git a/cubescript.hh b/cubescript.hh index 312525fb..0e85defc 100644 --- a/cubescript.hh +++ b/cubescript.hh @@ -372,7 +372,6 @@ struct OSTD_EXPORT CsState { int nodebug = 0; int numargs = 0; int dbgalias = 4; - int rundepth = 0; CsState(); ~CsState();