= frame_clear_impl
(&self, vm: &VirtualMachine)
| 670 | #[pymethod] |
| 671 | // = frame_clear_impl |
| 672 | fn clear(&self, vm: &VirtualMachine) -> PyResult<()> { |
| 673 | let owner = FrameOwner::from_i8(self.owner.load(core::sync::atomic::Ordering::Acquire)); |
| 674 | match owner { |
| 675 | FrameOwner::Generator => { |
| 676 | // Generator frame: check if suspended (lasti > 0 means |
| 677 | // FRAME_SUSPENDED). lasti == 0 means FRAME_CREATED and |
| 678 | // can be cleared. |
| 679 | if self.lasti() != 0 { |
| 680 | return Err(vm.new_runtime_error("cannot clear a suspended frame")); |
| 681 | } |
| 682 | } |
| 683 | FrameOwner::Thread => { |
| 684 | // Thread-owned frame: always executing, cannot clear. |
| 685 | return Err(vm.new_runtime_error("cannot clear an executing frame")); |
| 686 | } |
| 687 | FrameOwner::FrameObject => { |
| 688 | // Detached frame: safe to clear. |
| 689 | } |
| 690 | } |
| 691 | |
| 692 | // Clear fastlocals |
| 693 | // SAFETY: Frame is not executing (detached or stopped). |
| 694 | { |
| 695 | let fastlocals = unsafe { self.fastlocals_mut() }; |
| 696 | for slot in fastlocals.iter_mut() { |
| 697 | *slot = None; |
| 698 | } |
| 699 | } |
| 700 | |
| 701 | // Clear the evaluation stack and cell references |
| 702 | self.clear_stack_and_cells(); |
| 703 | |
| 704 | // Clear temporary refs |
| 705 | self.temporary_refs.lock().clear(); |
| 706 | |
| 707 | Ok(()) |
| 708 | } |
| 709 | |
| 710 | #[pygetset] |
| 711 | fn f_generator(&self) -> Option<PyObjectRef> { |
nothing calls this directly
no test coverage detected