On Wed, 9 Jan 2002, Dan Sugalski wrote:
> At 06:39 PM 1/9/2002 +0000, Simon Glover wrote:
>
> > On Wed, 9 Jan 2002, Simon Glover wrote:
> >
> > > Two separate bugs:
> > >
> > > 1. The index checks should use && and not ||, or else they'll always be
> > > true.
> > >
> > > 2. The check in key_inc has an off-by-one error.
> > >
> > > Simon
> > >
> >
> > Better hold off on applying this patch; it makes test 5 in perlhash.t
> > fail (and yes, I know I should have checked this _before_ sending the
> > patch off).
>
> Will do.
>
OK, I think I've got it this time. The previous patch uncovered a bug in
perlhash.pmc; index is actually the offset of a particular key pair
within the perlhash structure, so we need to ensure that key->size is
bigger than index.
This also threw up a bug in the test: since the index is an offset,
assigning to index 1 will create a hash with a size of 2.
Patches below; and this time all tests pass!
Simon
--- perlhash.pmc.old Wed Jan 9 18:51:59 2002
+++ perlhash.pmc Wed Jan 9 18:52:03 2002
@@ -135,7 +135,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_int;
key_pair.cache.int_val = value;
--- pmc_perlhash.t.old Wed Jan 9 18:57:03 2002
+++ pmc_perlhash.t Wed Jan 9 18:57:10 2002
@@ -91,17 +91,17 @@
output_is(<<'CODE', <<OUTPUT, "size of the hash");
new P0, PerlHash
- set P0, 1, 1
+ set P0, 1, 0
set I0, P0
print I0
print "\n"
- set P0, 1, 2
+ set P0, 1, 1
set I0, P0
print I0
print "\n"
- set P0, 1, 1
+ set P0, 1, 0
set I0, P0
print I0
print "\n"