MCPcopy Index your code
hub / github.com/RustPython/RustPython / with_recursion

Method with_recursion

crates/vm/src/vm/mod.rs:1539–1550  ·  view source on GitHub ↗

Used to run the body of a (possibly) recursive function. It will raise a RecursionError if recursive functions are nested far too many times, preventing a stack overflow.

(&self, _where: &str, f: F)

Source from the content-addressed store, hash-verified

1537 /// RecursionError if recursive functions are nested far too many times,
1538 /// preventing a stack overflow.
1539 pub fn with_recursion<R, F: FnOnce() -> PyResult<R>>(&self, _where: &str, f: F) -> PyResult<R> {
1540 self.check_recursive_call(_where)?;
1541
1542 // Native stack guard: check C stack like _Py_MakeRecCheck
1543 if self.check_c_stack_overflow() {
1544 return Err(self.new_recursion_error(_where.to_string()));
1545 }
1546
1547 self.recursion_depth.update(|d| d + 1);
1548 scopeguard::defer! { self.recursion_depth.update(|d| d - 1) }
1549 f()
1550 }
1551
1552 pub fn with_frame<R, F: FnOnce(FrameRef) -> PyResult<R>>(
1553 &self,

Callers 6

_cmpMethod · 0.80
reprMethod · 0.80
abstract_issubclassMethod · 0.80
is_subclassMethod · 0.80
with_frame_implMethod · 0.80

Calls 6

check_recursive_callMethod · 0.80
to_stringMethod · 0.80
ErrClass · 0.50
fFunction · 0.50
updateMethod · 0.45

Tested by

no test coverage detected