Index: DEPRECATED.pod =================================================================== --- DEPRECATED.pod (revision 37417) +++ DEPRECATED.pod (working copy) @@ -165,24 +165,8 @@ L -=item src/hash.c API cleanup [eligible in 1.1] - -After the 1.0 release, the following functions will return a Hash* instead of taking a Hash** as an argument: - -=over 4 - -=item * parrot_new_hash_x - -=item * parrot_new_cstring_hash - -=item * parrot_new_pointer_hash - =back -L - -=back - =head1 Compiler tools =over 4 Index: src/hash.c =================================================================== --- src/hash.c (revision 37416) +++ src/hash.c (working copy) @@ -37,19 +37,7 @@ /* 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, ARGIN(const char *a), @@ -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 +=item C Creates a new Parrot STRING hash in C. @@ -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 +=item C Creates a new C string hash in C. @@ -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 +=item C 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 +=item C -Creates and stores a new hash in C. +Create and return a new hash with void * keys and values. -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 is seen, it doesn't get properly marked -(only the C 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 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 - -Creates a new PMC hash. - -Like parrot_new_hash_x but w/o the described problems. The passed in -C 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 - -Creates a new hash with void * keys and values, storing it via the passed-in -Hash **. - -=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; } Index: src/string/api.c =================================================================== --- src/string/api.c (revision 37415) +++ src/string/api.c (working copy) @@ -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 */ Index: src/multidispatch.c =================================================================== --- src/multidispatch.c (revision 37415) +++ src/multidispatch.c (working copy) @@ -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; } Index: src/pmc/addrregistry.pmc =================================================================== --- src/pmc/addrregistry.pmc (revision 37415) +++ src/pmc/addrregistry.pmc (working copy) @@ -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() { Index: src/pmc/lexinfo.pmc =================================================================== --- src/pmc/lexinfo.pmc (revision 37415) +++ src/pmc/lexinfo.pmc (working copy) @@ -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); } Index: src/vtables.c =================================================================== --- src/vtables.c (revision 37415) +++ src/vtables.c (working copy) @@ -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); } Index: src/packfile.c =================================================================== --- src/packfile.c (revision 37415) +++ src/packfile.c (working copy) @@ -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 @@ -3079,8 +3078,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; Index: lib/Parrot/Pmc2c/PMCEmitter.pm =================================================================== --- lib/Parrot/Pmc2c/PMCEmitter.pm (revision 37415) +++ lib/Parrot/Pmc2c/PMCEmitter.pm (working copy) @@ -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 } Index: include/parrot/hash.h =================================================================== --- include/parrot/hash.h (revision 37415) +++ include/parrot/hash.h (working copy) @@ -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,30 +230,18 @@ __attribute__nonnull__(3) FUNC_MODIFIES(*hash); -void parrot_new_hash_x(PARROT_INTERP, - ARGOUT(Hash **hptr), +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(*hptr); + __attribute__nonnull__(4) + __attribute__nonnull__(5); -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)) - __attribute__nonnull__(1) - __attribute__nonnull__(2) - __attribute__nonnull__(5) - __attribute__nonnull__(6) - FUNC_MODIFIES(*container); - #define ASSERT_ARGS_parrot_dump_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \ PARROT_ASSERT_ARG(hash) #define ASSERT_ARGS_parrot_hash_clone __attribute__unused__ int _ASSERT_ARGS_CHECK = \ @@ -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,16 +305,10 @@ 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 = \ +#define ASSERT_ARGS_parrot_create_hash __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 = \ - 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. */ /* HEADERIZER END: src/hash.c */ Index: compilers/imcc/imclexer.c =================================================================== --- compilers/imcc/imclexer.c (revision 37415) +++ compilers/imcc/imclexer.c (working copy) @@ -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); }