This time in perlarray.pmc; they're both simple off-by-one errors.
Patch below fixes.
I've also added a regression test to guard against the reoccurence of
the bug. I've put this, plus the existing PerlArray tests, in a separate
file, pmc_perlarray.t, in line with what we've done for hashes and
strings.
Simon
--- perlarray.pmc.old Wed Jan 9 20:00:42 2002
+++ perlarray.pmc Wed Jan 9 20:01:01 2002
@@ -156,7 +156,7 @@
KEY* key = SELF->cache.struct_val;
KEY_PAIR key_pair;
if(index >= key_size(INTERP,key)) {
- key_set_size(INTERP,key,index);
+ key_set_size(INTERP,key,index+1);
}
key_pair.type = enum_key_num;
key_pair.cache.num_val = value;
@@ -182,7 +182,7 @@
KEY* key = SELF->cache.struct_val;
KEY_PAIR key_pair;
if(index >= key_size(INTERP,key)) {
- key_set_size(INTERP,key,index);
+ key_set_size(INTERP,key,index+1);
}
key_pair.type = enum_key_string;
key_pair.cache.struct_val = value;
--- pmc.t.old Wed Jan 9 19:30:32 2002
+++ pmc.t Wed Jan 9 19:31:34 2002
@@ -1,6 +1,6 @@
#! perl -w
-use Parrot::Test tests => 58;
+use Parrot::Test tests => 57;
my $fp_equality_macro = <<'ENDOFMACRO';
fp_eq macro J,K,L
@@ -814,36 +814,7 @@
foo
OUTPUT
-output_is(<<'CODE', <<'OUTPUT', "array test");
- new P0,PerlArray
- set P0,1
- set I0,P0
- print I0
- print "\n"
-
- set P0,3,0
- set I1,P0,0
- print I1
- print "\n"
-
- set P0,2
- set P0,3.7,1
- set N1,P0,1
- print N1
- print "\n"
- set P0,3
- set P0,"hey",2
- set S1,P0,2
- print S1
- print "\n"
-end
-CODE
-1
-3
-3.700000
-hey
-OUTPUT
output_is(<<CODE, <<OUTPUT, "if (P) - Int");
new P0, PerlInt
--- /dev/null Sat Mar 24 04:37:44 2001
+++ pmc_perlarray.t Wed Jan 9 19:54:39 2002
@@ -0,0 +1,80 @@
+#! perl -w
+
+use Parrot::Test tests => 3;
+
+output_is(<<'CODE', <<'OUTPUT', "size of the array");
+ new P0,PerlArray
+ set P0,0
+ set I0,P0
+ print I0
+ print "\n"
+
+ set P0,1
+ set I0,P0
+ print I0
+ print "\n"
+
+ set P0,5
+ set I0,P0
+ print I0
+ print "\n"
+
+ end
+CODE
+0
+1
+5
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "set/get by index");
+ new P0,PerlArray
+ set P0,3,0
+ set I1,P0,0
+ print I1
+ print "\n"
+
+ set P0,2
+ set P0,3.7,1
+ set N1,P0,1
+ print N1
+ print "\n"
+
+ set P0,3
+ set P0,"hey",2
+ set S1,P0,2
+ print S1
+ print "\n"
+
+ end
+CODE
+3
+3.700000
+hey
+OUTPUT
+
+output_is(<<'CODE', <<'OUTPUT', "same, but with implicit resizing");
+ new P0,PerlArray
+ set P0,3,0
+ set I1,P0,0
+ print I1
+ print "\n"
+
+ set P0,3.7,1
+ set N1,P0,1
+ print N1
+ print "\n"
+
+ set P0,"hey",2
+ set S1,P0,2
+ print S1
+ print "\n"
+
+ end
+CODE
+3
+3.700000
+hey
+OUTPUT
+
+
+1;
--- MANIFEST.old Wed Jan 9 20:12:04 2002
+++ MANIFEST Wed Jan 9 19:41:14 2002
@@ -199,6 +199,7 @@
t/op/macro.t
t/op/number.t
t/op/pmc.t
+t/op/pmc_perlarray.t
t/op/pmc_perlhash.t
t/op/pmc_perlstring.t
t/op/stacks.t