From f17439a9d36f2e10ea59884aea18cd84d5853804 Mon Sep 17 00:00:00 2001 From: Jason Turner Date: Thu, 1 Dec 2016 13:42:40 -0700 Subject: [PATCH] Add scope around condition in for/while * solves issue with rapidly expanding memory usage if function variable use stack is growing rapidly --- include/chaiscript/language/chaiscript_eval.hpp | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/include/chaiscript/language/chaiscript_eval.hpp b/include/chaiscript/language/chaiscript_eval.hpp index 2fba032b..adc86ed4 100644 --- a/include/chaiscript/language/chaiscript_eval.hpp +++ b/include/chaiscript/language/chaiscript_eval.hpp @@ -96,6 +96,11 @@ namespace chaiscript { } + static bool get_scoped_bool_condition(const AST_Node_Impl &node, const chaiscript::detail::Dispatch_State &t_ss) { + chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); + return get_bool_condition(node.eval(t_ss), t_ss); + } + std::vector get_children() const final { return {children.begin(), children.end()}; @@ -746,7 +751,7 @@ namespace chaiscript chaiscript::eval::detail::Scope_Push_Pop spp(t_ss); try { - while (this->get_bool_condition(this->children[0]->eval(t_ss), t_ss)) { + while (this->get_scoped_bool_condition(*this->children[0], t_ss)) { try { this->children[1]->eval(t_ss); } catch (detail::Continue_Loop &) { @@ -889,7 +894,7 @@ namespace chaiscript try { for ( this->children[0]->eval(t_ss); - this->get_bool_condition(this->children[1]->eval(t_ss), t_ss); + this->get_scoped_bool_condition(*this->children[1], t_ss); this->children[2]->eval(t_ss) ) { try {