From 376504e81ede2421eb7331546ff6f51ebe362ae2 Mon Sep 17 00:00:00 2001
From: Martin Nilsson <nilsson@fastmail.com>
Date: Thu, 10 Mar 2016 00:21:14 +0100
Subject: [PATCH] Fixed iterator _sizeof

---
 lib/modules/testsuite.in | 8 ++++++--
 src/iterators.cmod       | 9 ++++++---
 2 files changed, 12 insertions(+), 5 deletions(-)

diff --git a/lib/modules/testsuite.in b/lib/modules/testsuite.in
index ada820a4e2..a24b99be34 100644
--- a/lib/modules/testsuite.in
+++ b/lib/modules/testsuite.in
@@ -832,6 +832,8 @@ test_equal(Array.common_prefix(({ "labyrinth"/1, "diatom"/1 })), ({}))
 test_equal(Array.common_prefix(({ "abc"/1, "abc"/1, "abc"/1 })), "abc"/1)
 test_equal(Array.common_prefix(({})), ({}))
 
+test_eq( sizeof(Array.Iterator(({1,2,3,4}))), 4 )
+
 dnl - Colors
 
 define(test_rgb,[[
@@ -1167,7 +1169,8 @@ test_eq( Int.swap_long(array_sscanf("\1\2\3\4", "%4c")[0]),
 
 dnl - Mapping
 dnl Mapping.delete
-dnl Mapping.Iterator
+
+test_eq( sizeof(Mapping.Iterator(([1:2,3:4]))), 2 )
 
 test_do([[
   // Test for [bug 5085].
@@ -1178,7 +1181,8 @@ test_do([[
 ]])
 
 dnl - Multiset
-dnl Multiset.Iterator
+
+test_eq( sizeof(Multiset.Iterator((<1,2,3>))), 3 )
 
 dnl - Process
 test_equal([[Process.split_quoted_string("test ")]],[[({"test"})]])
diff --git a/src/iterators.cmod b/src/iterators.cmod
index d2e34ae9c0..89e94b1739 100644
--- a/src/iterators.cmod
+++ b/src/iterators.cmod
@@ -525,7 +525,8 @@ PIKECLASS array_iterator
     if (THIS->a) {
       push_int(THIS->a->size);
     }
-    push_undefined();
+    else
+      push_undefined();
   }
 
   PIKEFUN object `+(int steps)
@@ -659,7 +660,8 @@ PIKECLASS multiset_iterator
     if (THIS->l) {
       push_int(THIS->l->msd->size);
     }
-    push_undefined();
+    else
+      push_undefined();
   }
 
   static struct object *li_copy (struct multiset_iterator_struct *li)
@@ -874,7 +876,8 @@ PIKECLASS string_iterator
     if (THIS->s) {
       push_int(THIS->s->len);
     }
-    push_undefined();
+    else
+      push_undefined();
   }
 
   PIKEFUN object `+(int steps)
-- 
GitLab