Here is another way of resolving this, as I mentioned in the last message.
Having new_hash() initialize the PMC's data pointer so that the hash is
immediately visible to the collector.

-- 
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       12 Aug 2002 23:10:04 -0000
@@ -281,10 +281,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
@@ -299,7 +301,6 @@
     /*      hash->bucket_pool->flags |= BUFFER_report_FLAG; */
     hash->free_list = NULLBucketIndex;
     expand_hash(interpreter, hash);
-    return hash;
 }
 
 /*=for api key hash_size
@@ -412,9 +413,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 12 Aug 2002 23:10:04 -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        12 Aug 2002 23:10:05 -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);


Reply via email to