Build a pickle-compatible reduce tuple. `func` must be resolved **before** acquiring any lock that guards this `PositionIterInternal`, so that the builtins lookup cannot trigger reentrant iterator access and deadlock.
(
&self,
func: PyObjectRef,
active: F,
empty: E,
vm: &VirtualMachine,
)
| 74 | /// `PositionIterInternal`, so that the builtins lookup cannot trigger |
| 75 | /// reentrant iterator access and deadlock. |
| 76 | pub fn reduce<F, E>( |
| 77 | &self, |
| 78 | func: PyObjectRef, |
| 79 | active: F, |
| 80 | empty: E, |
| 81 | vm: &VirtualMachine, |
| 82 | ) -> PyTupleRef |
| 83 | where |
| 84 | F: FnOnce(&T) -> PyObjectRef, |
| 85 | E: FnOnce(&VirtualMachine) -> PyObjectRef, |
| 86 | { |
| 87 | if let IterStatus::Active(obj) = &self.status { |
| 88 | vm.new_tuple((func, (active(obj),), self.position)) |
| 89 | } else { |
| 90 | vm.new_tuple((func, (empty(vm),))) |
| 91 | } |
| 92 | } |
| 93 | |
| 94 | fn _next<F, OP>(&mut self, f: F, op: OP) -> PyResult<PyIterReturn> |
| 95 | where |