Ticket #447: hash_cleanup.patch
| File hash_cleanup.patch, 17.3 KB (added by cotto, 4 years ago) |
|---|
-
DEPRECATED.pod
165 165 166 166 L<https://trac.parrot.org/parrot/ticket/443> 167 167 168 =item src/hash.c API cleanup [eligible in 1.1]169 170 After the 1.0 release, the following functions will return a Hash* instead of taking a Hash** as an argument:171 172 =over 4173 174 =item * parrot_new_hash_x175 176 =item * parrot_new_cstring_hash177 178 =item * parrot_new_pointer_hash179 180 168 =back 181 169 182 L<https://trac.parrot.org/parrot/ticket/447>183 184 =back185 186 170 =head1 Compiler tools 187 171 188 172 =over 4 -
src/hash.c
37 37 /* HEADERIZER BEGIN: static */ 38 38 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ 39 39 40 PARROT_CANNOT_RETURN_NULL41 40 PARROT_WARN_UNUSED_RESULT 42 PARROT_MALLOC43 static Hash * create_hash(PARROT_INTERP,44 PARROT_DATA_TYPE val_type,45 Hash_key_type hkey_type,46 ARGIN(hash_comp_fn compare),47 ARGIN(hash_hash_key_fn keyhash))48 __attribute__nonnull__(1)49 __attribute__nonnull__(4)50 __attribute__nonnull__(5);51 52 PARROT_WARN_UNUSED_RESULT53 41 PARROT_PURE_FUNCTION 54 42 static int cstring_compare(SHIM_INTERP, 55 43 ARGIN(const char *a), … … 126 114 __attribute__nonnull__(1) 127 115 __attribute__nonnull__(2); 128 116 129 #define ASSERT_ARGS_create_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \130 PARROT_ASSERT_ARG(interp) \131 || PARROT_ASSERT_ARG(compare) \132 || PARROT_ASSERT_ARG(keyhash)133 117 #define ASSERT_ARGS_cstring_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 134 118 PARROT_ASSERT_ARG(a) \ 135 119 || PARROT_ASSERT_ARG(b) … … 824 808 825 809 /* 826 810 827 =item C< voidparrot_new_hash>811 =item C<Hash* parrot_new_hash> 828 812 829 813 Creates a new Parrot STRING hash in C<hptr>. 830 814 … … 833 817 */ 834 818 835 819 PARROT_EXPORT 836 void 837 parrot_new_hash(PARROT_INTERP, ARGOUT(Hash **hptr)) 820 PARROT_CANNOT_RETURN_NULL 821 Hash* 822 parrot_new_hash(PARROT_INTERP) 838 823 { 839 824 ASSERT_ARGS(parrot_new_hash) 840 parrot_new_hash_x(interp, 841 hptr, 825 return parrot_create_hash(interp, 842 826 enum_type_PMC, 843 827 Hash_key_type_STRING, 844 STRING_compare, /* STRING compare */845 (hash_hash_key_fn)key_hash_STRING); /* hash */828 STRING_compare, 829 (hash_hash_key_fn)key_hash_STRING); 846 830 } 847 831 848 832 … … 861 845 parrot_new_pmc_hash(PARROT_INTERP, ARGOUT(PMC *container)) 862 846 { 863 847 ASSERT_ARGS(parrot_new_pmc_hash) 864 parrot_new_pmc_hash_x(interp, 865 container, 866 enum_type_PMC, 867 Hash_key_type_STRING, 868 STRING_compare, /* STRING compare */ 869 (hash_hash_key_fn)key_hash_STRING); /* hash */ 848 Hash * const hash = parrot_create_hash(interp, enum_type_PMC, 849 Hash_key_type_STRING, STRING_compare, 850 (hash_hash_key_fn)key_hash_STRING); 851 PMC_struct_val(container) = hash; 852 hash->container = container; 870 853 } 871 854 872 855 873 856 /* 874 857 875 =item C< voidparrot_new_cstring_hash>858 =item C<Hash* parrot_new_cstring_hash> 876 859 877 860 Creates a new C string hash in C<hptr>. 878 861 … … 881 864 */ 882 865 883 866 PARROT_EXPORT 884 void 885 parrot_new_cstring_hash(PARROT_INTERP, ARGOUT(Hash **hptr)) 867 PARROT_CANNOT_RETURN_NULL 868 Hash* 869 parrot_new_cstring_hash(PARROT_INTERP) 886 870 { 887 871 ASSERT_ARGS(parrot_new_cstring_hash) 888 parrot_new_hash_x(interp, 889 hptr, 872 return parrot_create_hash(interp, 890 873 enum_type_PMC, 891 874 Hash_key_type_cstring, 892 (hash_comp_fn)cstring_compare, /* cstring compare */893 (hash_hash_key_fn)key_hash_cstring); /* hash */875 (hash_comp_fn)cstring_compare, 876 (hash_hash_key_fn)key_hash_cstring); 894 877 } 895 878 896 879 897 880 /* 898 881 899 =item C< static Hash *create_hash>882 =item C<Hash * parrot_create_hash> 900 883 901 884 Creates and initializes a hash. Function pointers determine its behaviors. 902 885 The container passed in is the address of the hash PMC that is using it. The … … 911 894 PARROT_CANNOT_RETURN_NULL 912 895 PARROT_WARN_UNUSED_RESULT 913 896 PARROT_MALLOC 914 staticHash *915 create_hash(PARROT_INTERP, PARROT_DATA_TYPE val_type, Hash_key_type hkey_type,897 Hash * 898 parrot_create_hash(PARROT_INTERP, PARROT_DATA_TYPE val_type, Hash_key_type hkey_type, 916 899 ARGIN(hash_comp_fn compare), ARGIN(hash_hash_key_fn keyhash)) 917 900 { 918 ASSERT_ARGS( create_hash)901 ASSERT_ARGS(parrot_create_hash) 919 902 HashBucket *bp; 920 903 Hash * const hash = mem_allocate_zeroed_typed(Hash); 921 904 size_t i; … … 1048 1031 1049 1032 /* 1050 1033 1051 =item C< void parrot_new_hash_x>1034 =item C<Hash * parrot_new_pointer_hash> 1052 1035 1053 Create s and stores a new hash in C<hptr>.1036 Create and return a new hash with void * keys and values. 1054 1037 1055 FIXME: This function can go back to just returning the hash struct1056 pointer once Buffers can define their own custom mark routines.1057 1058 The problem is: During GC stack walking the item on the stack must be1059 a PMC. When an auto C<Hash*> is seen, it doesn't get properly marked1060 (only the C<Hash*> buffer is marked, not its contents). By passing the1061 C<**hptr> up to the Hash's init function, the newly constructed PMC is1062 on the stack I<including> this newly constructed Hash, so that it gets1063 marked properly.1064 1065 1038 =cut 1066 1039 1067 1040 */ 1068 1041 1069 void1070 parrot_new_hash_x(PARROT_INTERP,1071 ARGOUT(Hash **hptr),1072 PARROT_DATA_TYPE val_type,1073 Hash_key_type hkey_type,1074 NOTNULL(hash_comp_fn compare),1075 NOTNULL(hash_hash_key_fn keyhash))1076 {1077 ASSERT_ARGS(parrot_new_hash_x)1078 *hptr = create_hash(interp, val_type, hkey_type, compare, keyhash);1079 }1080 1081 1082 /*1083 1084 =item C<void parrot_new_pmc_hash_x>1085 1086 Creates a new PMC hash.1087 1088 Like parrot_new_hash_x but w/o the described problems. The passed in1089 C<container> PMC gets stored in the Hash and the newly created Hash is in1090 PMC_struct_val(container).1091 1092 =cut1093 1094 */1095 1096 void1097 parrot_new_pmc_hash_x(PARROT_INTERP,1098 ARGMOD(PMC *container),1099 PARROT_DATA_TYPE val_type,1100 Hash_key_type hkey_type,1101 NOTNULL(hash_comp_fn compare),1102 NOTNULL(hash_hash_key_fn keyhash))1103 {1104 ASSERT_ARGS(parrot_new_pmc_hash_x)1105 Hash * const hash = create_hash(interp, val_type, hkey_type,1106 compare, keyhash);1107 PMC_struct_val(container) = hash;1108 hash->container = container;1109 }1110 1111 1112 /*1113 1114 =item C<void parrot_new_pointer_hash>1115 1116 Creates a new hash with void * keys and values, storing it via the passed-in1117 Hash **.1118 1119 =cut1120 1121 */1122 1123 1042 PARROT_EXPORT 1124 void 1125 parrot_new_pointer_hash(PARROT_INTERP, ARGOUT(Hash **hptr)) 1043 PARROT_CANNOT_RETURN_NULL 1044 Hash * 1045 parrot_new_pointer_hash(PARROT_INTERP) 1126 1046 { 1127 1047 ASSERT_ARGS(parrot_new_pointer_hash) 1128 parrot_new_hash_x(interp, hptr, enum_type_ptr, Hash_key_type_ptr,1048 return parrot_create_hash(interp, enum_type_ptr, Hash_key_type_ptr, 1129 1049 pointer_compare, key_hash_pointer); 1130 1050 } 1131 1051 … … 1148 1068 Parrot_new_INTVAL_hash(PARROT_INTERP, UINTVAL flags) 1149 1069 { 1150 1070 ASSERT_ARGS(Parrot_new_INTVAL_hash) 1071 Hash *hash; 1151 1072 PMC * const h = (flags & PObj_constant_FLAG) 1152 1073 ? constant_pmc_new_noinit(interp, enum_class_Hash) 1153 1074 : pmc_new_noinit(interp, enum_class_Hash); 1154 1075 1155 parrot_new_pmc_hash_x(interp, h, enum_type_INTVAL, Hash_key_type_int, 1156 int_compare, key_hash_int); 1076 hash = parrot_create_hash(interp, 1077 enum_type_INTVAL, Hash_key_type_int, int_compare, key_hash_int); 1078 PMC_struct_val(h) = hash; 1079 hash->container = h; 1157 1080 PObj_active_destroy_SET(h); 1158 1081 return h; 1159 1082 } -
src/string/api.c
299 299 300 300 /* Set up the cstring cache, then load the basic encodings and charsets */ 301 301 if (!interp->parent_interpreter) { 302 parrot_new_cstring_hash(interp, &const_cstring_hash);303 interp->const_cstring_hash = (Hash *)const_cstring_hash;302 const_cstring_hash = parrot_new_cstring_hash(interp); 303 interp->const_cstring_hash = const_cstring_hash; 304 304 Parrot_charsets_encodings_init(interp); 305 305 } 306 306 /* initialize the constant string table */ -
src/multidispatch.c
1411 1411 { 1412 1412 ASSERT_ARGS(Parrot_mmd_cache_create) 1413 1413 /* String hash. */ 1414 Hash *cache; 1415 parrot_new_hash(interp, &cache); 1414 Hash *cache = parrot_new_hash(interp); 1416 1415 return cache; 1417 1416 } 1418 1417 -
src/pmc/addrregistry.pmc
55 55 PMC_data(SELF) = addr_registry; 56 56 PObj_custom_mark_destroy_SETALL(SELF); 57 57 58 parrot_new_pmc_hash_x(INTERP, SELF, enum_type_int, Hash_key_type_PMC,58 registry = parrot_create_hash(INTERP, enum_type_int, Hash_key_type_PMC, 59 59 int_compare, key_hash_int); 60 60 61 registry = (Hash *)PMC_struct_val(SELF); 61 PMC_struct_val(SELF) = registry; 62 addr_registry->hash = registry; 63 registry->container = SELF; 62 64 63 /* this hack can go away when parrot_new_pmc_hash_x behaves */64 addr_registry->hash = registry;65 registry->container = SELF;66 65 } 67 66 68 67 VTABLE void destroy() { -
src/pmc/lexinfo.pmc
62 62 } 63 63 64 64 VTABLE void init_pmc(PMC *sub) { 65 Hash *hash; 65 66 PARROT_ASSERT(PObj_constant_TEST(SELF)); 66 67 PMC_pmc_val(SELF) = sub; 67 68 68 parrot_new_pmc_hash_x(INTERP, SELF,69 hash = parrot_create_hash(INTERP, 69 70 (PARROT_DATA_TYPE)enum_hash_int, 70 71 Hash_key_type_STRING, 71 72 (hash_comp_fn)Parrot_str_not_equal, /* STRING compare */ 72 73 (hash_hash_key_fn)Parrot_str_to_hashval); /* hash */ 73 74 75 PMC_struct_val(SELF) = hash; 76 hash->container = SELF; 74 77 PObj_active_destroy_SET(SELF); 75 78 } 76 79 -
src/vtables.c
65 65 /* when called from global PMC initialization, not all vtables have isa_hash 66 66 * when called at runtime, they do */ 67 67 if (base_vtable->isa_hash) { 68 parrot_new_hash(interp, &new_vtable->isa_hash);68 new_vtable->isa_hash = parrot_new_hash(interp); 69 69 parrot_hash_clone(interp, base_vtable->isa_hash, new_vtable->isa_hash); 70 70 } 71 71 -
src/packfile.c
152 152 __attribute__nonnull__(1) 153 153 __attribute__nonnull__(2) 154 154 __attribute__nonnull__(3) 155 FUNC_MODIFIES(*segp) 156 FUNC_MODIFIES(*cursor); 155 FUNC_MODIFIES(*segp); 157 156 158 157 PARROT_WARN_UNUSED_RESULT 159 158 PARROT_CAN_RETURN_NULL … … 3079 3078 PARROT_ASSERT(interp->thread_data); 3080 3079 3081 3080 if (!interp->thread_data->const_tables) { 3082 interp->thread_data->const_tables = mem_allocate_typed(Hash); 3083 parrot_new_pointer_hash(interp, &interp->thread_data->const_tables); 3081 interp->thread_data->const_tables = parrot_new_pointer_hash(interp); 3084 3082 } 3085 3083 3086 3084 tables = interp->thread_data->const_tables; -
lib/Parrot/Pmc2c/PMCEmitter.pm
563 563 PObj_constant_FLAG|PObj_external_FLAG)); 564 564 565 565 /* set up isa hash */ 566 parrot_new_hash(interp, &isa_hash);566 isa_hash = parrot_new_hash(interp); 567 567 vt_clone->isa_hash = isa_hash; 568 568 EOC 569 569 } … … 573 573 vt_clone->provides_str = CONST_STRING_GEN(interp, "$provides"); 574 574 575 575 /* set up isa hash */ 576 parrot_new_hash(interp, &isa_hash);576 isa_hash = parrot_new_hash(interp); 577 577 vt_clone->isa_hash = isa_hash; 578 578 EOC 579 579 } -
include/parrot/hash.h
180 180 __attribute__nonnull__(2); 181 181 182 182 PARROT_EXPORT 183 void parrot_new_cstring_hash(PARROT_INTERP, ARGOUT(Hash **hptr)) 184 __attribute__nonnull__(1) 185 __attribute__nonnull__(2) 186 FUNC_MODIFIES(*hptr); 183 PARROT_CANNOT_RETURN_NULL 184 Hash* parrot_new_cstring_hash(PARROT_INTERP) 185 __attribute__nonnull__(1); 187 186 188 187 PARROT_EXPORT 189 void parrot_new_hash(PARROT_INTERP, ARGOUT(Hash **hptr)) 190 __attribute__nonnull__(1) 191 __attribute__nonnull__(2) 192 FUNC_MODIFIES(*hptr); 188 PARROT_CANNOT_RETURN_NULL 189 Hash* parrot_new_hash(PARROT_INTERP) 190 __attribute__nonnull__(1); 193 191 194 192 PARROT_EXPORT 195 193 PARROT_WARN_UNUSED_RESULT … … 204 202 FUNC_MODIFIES(*container); 205 203 206 204 PARROT_EXPORT 207 void parrot_new_pointer_hash(PARROT_INTERP, ARGOUT(Hash **hptr)) 208 __attribute__nonnull__(1) 209 __attribute__nonnull__(2) 210 FUNC_MODIFIES(*hptr); 205 PARROT_CANNOT_RETURN_NULL 206 Hash * parrot_new_pointer_hash(PARROT_INTERP) 207 __attribute__nonnull__(1); 211 208 212 209 PARROT_WARN_UNUSED_RESULT 213 210 PARROT_PURE_FUNCTION … … 233 230 __attribute__nonnull__(3) 234 231 FUNC_MODIFIES(*hash); 235 232 236 void parrot_new_hash_x(PARROT_INTERP, 237 ARGOUT(Hash **hptr), 233 PARROT_CANNOT_RETURN_NULL 234 PARROT_WARN_UNUSED_RESULT 235 PARROT_MALLOC 236 Hash * parrot_create_hash(PARROT_INTERP, 238 237 PARROT_DATA_TYPE val_type, 239 238 Hash_key_type hkey_type, 240 NOTNULL(hash_comp_fn compare),241 NOTNULL(hash_hash_key_fn keyhash))239 ARGIN(hash_comp_fn compare), 240 ARGIN(hash_hash_key_fn keyhash)) 242 241 __attribute__nonnull__(1) 243 __attribute__nonnull__(2) 244 __attribute__nonnull__(5) 245 __attribute__nonnull__(6) 246 FUNC_MODIFIES(*hptr); 242 __attribute__nonnull__(4) 243 __attribute__nonnull__(5); 247 244 248 void parrot_new_pmc_hash_x(PARROT_INTERP,249 ARGMOD(PMC *container),250 PARROT_DATA_TYPE val_type,251 Hash_key_type hkey_type,252 NOTNULL(hash_comp_fn compare),253 NOTNULL(hash_hash_key_fn keyhash))254 __attribute__nonnull__(1)255 __attribute__nonnull__(2)256 __attribute__nonnull__(5)257 __attribute__nonnull__(6)258 FUNC_MODIFIES(*container);259 260 245 #define ASSERT_ARGS_parrot_dump_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 261 246 PARROT_ASSERT_ARG(hash) 262 247 #define ASSERT_ARGS_parrot_hash_clone __attribute__unused__ int _ASSERT_ARGS_CHECK = \ … … 300 285 PARROT_ASSERT_ARG(interp) \ 301 286 || PARROT_ASSERT_ARG(hash) 302 287 #define ASSERT_ARGS_parrot_new_cstring_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 303 PARROT_ASSERT_ARG(interp) \ 304 || PARROT_ASSERT_ARG(hptr) 288 PARROT_ASSERT_ARG(interp) 305 289 #define ASSERT_ARGS_parrot_new_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 306 PARROT_ASSERT_ARG(interp) \ 307 || PARROT_ASSERT_ARG(hptr) 290 PARROT_ASSERT_ARG(interp) 308 291 #define ASSERT_ARGS_Parrot_new_INTVAL_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 309 292 PARROT_ASSERT_ARG(interp) 310 293 #define ASSERT_ARGS_parrot_new_pmc_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 311 294 PARROT_ASSERT_ARG(interp) \ 312 295 || PARROT_ASSERT_ARG(container) 313 296 #define ASSERT_ARGS_parrot_new_pointer_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 314 PARROT_ASSERT_ARG(interp) \ 315 || PARROT_ASSERT_ARG(hptr) 297 PARROT_ASSERT_ARG(interp) 316 298 #define ASSERT_ARGS_int_compare __attribute__unused__ int _ASSERT_ARGS_CHECK = 0 317 299 #define ASSERT_ARGS_key_hash_int __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 318 300 PARROT_ASSERT_ARG(value) … … 323 305 PARROT_ASSERT_ARG(interp) \ 324 306 || PARROT_ASSERT_ARG(hash) \ 325 307 || PARROT_ASSERT_ARG(func) 326 #define ASSERT_ARGS_parrot_ new_hash_x__attribute__unused__ int _ASSERT_ARGS_CHECK = \308 #define ASSERT_ARGS_parrot_create_hash __attribute__unused__ int _ASSERT_ARGS_CHECK = \ 327 309 PARROT_ASSERT_ARG(interp) \ 328 || PARROT_ASSERT_ARG(hptr) \329 310 || PARROT_ASSERT_ARG(compare) \ 330 311 || PARROT_ASSERT_ARG(keyhash) 331 #define ASSERT_ARGS_parrot_new_pmc_hash_x __attribute__unused__ int _ASSERT_ARGS_CHECK = \332 PARROT_ASSERT_ARG(interp) \333 || PARROT_ASSERT_ARG(container) \334 || PARROT_ASSERT_ARG(compare) \335 || PARROT_ASSERT_ARG(keyhash)336 312 /* Don't modify between HEADERIZER BEGIN / HEADERIZER END. Your changes will be lost. */ 337 313 /* HEADERIZER END: src/hash.c */ 338 314 -
compilers/imcc/imclexer.c
5495 5495 m = mem_allocate_zeroed_typed(macro_t); 5496 5496 5497 5497 if (!IMCC_INFO(interp)->macros) 5498 parrot_new_cstring_hash(interp, &IMCC_INFO(interp)->macros);5498 IMCC_INFO(interp)->macros = parrot_new_cstring_hash(interp); 5499 5499 parrot_hash_put(interp, IMCC_INFO(interp)->macros, 5500 5500 PARROT_const_cast(char *, name), m); 5501 5501 }
