Merge pull request #3311 from pheki/recursion-limit

Guarantee recursion_depth is never higher than recursion_limit
This commit is contained in:
Jim Fasarakis-Hilliard
2021-10-15 09:16:57 +03:00
committed by GitHub
2 changed files with 3 additions and 2 deletions

View File

@@ -479,7 +479,7 @@ mod sys {
})?;
let recursion_depth = vm.current_recursion_depth();
if recursion_limit > recursion_depth + 1 {
if recursion_limit > recursion_depth {
vm.recursion_limit.set(recursion_limit);
Ok(())
} else {

View File

@@ -538,8 +538,9 @@ impl VirtualMachine {
self.with_frame(frame, |f| f.run(self))
}
// To be called right before raising the recursion depth.
fn check_recursive_call(&self, _where: &str) -> PyResult<()> {
if self.recursion_depth.get() > self.recursion_limit.get() {
if self.recursion_depth.get() >= self.recursion_limit.get() {
Err(self.new_recursion_error(format!("maximum recursion depth exceeded {}", _where)))
} else {
Ok(())