[svn:parrot] r37543 - in trunk: compilers/imcc include/parrot lib/Parrot/Pmc2c src src/pmc src/string

cotto at svn.parrot.org cotto at svn.parrot.org
Wed Mar 18 06:28:29 UTC 2009


Author: cotto
Date: Wed Mar 18 06:28:27 2009
New Revision: 37543
URL: https://trac.parrot.org/parrot/changeset/37543

Log:
[hash] make various hash functions return Hash*, remove now-unused functions

Modified:
   trunk/compilers/imcc/imclexer.c
   trunk/include/parrot/hash.h
   trunk/lib/Parrot/Pmc2c/PMCEmitter.pm
   trunk/src/hash.c
   trunk/src/multidispatch.c
   trunk/src/packfile.c
   trunk/src/pmc/addrregistry.pmc
   trunk/src/pmc/lexinfo.pmc
   trunk/src/string/api.c
   trunk/src/vtables.c

Modified: trunk/compilers/imcc/imclexer.c
==============================================================================
--- trunk/compilers/imcc/imclexer.c	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/compilers/imcc/imclexer.c	Wed Mar 18 06:28:27 2009	(r37543)
@@ -5495,7 +5495,7 @@
         m = mem_allocate_zeroed_typed(macro_t);
 
         if (!IMCC_INFO(interp)->macros)
-            parrot_new_cstring_hash(interp, &IMCC_INFO(interp)->macros);
+            IMCC_INFO(interp)->macros = parrot_new_cstring_hash(interp);
         parrot_hash_put(interp, IMCC_INFO(interp)->macros,
             PARROT_const_cast(char *, name), m);
     }

Modified: trunk/include/parrot/hash.h
==============================================================================
--- trunk/include/parrot/hash.h	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/include/parrot/hash.h	Wed Mar 18 06:28:27 2009	(r37543)
@@ -180,16 +180,14 @@
         __attribute__nonnull__(2);
 
 PARROT_EXPORT
-void parrot_new_cstring_hash(PARROT_INTERP, ARGOUT(Hash **hptr))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        FUNC_MODIFIES(*hptr);
+PARROT_CANNOT_RETURN_NULL
+Hash* parrot_new_cstring_hash(PARROT_INTERP)
+        __attribute__nonnull__(1);
 
 PARROT_EXPORT
-void parrot_new_hash(PARROT_INTERP, ARGOUT(Hash **hptr))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        FUNC_MODIFIES(*hptr);
+PARROT_CANNOT_RETURN_NULL
+Hash* parrot_new_hash(PARROT_INTERP)
+        __attribute__nonnull__(1);
 
 PARROT_EXPORT
 PARROT_WARN_UNUSED_RESULT
@@ -204,10 +202,9 @@
         FUNC_MODIFIES(*container);
 
 PARROT_EXPORT
-void parrot_new_pointer_hash(PARROT_INTERP, ARGOUT(Hash **hptr))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        FUNC_MODIFIES(*hptr);
+PARROT_CANNOT_RETURN_NULL
+Hash * parrot_new_pointer_hash(PARROT_INTERP)
+        __attribute__nonnull__(1);
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
@@ -233,29 +230,17 @@
         __attribute__nonnull__(3)
         FUNC_MODIFIES(*hash);
 
-void parrot_new_hash_x(PARROT_INTERP,
-    ARGOUT(Hash **hptr),
-    PARROT_DATA_TYPE val_type,
-    Hash_key_type hkey_type,
-    NOTNULL(hash_comp_fn compare),
-    NOTNULL(hash_hash_key_fn keyhash))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        __attribute__nonnull__(5)
-        __attribute__nonnull__(6)
-        FUNC_MODIFIES(*hptr);
-
-void parrot_new_pmc_hash_x(PARROT_INTERP,
-    ARGMOD(PMC *container),
+PARROT_CANNOT_RETURN_NULL
+PARROT_WARN_UNUSED_RESULT
+PARROT_MALLOC
+Hash * parrot_create_hash(PARROT_INTERP,
     PARROT_DATA_TYPE val_type,
     Hash_key_type hkey_type,
-    NOTNULL(hash_comp_fn compare),
-    NOTNULL(hash_hash_key_fn keyhash))
+    ARGIN(hash_comp_fn compare),
+    ARGIN(hash_hash_key_fn keyhash))
         __attribute__nonnull__(1)
