[svn:parrot] r48894 - in trunk: compilers/imcc include/parrot src

nwellnhof at svn.parrot.org nwellnhof at svn.parrot.org
Fri Sep 10 00:09:51 UTC 2010


Author: nwellnhof
Date: Fri Sep 10 00:09:51 2010
New Revision: 48894
URL: https://trac.parrot.org/parrot/changeset/48894

Log:
Use Hash instead of Hash PMC in PackFile_ConstTable

The Hash PMC might get collected and destroyed by GC.

Modified:
   trunk/compilers/imcc/pbc.c
   trunk/include/parrot/packfile.h
   trunk/src/packout.c

Modified: trunk/compilers/imcc/pbc.c
==============================================================================
--- trunk/compilers/imcc/pbc.c	Thu Sep  9 23:57:39 2010	(r48893)
+++ trunk/compilers/imcc/pbc.c	Fri Sep 10 00:09:51 2010	(r48894)
@@ -360,11 +360,11 @@
     }
     else {
         /* initialize rlookup cache */
-        interp->code->const_table->string_hash =
-            Parrot_pmc_new_init_int(interp, enum_class_Hash, enum_type_INTVAL);
-        ((Hash *)VTABLE_get_pointer(interp, interp->code->const_table->string_hash))->compare =
-            (hash_comp_fn)hash_compare_string_distinct_enc;
-
+        interp->code->const_table->string_hash = parrot_create_hash(interp,
+                enum_type_INTVAL,
+                Hash_key_type_STRING,
+                hash_compare_string_distinct_enc,
+                (hash_hash_key_fn)key_hash_STRING);
         interp->code->const_table->constants =
             mem_gc_allocate_n_zeroed_typed(interp, newcount, PackFile_Constant);
     }
@@ -1142,7 +1142,7 @@
         constant->type              = PFC_STRING;
         constant->u.string          = s;
 
-        VTABLE_set_integer_keyed_str(interp, table->string_hash, s, k);
+        parrot_hash_put(interp, table->string_hash, s, (void *)k);
 
         return k;
     }

Modified: trunk/include/parrot/packfile.h
==============================================================================
--- trunk/include/parrot/packfile.h	Thu Sep  9 23:57:39 2010	(r48893)
+++ trunk/include/parrot/packfile.h	Fri Sep 10 00:09:51 2010	(r48894)
@@ -263,7 +263,7 @@
     opcode_t                   const_count;
     PackFile_Constant         *constants;
     PackFile_ByteCode         *code;  /* where this segment belongs to */
-    PMC                       *string_hash; /* Hash for lookup strings and numbers */
+    Hash                      *string_hash; /* Hash for lookup strings and numbers */
 } PackFile_ConstTable;
 
 typedef struct PackFile_ByteCode_OpMappingEntry {

Modified: trunk/src/packout.c
==============================================================================
--- trunk/src/packout.c	Thu Sep  9 23:57:39 2010	(r48893)
+++ trunk/src/packout.c	Fri Sep 10 00:09:51 2010	(r48894)
@@ -273,9 +273,11 @@
     GETATTR_Key_str_key(interp, key, key_str);
     GETATTR_Key_num_key(interp, key, key_num);
 
-    if (type == PFC_STRING && !PMC_IS_NULL(ct->string_hash)) {
-        if (VTABLE_exists_keyed_str(interp, ct->string_hash, key_str)) {
-            i = VTABLE_get_integer_keyed_str(interp, ct->string_hash, key_str);
+    if (type == PFC_STRING && ct->string_hash) {
+        HashBucket *bucket = parrot_hash_get_bucket(interp, ct->string_hash,
+                key_str);
+        if (bucket) {
+            i = (int)bucket->value;
             if (i < ct->const_count) /* only consider constants that have already occured */
                 return i;
         }


More information about the parrot-commits mailing list