| 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 { |