Patrick R. Michaud wrote:
Fixing this shouldn't be all that difficult -- in particular,
I think that src/pmc/resizablepmcarray.pmc lines 205-206 should
be changed from
- if (key >= PMC_int_val(SELF))
- SELF.set_integer_native(key+1);
to something like
+ if (key >= PMC_int_val(SELF))
+ return PMCNULL;
I haven't tested this -- there may be other things that need
to change as well.
Hope this helps,
Pm
It turns out that no further changes were needed to implement this behavior.
The attached patch fixes this (and two incorrect ResizableBooleanArray tests).
With the patch applied, all tests in make test pass. If this is what we
want Parrot to do, I'll apply the patch and add tests to Resizable*Array to
make sure the behavior stays consistent.
Index: src/pmc/resizablepmcarray.pmc
===================================================================
--- src/pmc/resizablepmcarray.pmc (revision 30915)
+++ src/pmc/resizablepmcarray.pmc (working copy)
@@ -203,7 +203,7 @@
"ResizablePMCArray: index out of bounds!");
if (key >= PMC_int_val(SELF))
- SELF.set_integer_native(key+1);
+ return PMCNULL;
data = PMC_data_typed(SELF, PMC **);
Index: src/pmc/resizableintegerarray.pmc
===================================================================
--- src/pmc/resizableintegerarray.pmc (revision 30915)
+++ src/pmc/resizableintegerarray.pmc (working copy)
@@ -43,7 +43,7 @@
"ResizableIntegerArray: index out of bounds!");
if (key >= PMC_int_val(SELF))
- SELF.set_integer_native(key+1);
+ return 0;
data = (INTVAL *)PMC_data(SELF);
return data[key];
Index: src/pmc/resizablefloatarray.pmc
===================================================================
--- src/pmc/resizablefloatarray.pmc (revision 30915)
+++ src/pmc/resizablefloatarray.pmc (working copy)
@@ -43,7 +43,7 @@
"ResizableFloatArray: index out of bounds!");
if (key >= PMC_int_val(SELF))
- SELF.set_integer_native(key+1);
+ return 0.0;
data = (FLOATVAL *)PMC_data(SELF);
return data[key];
Index: src/pmc/resizablestringarray.pmc
===================================================================
--- src/pmc/resizablestringarray.pmc (revision 30915)
+++ src/pmc/resizablestringarray.pmc (working copy)
@@ -49,7 +49,7 @@
}
if (key >= PMC_int_val(SELF))
- SELF.set_integer_native(key+1);
+ return CONST_STRING(INTERP, "");
data = (STRING**)PMC_data(SELF);
Index: src/pmc/resizablebooleanarray.pmc
===================================================================
--- src/pmc/resizablebooleanarray.pmc (revision 30915)
+++ src/pmc/resizablebooleanarray.pmc (working copy)
@@ -69,7 +69,7 @@
offsetkey = key + PMC_int_val2(SELF);
if (offsetkey >= PMC_int_val(SELF))
- SELF.set_integer_native(key+1);
+ return 0;
return SUPER(offsetkey);
}
Index: t/pmc/resizablebooleanarray.t
===================================================================
--- t/pmc/resizablebooleanarray.t (revision 30915)
+++ t/pmc/resizablebooleanarray.t (working copy)
@@ -910,14 +910,16 @@
print "nok 4 "
ok_4:
- i = rba2[5000]
- if i == 1 goto ok_5
+ i = rba2[5000] #should be undefined, i.e. 0
+ if i == 0 goto ok_5
print "nok 5 "
ok_5:
- i = pop rba2
- if i == 1 goto ok_6
+ i = pop rba2 #same as previous
+ if i == 0 goto ok_6
print "nok 6 "
+ $S0 = rba2
+ say $S0
end
ok_6:
@@ -969,13 +971,13 @@
print "nok 4 "
ok_4:
- i = rba2[5000]
- if i == 1 goto ok_5
+ i = rba2[5000] #should be undefined, i.e. 0
+ if i == 0 goto ok_5
print "nok 5 "
ok_5:
- i = pop rba2
- if i == 1 goto ok_6
+ i = pop rba2 #same as previous
+ if i == 0 goto ok_6
print "nok 6 "
end