From a797e4f7daf5fbcc9b12f64c298e9aa4df0f0acc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Rapha=C3=ABl=20Barrois?= Date: Fri, 28 May 2010 12:37:23 +0200 Subject: [PATCH] Fix problem with PlParallelIteratorUtils (Closes #1056) MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit Bug when a subiterator comes to its end. Signed-off-by: Raphaël Barrois --- classes/pliteratorutils.php | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/classes/pliteratorutils.php b/classes/pliteratorutils.php index a77244b..c9bf046 100644 --- a/classes/pliteratorutils.php +++ b/classes/pliteratorutils.php @@ -665,7 +665,8 @@ class PlParallelIterator implements PlIterator private $master_id; private $master; - private $stepped; + private $over = array(); + private $stepped = array(); private $current_elts = array(); private $callback_res = array(); @@ -689,6 +690,7 @@ class PlParallelIterator implements PlIterator foreach ($this->ids as $id) { $this->stepped[$id] = false; + $this->over[$id] = false; $this->current_elts[$id] = null; $this->callback_res[$id] = null; } @@ -700,12 +702,24 @@ class PlParallelIterator implements PlIterator return; } + // Don't do anything if the iterator is at its end + if ($this->over[$id]) { + $this->stepped[$id] = true; + return; + } + $it = $this->iterators[$id]; $nxt = $it->next(); + $this->stepped[$id] = true; + if ($nxt === null) { + $this->over[$id] = true; + $this->current_elts[$id] = null; + $this->callback_res[$id] = null; + return; + } $res = call_user_func($this->callbacks[$id], $nxt); $this->current_elts[$id] = $nxt; $this->callback_res[$id] = $res; - $this->stepped[$id] = true; } private function stepAll() @@ -718,7 +732,7 @@ class PlParallelIterator implements PlIterator public function next() { $this->stepAll(); - if ($this->current_elts[$this->master_id] == null) { + if ($this->current_elts[$this->master_id] === null) { return null; } -- 2.1.4