From fbd727e769983ddfa2afc20bdfd3f3df94d6eaa8 Mon Sep 17 00:00:00 2001 From: Space0726 Date: Tue, 26 Nov 2019 18:24:35 +0900 Subject: [PATCH] Fix numactive to immutable and Cell type, clarify error handling --- vm/src/stdlib/itertools.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/vm/src/stdlib/itertools.rs b/vm/src/stdlib/itertools.rs index dcc6dcd3b..f114d8076 100644 --- a/vm/src/stdlib/itertools.rs +++ b/vm/src/stdlib/itertools.rs @@ -958,7 +958,7 @@ impl PyItertoolsCombinations { struct PyItertoolsZiplongest { iterators: Vec, fillvalue: PyObjectRef, - numactive: RefCell, + numactive: Cell, } impl PyValue for PyItertoolsZiplongest { @@ -992,7 +992,7 @@ impl PyItertoolsZiplongest { .map(|iterable| get_iter(vm, &iterable)) .collect::, _>>()?; - let numactive = RefCell::new(iterators.len()); + let numactive = Cell::new(iterators.len()); PyItertoolsZiplongest { iterators, @@ -1007,14 +1007,16 @@ impl PyItertoolsZiplongest { if self.iterators.is_empty() { Err(new_stop_iteration(vm)) } else { - let mut next_obj: PyObjectRef; let mut result: Vec = Vec::new(); - let mut numactive = self.numactive.clone().into_inner(); + let mut numactive = self.numactive.get(); for idx in 0..self.iterators.len() { - next_obj = match call_next(vm, &self.iterators[idx]) { + let next_obj = match call_next(vm, &self.iterators[idx]) { Ok(obj) => obj, - Err(_) => { + Err(err) => { + if !objtype::isinstance(&err, &vm.ctx.exceptions.stop_iteration) { + return Err(err); + } numactive -= 1; if numactive == 0 { return Err(new_stop_iteration(vm));