-        __attribute__nonnull__(2)
-        __attribute__nonnull__(5)
-        __attribute__nonnull__(6)
-        FUNC_MODIFIES(*container);
+        __attribute__nonnull__(4)
+        __attribute__nonnull__(5);
 
 #define ASSERT_ARGS_parrot_dump_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(hash)
@@ -300,19 +285,16 @@
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(hash)
 #define ASSERT_ARGS_parrot_new_cstring_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(hptr)
+       PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_parrot_new_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(hptr)
+       PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_Parrot_new_INTVAL_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_parrot_new_pmc_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(container)
 #define ASSERT_ARGS_parrot_new_pointer_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(hptr)
+       PARROT_ASSERT_ARG(interp)
 #define ASSERT_ARGS_int_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = 0
 #define ASSERT_ARGS_key_hash_int __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(value)
@@ -323,14 +305,8 @@
        PARROT_ASSERT_ARG(interp) \
     || PARROT_ASSERT_ARG(hash) \
     || PARROT_ASSERT_ARG(func)
-#define ASSERT_ARGS_parrot_new_hash_x __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(hptr) \
-    || PARROT_ASSERT_ARG(compare) \
-    || PARROT_ASSERT_ARG(keyhash)
-#define ASSERT_ARGS_parrot_new_pmc_hash_x __attribute__unused__ int _ASSERT_ARGS_CHECK = \
+#define ASSERT_ARGS_parrot_create_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(container) \
     || PARROT_ASSERT_ARG(compare) \
     || PARROT_ASSERT_ARG(keyhash)
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */

Modified: trunk/lib/Parrot/Pmc2c/PMCEmitter.pm
==============================================================================
--- trunk/lib/Parrot/Pmc2c/PMCEmitter.pm	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/lib/Parrot/Pmc2c/PMCEmitter.pm	Wed Mar 18 06:28:27 2009	(r37543)
@@ -563,7 +563,7 @@
             PObj_constant_FLAG|PObj_external_FLAG));
 
         /* set up isa hash */
-        parrot_new_hash(interp, &isa_hash);
+        isa_hash = parrot_new_hash(interp);
         vt_clone->isa_hash     = isa_hash;
 EOC
     }
@@ -573,7 +573,7 @@
         vt_clone->provides_str = CONST_STRING_GEN(interp, "$provides");
 
         /* set up isa hash */
-        parrot_new_hash(interp, &isa_hash);
+        isa_hash = parrot_new_hash(interp);
         vt_clone->isa_hash     = isa_hash;
 EOC
     }

Modified: trunk/src/hash.c
==============================================================================
--- trunk/src/hash.c	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/src/hash.c	Wed Mar 18 06:28:27 2009	(r37543)
@@ -37,18 +37,6 @@
 /* HEADERIZER BEGIN: static */
 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END.  Your changes will be lost. */
 
