# New Ticket Created by  Eric Hanchrow 
# Please include the string:  [perl #41763]
# in the subject line of all future correspondence about this issue. 
# <URL: http://rt.perl.org/rt3/Ticket/Display.html?id=41763 >


I noticed that if you cloned an iterator that you had already
"shifted", the clone started at the beginning, rather than at the
original's current location.
commit 78d423162c66aa2f506fd6a785cbe7bd6b80088c
Author: Eric Hanchrow <[EMAIL PROTECTED]>
Date:   Thu Mar 8 17:04:32 2007 -0800

    clone the iterator key.

diff --git a/src/pmc/iterator.pmc b/src/pmc/iterator.pmc
index 0ff62fa..fa8da16 100644
--- a/src/pmc/iterator.pmc
+++ b/src/pmc/iterator.pmc
@@ -87,8 +87,9 @@ Marks the current idx/key and the aggregate as live.
 
     PMC* clone() {
         PMC *res;
-        /* TODO -- find the proper macro that expands to this stuff */
         res = pmc_new_init(INTERP, SELF->vtable->base_type, PMC_pmc_val(SELF));
+        PMC * const key = PMC_struct_val(SELF);
+        PMC_struct_val (res) = VTABLE_clone(interp, key);
         return res;
     }
 
diff --git a/t/pmc/iterator.t b/t/pmc/iterator.t
index f365d7d..1a5f943 100644
--- a/t/pmc/iterator.t
+++ b/t/pmc/iterator.t
@@ -7,7 +7,7 @@ use warnings;
 use lib qw( . lib ../lib ../../lib );
 
 use Test::More;
-use Parrot::Test tests => 42;
+use Parrot::Test tests => 43;
 
 =head1 NAME
 
@@ -1364,6 +1364,34 @@ CODE
 ok
 OUTPUT
 
+pir_output_is (<< 'CODE', << 'OUTPUT', "clone of partly-advanced iterator");
+.sub main :main
+    .local pmc ar, i1, i2
+    .local Integer temp
+    ar = new ResizableIntegerArray
+    push ar, 1
+    push ar, 2
+    new i1, .Iterator, ar
+
+    shift temp, i1
+    unless temp == 1 goto fail
+
+    clone i2, i1
+    shift temp, i1
+    unless temp == 2 goto fail
+
+    shift temp, i2
+    unless temp == 2 goto fail
+
+    say "ok"
+    end
+fail:
+    say "not ok"
+.end
+CODE
+ok
+OUTPUT
+
 # Local Variables:
 #   mode: cperl
 #   cperl-indent-level: 4
 src/pmc/iterator.pmc |    3 ++-
 t/pmc/iterator.t     |   30 +++++++++++++++++++++++++++++-
 2 files changed, 31 insertions(+), 2 deletions(-)
-- 
"I said, `Shut up!' " Ms. Glass recalled ... " `You do not!
Oh my God! Oh my God! Oh my God!' So I went to Nina, my boss, and
said, `Oh my God! Oh my God! Oh my God!' "

        --- Julie Salamon, in the New York Times

Reply via email to