Author: mdiep
Date: Thu Mar 22 08:10:31 2007
New Revision: 17691
Modified:
trunk/src/pmc/iterator.pmc
trunk/t/pmc/iterator.t
Log:
#41763: [PATCH]: fix "clone" method for iterators
Courtesy of Eric Hanchrow <[EMAIL PROTECTED]>.
Modified: trunk/src/pmc/iterator.pmc
==============================================================================
--- trunk/src/pmc/iterator.pmc (original)
+++ trunk/src/pmc/iterator.pmc Thu Mar 22 08:10:31 2007
@@ -89,14 +89,16 @@
=item C<PMC *clone()>
-Make a clone of the iterator that's reset to the beginning.
+Make a clone of the iterator.
=cut
*/
PMC* clone() {
- return pmc_new_init(INTERP, SELF->vtable->base_type,
PMC_pmc_val(SELF));
+ PMC * const key = PMC_struct_val(SELF);
+ PMC *res = pmc_new_init(INTERP, SELF->vtable->base_type,
PMC_pmc_val(SELF));
+ PMC_struct_val(res) = VTABLE_clone(interp, key);
}
/*
Modified: trunk/t/pmc/iterator.t
==============================================================================
--- trunk/t/pmc/iterator.t (original)
+++ trunk/t/pmc/iterator.t Thu Mar 22 08:10:31 2007
@@ -7,7 +7,7 @@
use lib qw( . lib ../lib ../../lib );
use Test::More;
-use Parrot::Test tests => 42;
+use Parrot::Test tests => 43;
=head1 NAME
@@ -1363,6 +1363,34 @@
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