-PARROT_CANNOT_RETURN_NULL
-PARROT_WARN_UNUSED_RESULT
-PARROT_MALLOC
-static Hash * create_hash(PARROT_INTERP,
-    PARROT_DATA_TYPE val_type,
-    Hash_key_type hkey_type,
-    ARGIN(hash_comp_fn compare),
-    ARGIN(hash_hash_key_fn keyhash))
-        __attribute__nonnull__(1)
-        __attribute__nonnull__(4)
-        __attribute__nonnull__(5);
-
 PARROT_WARN_UNUSED_RESULT
 PARROT_PURE_FUNCTION
 static int cstring_compare(SHIM_INTERP,
@@ -126,10 +114,6 @@
         __attribute__nonnull__(1)
         __attribute__nonnull__(2);
 
-#define ASSERT_ARGS_create_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \
-       PARROT_ASSERT_ARG(interp) \
-    || PARROT_ASSERT_ARG(compare) \
-    || PARROT_ASSERT_ARG(keyhash)
 #define ASSERT_ARGS_cstring_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = \
        PARROT_ASSERT_ARG(a) \
     || PARROT_ASSERT_ARG(b)
@@ -824,7 +808,7 @@
 
 /*
 
-=item C<void parrot_new_hash>
+=item C<Hash* parrot_new_hash>
 
 Creates a new Parrot STRING hash in C<hptr>.
 
@@ -833,16 +817,16 @@
 */
 
 PARROT_EXPORT
-void
-parrot_new_hash(PARROT_INTERP, ARGOUT(Hash **hptr))
+PARROT_CANNOT_RETURN_NULL
+Hash*
+parrot_new_hash(PARROT_INTERP)
 {
     ASSERT_ARGS(parrot_new_hash)
-    parrot_new_hash_x(interp,
-            hptr,
+    return parrot_create_hash(interp,
             enum_type_PMC,
             Hash_key_type_STRING,
-            STRING_compare,     /* STRING compare */
-            (hash_hash_key_fn)key_hash_STRING);    /*        hash */
+            STRING_compare,
+            (hash_hash_key_fn)key_hash_STRING);
 }
 
 
@@ -861,18 +845,17 @@
 parrot_new_pmc_hash(PARROT_INTERP, ARGOUT(PMC *container))
 {
     ASSERT_ARGS(parrot_new_pmc_hash)
-    parrot_new_pmc_hash_x(interp,
-            container,
-            enum_type_PMC,
-            Hash_key_type_STRING,
-            STRING_compare,     /* STRING compare */
-            (hash_hash_key_fn)key_hash_STRING);    /*        hash */
+    Hash * const hash = parrot_create_hash(interp, enum_type_PMC,
+            Hash_key_type_STRING, STRING_compare,
+            (hash_hash_key_fn)key_hash_STRING);
+    PMC_struct_val(container) = hash;
+    hash->container           = container;
 }
 
 
 /*
 
-=item C<void parrot_new_cstring_hash>
+=item C<Hash* parrot_new_cstring_hash>
 
 Creates a new C string hash in C<hptr>.
 
@@ -881,22 +864,22 @@
 */
 
 PARROT_EXPORT
-void
-parrot_new_cstring_hash(PARROT_INTERP, ARGOUT(Hash **hptr))
+PARROT_CANNOT_RETURN_NULL
+Hash*
+parrot_new_cstring_hash(PARROT_INTERP)
 {
     ASSERT_ARGS(parrot_new_cstring_hash)
-    parrot_new_hash_x(interp,
-            hptr,
+    return parrot_create_hash(interp,
             enum_type_PMC,
             Hash_key_type_cstring,
-            (hash_comp_fn)cstring_compare,     /* cstring compare */
-            (hash_hash_key_fn)key_hash_cstring);    /*        hash */
+            (hash_comp_fn)cstring_compare,
+            (hash_hash_key_fn)key_hash_cstring);
 }
 
 
 /*
 
-=item C<static Hash * create_hash>
+=item C<Hash * parrot_create_hash>
 
 Creates and initializes a hash.  Function pointers determine its behaviors.
 The container passed in is the address of the hash PMC that is using it.  The
@@ -911,11 +894,11 @@
 PARROT_CANNOT_RETURN_NULL
 PARROT_WARN_UNUSED_RESULT
 PARROT_MALLOC
-static Hash *
-create_hash(PARROT_INTERP, PARROT_DATA_TYPE val_type, Hash_key_type hkey_type,
+Hash *
+parrot_create_hash(PARROT_INTERP, PARROT_DATA_TYPE val_type, Hash_key_type hkey_type,
         ARGIN(hash_comp_fn compare), ARGIN(hash_hash_key_fn keyhash))
 {
-    ASSERT_ARGS(create_hash)
+    ASSERT_ARGS(parrot_create_hash)
     HashBucket  *bp;
     Hash * const hash = mem_allocate_zeroed_typed(Hash);
     size_t       i;
@@ -1048,84 +1031,21 @@
 
 /*
 
-=item C<void parrot_new_hash_x>
-
-Creates and stores a new hash in C<hptr>.
-
-FIXME: This function can go back to just returning the hash struct
-pointer once Buffers can define their own custom mark routines.
-
-The problem is: During GC stack walking the item on the stack must be
-a PMC. When an auto C<Hash*> is seen, it doesn't get properly marked
-(only the C<Hash*> buffer is marked, not its contents). By passing the
-C<**hptr> up to the Hash's init function, the newly constructed PMC is
-on the stack I<including> this newly constructed Hash, so that it gets
-marked properly.
-
-=cut
-
-*/
-
-void
-parrot_new_hash_x(PARROT_INTERP,
-        ARGOUT(Hash **hptr),
-        PARROT_DATA_TYPE val_type,
-        Hash_key_type hkey_type,
-        NOTNULL(hash_comp_fn compare),
-        NOTNULL(hash_hash_key_fn keyhash))
-{
-    ASSERT_ARGS(parrot_new_hash_x)
-    *hptr = create_hash(interp, val_type, hkey_type, compare, keyhash);
-}
-
-
-/*
-
-=item C<void parrot_new_pmc_hash_x>
+=item C<Hash * parrot_new_pointer_hash>
 
-Creates a new PMC hash.
-
-Like parrot_new_hash_x but w/o the described problems.  The passed in
-C<container> PMC gets stored in the Hash and the newly created Hash is in
-PMC_struct_val(container).
-
-=cut
-
-*/
-
-void
-parrot_new_pmc_hash_x(PARROT_INTERP,
-        ARGMOD(PMC *container),
-        PARROT_DATA_TYPE val_type,
-        Hash_key_type hkey_type,
-        NOTNULL(hash_comp_fn compare),
-        NOTNULL(hash_hash_key_fn keyhash))
-{
-    ASSERT_ARGS(parrot_new_pmc_hash_x)
-    Hash * const hash         = create_hash(interp, val_type, hkey_type,
-                                            compare, keyhash);
-    PMC_struct_val(container) = hash;
-    hash->container           = container;
-}
-
-
-/*
-
-=item C<void parrot_new_pointer_hash>
-
-Creates a new hash with void * keys and values, storing it via the passed-in
-Hash **.
+Create and return a new hash with void * keys and values.
 
 =cut
 
 */
 
 PARROT_EXPORT
-void
-parrot_new_pointer_hash(PARROT_INTERP, ARGOUT(Hash **hptr))
+PARROT_CANNOT_RETURN_NULL
+Hash *
+parrot_new_pointer_hash(PARROT_INTERP)
 {
     ASSERT_ARGS(parrot_new_pointer_hash)
-    parrot_new_hash_x(interp, hptr, enum_type_ptr, Hash_key_type_ptr,
+    return parrot_create_hash(interp, enum_type_ptr, Hash_key_type_ptr,
             pointer_compare, key_hash_pointer);
 }
 
@@ -1148,12 +1068,15 @@
 Parrot_new_INTVAL_hash(PARROT_INTERP, UINTVAL flags)
 {
     ASSERT_ARGS(Parrot_new_INTVAL_hash)
+    Hash *hash;
     PMC * const h = (flags & PObj_constant_FLAG)
                   ? constant_pmc_new_noinit(interp, enum_class_Hash)
                   : pmc_new_noinit(interp, enum_class_Hash);
 
-    parrot_new_pmc_hash_x(interp, h, enum_type_INTVAL, Hash_key_type_int,
-            int_compare, key_hash_int);
+    hash = parrot_create_hash(interp, 
+            enum_type_INTVAL, Hash_key_type_int, int_compare, key_hash_int);
+    PMC_struct_val(h) = hash;
+    hash->container   = h;
     PObj_active_destroy_SET(h);
     return h;
 }

Modified: trunk/src/multidispatch.c
==============================================================================
--- trunk/src/multidispatch.c	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/src/multidispatch.c	Wed Mar 18 06:28:27 2009	(r37543)
@@ -1411,8 +1411,7 @@
 {
     ASSERT_ARGS(Parrot_mmd_cache_create)
     /* String hash. */
-    Hash *cache;
-    parrot_new_hash(interp, &cache);
+    Hash *cache = parrot_new_hash(interp);
     return cache;
 }
 

Modified: trunk/src/packfile.c
==============================================================================
--- trunk/src/packfile.c	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/src/packfile.c	Wed Mar 18 06:28:27 2009	(r37543)
@@ -152,8 +152,7 @@
         __attribute__nonnull__(1)
         __attribute__nonnull__(2)
         __attribute__nonnull__(3)
-        FUNC_MODIFIES(*segp)
-        FUNC_MODIFIES(*cursor);
+        FUNC_MODIFIES(*segp);
 
 PARROT_WARN_UNUSED_RESULT
 PARROT_CAN_RETURN_NULL
@@ -3078,8 +3077,7 @@
         PARROT_ASSERT(interp->thread_data);
 
         if (!interp->thread_data->const_tables) {
-            interp->thread_data->const_tables = mem_allocate_typed(Hash);
-            parrot_new_pointer_hash(interp, &interp->thread_data->const_tables);
+            interp->thread_data->const_tables = parrot_new_pointer_hash(interp);
         }
 
         tables     = interp->thread_data->const_tables;

Modified: trunk/src/pmc/addrregistry.pmc
==============================================================================
--- trunk/src/pmc/addrregistry.pmc	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/src/pmc/addrregistry.pmc	Wed Mar 18 06:28:27 2009	(r37543)
@@ -55,14 +55,13 @@
         PMC_data(SELF)      = addr_registry;
         PObj_custom_mark_destroy_SETALL(SELF);
 
-        parrot_new_pmc_hash_x(INTERP, SELF, enum_type_int, Hash_key_type_PMC,
+        registry = parrot_create_hash(INTERP, enum_type_int, Hash_key_type_PMC,
                               int_compare, key_hash_int);
 
-        registry            = (Hash *)PMC_struct_val(SELF);
+        PMC_struct_val(SELF) = registry;
+        addr_registry->hash  = registry;
+        registry->container  = SELF;
 
-        /* this hack can go away when parrot_new_pmc_hash_x behaves */
-        addr_registry->hash = registry;
-        registry->container = SELF;
     }
 
     VTABLE void destroy() {

Modified: trunk/src/pmc/lexinfo.pmc
==============================================================================
--- trunk/src/pmc/lexinfo.pmc	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/src/pmc/lexinfo.pmc	Wed Mar 18 06:28:27 2009	(r37543)
@@ -62,15 +62,18 @@
     }
 
     VTABLE void init_pmc(PMC *sub) {
+        Hash *hash;
         PARROT_ASSERT(PObj_constant_TEST(SELF));
         PMC_pmc_val(SELF) = sub;
 
-        parrot_new_pmc_hash_x(INTERP, SELF,
+        hash = parrot_create_hash(INTERP,
             (PARROT_DATA_TYPE)enum_hash_int,
             Hash_key_type_STRING,
             (hash_comp_fn)Parrot_str_not_equal,     /* STRING compare */
             (hash_hash_key_fn)Parrot_str_to_hashval); /*        hash    */
 
+        PMC_struct_val(SELF) = hash;
+        hash->container      = SELF;
         PObj_active_destroy_SET(SELF);
     }
 

Modified: trunk/src/string/api.c
==============================================================================
--- trunk/src/string/api.c	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/src/string/api.c	Wed Mar 18 06:28:27 2009	(r37543)
@@ -299,8 +299,8 @@
 
     /* Set up the cstring cache, then load the basic encodings and charsets */
     if (!interp->parent_interpreter) {
-        parrot_new_cstring_hash(interp, &const_cstring_hash);
-        interp->const_cstring_hash  = (Hash *)const_cstring_hash;
+        const_cstring_hash = parrot_new_cstring_hash(interp);
+        interp->const_cstring_hash  = const_cstring_hash;
         Parrot_charsets_encodings_init(interp);
     }
     /* initialize the constant string table */

Modified: trunk/src/vtables.c
==============================================================================
--- trunk/src/vtables.c	Wed Mar 18 06:00:39 2009	(r37542)
+++ trunk/src/vtables.c	Wed Mar 18 06:28:27 2009	(r37543)
@@ -65,7 +65,7 @@
     /* when called from global PMC initialization, not all vtables have isa_hash
      * when called at runtime, they do */
     if (base_vtable->isa_hash) {
-        parrot_new_hash(interp, &new_vtable->isa_hash);
+        new_vtable->isa_hash = parrot_new_hash(interp);
         parrot_hash_clone(interp, base_vtable->isa_hash, new_vtable->isa_hash);
     }
 


More information about the parrot-commits mailing list