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

Function _getframe

crates/vm/src/stdlib/sys.rs:992–1002  ·  view source on GitHub ↗
(offset: OptionalArg<usize>, vm: &VirtualMachine)

Source from the content-addressed store, hash-verified

990
991 #[pyfunction]
992 fn _getframe(offset: OptionalArg<usize>, vm: &VirtualMachine) -> PyResult<FrameRef> {
993 let offset = offset.into_option().unwrap_or(0);
994 let frames = vm.frames.borrow();
995 if offset >= frames.len() {
996 return Err(vm.new_value_error("call stack is not deep enough"));
997 }
998 let idx = frames.len() - offset - 1;
999 // SAFETY: the FrameRef is alive on the call stack while it's in the Vec
1000 let py: &crate::Py<Frame> = unsafe { frames[idx].as_ref() };
1001 Ok(py.to_owned())
1002 }
1003
1004 #[pyfunction]
1005 fn _getframemodulename(depth: OptionalArg<usize>, vm: &VirtualMachine) -> PyResult {

Callers

nothing calls this directly

Calls 6

into_optionMethod · 0.80
ErrClass · 0.50
borrowMethod · 0.45
lenMethod · 0.45
as_refMethod · 0.45
to_ownedMethod · 0.45

Tested by

no test coverage detected