Here is one additional check...

-Jason (The other one)

On Mon, 2002-08-12 at 19:23, Jason Gloudon wrote:
> The last patch had an issue I didn't see on the test I was working against.
> mark_hash() assumes the buffer_pool is always initialized, but with the patch
> this is no longer the case.
> 
> -- 
> Jason
> ----
> 

> Index: parrot/hash.c
> ===================================================================
> RCS file: /cvs/public/parrot/hash.c,v
> retrieving revision 1.19
> diff -u -r1.19 hash.c
> --- parrot/hash.c     7 Aug 2002 20:27:53 -0000       1.19
> +++ parrot/hash.c     13 Aug 2002 00:20:39 -0000
> @@ -126,7 +126,9 @@
>      HashIndex i;
>  
>      buffer_lives((Buffer *)hash);
> -    buffer_lives(hash->bucket_pool);
> +    if(hash->bucket_pool){
> +        buffer_lives(hash->bucket_pool);
> +    }
>  
>      for (i = 0; i <= hash->max_chain; i++) {
>          HASHBUCKET *bucket = lookupBucket(hash, i);
> @@ -281,10 +283,12 @@
>      return NULL;
>  }
>  
> -HASH *
> -new_hash(Interp *interpreter)
> +void
> +new_hash(Interp *interpreter, HASH **hash_ptr)
>  {
>      HASH *hash = (HASH *)new_bufferlike_header(interpreter, sizeof(*hash));
> +    *hash_ptr = hash;
> +
>      /*      hash->buffer.flags |= BUFFER_report_FLAG; */
>  
>      /* We rely on the fact that expand_hash() will be called before
> @@ -295,11 +299,13 @@
>      hash->max_chain = (HashIndex) -1;
>  
>      hash->entries = 0;
> +
> +    /* Ensure mark_hash doesn't try to mark the buffer live */
> +    hash->bucket_pool = NULL;
>      hash->bucket_pool = new_buffer_header(interpreter);
>      /*      hash->bucket_pool->flags |= BUFFER_report_FLAG; */
>      hash->free_list = NULLBucketIndex;
>      expand_hash(interpreter, hash);
> -    return hash;
>  }
>  
>  /*=for api key hash_size
> @@ -412,9 +418,10 @@
>  
>  HASH *
>  hash_clone(struct Parrot_Interp * interp, HASH * hash) {
> -    HASH * ret = new_hash(interp);
> +    HASH *ret;
>      BucketIndex* table = (BucketIndex*) hash->buffer.bufstart;
>      BucketIndex i;
> +    new_hash(interp, &ret);
>      for (i = 0; i <= hash->max_chain; i++) {
>          HASHBUCKET * b = lookupBucket(hash, i);
>          while (b) {
> Index: parrot/classes/perlhash.pmc
> ===================================================================
> RCS file: /cvs/public/parrot/classes/perlhash.pmc,v
> retrieving revision 1.25
> diff -u -r1.25 perlhash.pmc
> --- parrot/classes/perlhash.pmc       12 Aug 2002 07:47:06 -0000      1.25
> +++ parrot/classes/perlhash.pmc       13 Aug 2002 00:20:40 -0000
> @@ -61,7 +61,7 @@
>              undef->flags |= PMC_constant_FLAG;
>          }
>          SELF->flags |= PMC_custom_mark_FLAG;
> -        SELF->data = new_hash(INTERP);
> +        new_hash(INTERP, (HASH **)&SELF->data);
>      }
>  
>      /* The end of used parameter is passed into the mark_used function of
> Index: parrot/include/parrot/hash.h
> ===================================================================
> RCS file: /cvs/public/parrot/include/parrot/hash.h,v
> retrieving revision 1.6
> diff -u -r1.6 hash.h
> --- parrot/include/parrot/hash.h      7 Aug 2002 19:02:06 -0000       1.6
> +++ parrot/include/parrot/hash.h      13 Aug 2002 00:20:40 -0000
> @@ -20,7 +20,7 @@
>  /* HASH is really a hashtable, but 'hash' is standard perl nomenclature. */
>  typedef struct _hash HASH;
>  
> -HASH *new_hash(Interp * interpreter);
> +void new_hash(Interp * interpreter, HASH **hash_ptr);
>  HASH *hash_clone(Interp * interpreter, HASH * hash);
>  INTVAL hash_size(Interp * interpreter, HASH *hash);
>  void hash_set_size(Interp * interpreter, HASH *hash, UINTVAL size);
> 
> 

Index: hash.c
===================================================================
RCS file: /cvs/public/parrot/hash.c,v
retrieving revision 1.19
diff -u -r1.19 hash.c
--- hash.c      7 Aug 2002 20:27:53 -0000       1.19
+++ hash.c      13 Aug 2002 01:59:57 -0000
@@ -126,8 +126,14 @@
     HashIndex i;
 
     buffer_lives((Buffer *)hash);
-    buffer_lives(hash->bucket_pool);
-
+    if(hash->bucket_pool){
+        buffer_lives(hash->bucket_pool);
+    }
+       
+    if (hash->buffer.bufstart == NULL) {
+        return end_of_used_list;
+    }
+    
     for (i = 0; i <= hash->max_chain; i++) {
         HASHBUCKET *bucket = lookupBucket(hash, i);
         while (bucket) {
@@ -281,10 +287,12 @@
     return NULL;
 }
 
-HASH *
-new_hash(Interp *interpreter)
+void
+new_hash(Interp *interpreter, HASH **hash_ptr)
 {
     HASH *hash = (HASH *)new_bufferlike_header(interpreter, sizeof(*hash));
+    *hash_ptr = hash;
+
     /*      hash->buffer.flags |= BUFFER_report_FLAG; */
 
     /* We rely on the fact that expand_hash() will be called before
@@ -295,11 +303,13 @@
     hash->max_chain = (HashIndex) -1;
 
     hash->entries = 0;
+
+    /* Ensure mark_hash doesn't try to mark the buffer live */
+    hash->bucket_pool = NULL;
     hash->bucket_pool = new_buffer_header(interpreter);
     /*      hash->bucket_pool->flags |= BUFFER_report_FLAG; */
     hash->free_list = NULLBucketIndex;
     expand_hash(interpreter, hash);
-    return hash;
 }
 
 /*=for api key hash_size
@@ -412,9 +422,10 @@
 
 HASH *
 hash_clone(struct Parrot_Interp * interp, HASH * hash) {
-    HASH * ret = new_hash(interp);
+    HASH *ret;
     BucketIndex* table = (BucketIndex*) hash->buffer.bufstart;
     BucketIndex i;
+    new_hash(interp, &ret);
     for (i = 0; i <= hash->max_chain; i++) {
         HASHBUCKET * b = lookupBucket(hash, i);
         while (b) {
Index: classes/perlhash.pmc
===================================================================
RCS file: /cvs/public/parrot/classes/perlhash.pmc,v
retrieving revision 1.25
diff -u -r1.25 perlhash.pmc
--- classes/perlhash.pmc        12 Aug 2002 07:47:06 -0000      1.25
+++ classes/perlhash.pmc        13 Aug 2002 01:59:57 -0000
@@ -61,7 +61,7 @@
             undef->flags |= PMC_constant_FLAG;
         }
         SELF->flags |= PMC_custom_mark_FLAG;
-        SELF->data = new_hash(INTERP);
+        new_hash(INTERP, (HASH **)&SELF->data);
     }
 
     /* The end of used parameter is passed into the mark_used function of

Reply via email to