Changeset 1391 for branches/GNU/src/gcc/libiberty/hashtab.c
- Timestamp:
- Apr 27, 2004, 8:39:34 PM (21 years ago)
- Location:
- branches/GNU/src/gcc
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
branches/GNU/src/gcc
- Property svn:ignore
-
old new 26 26 configure.vr 27 27 configure.vrs 28 dir.info 28 29 Makefile 29 dir.info30 30 lost+found 31 31 update.out
-
- Property svn:ignore
-
branches/GNU/src/gcc/libiberty/hashtab.c
-
Property cvs2svn:cvs-rev
changed from
1.1
to1.1.1.2
r1390 r1391 44 44 #ifdef HAVE_STRING_H 45 45 #include <string.h> 46 #endif 47 48 #ifdef HAVE_MALLOC_H 49 #include <malloc.h> 46 50 #endif 47 51 … … 159 163 source length. Created hash table is initiated as empty (all the 160 164 hash table entries are EMPTY_ENTRY). The function returns the 161 created hash table. Memory allocation must not fail. */ 162 165 created hash table, or NULL if memory allocation fails. */ 166 167 htab_t 168 htab_create_alloc (size, hash_f, eq_f, del_f, alloc_f, free_f) 169 size_t size; 170 htab_hash hash_f; 171 htab_eq eq_f; 172 htab_del del_f; 173 htab_alloc alloc_f; 174 htab_free free_f; 175 { 176 htab_t result; 177 178 size = higher_prime_number (size); 179 result = (htab_t) (*alloc_f) (1, sizeof (struct htab)); 180 if (result == NULL) 181 return NULL; 182 result->entries = (PTR *) (*alloc_f) (size, sizeof (PTR)); 183 if (result->entries == NULL) 184 { 185 if (free_f != NULL) 186 (*free_f) (result); 187 return NULL; 188 } 189 result->size = size; 190 result->hash_f = hash_f; 191 result->eq_f = eq_f; 192 result->del_f = del_f; 193 result->alloc_f = alloc_f; 194 result->free_f = free_f; 195 return result; 196 } 197 198 /* These functions exist solely for backward compatibility. */ 199 200 #undef htab_create 163 201 htab_t 164 202 htab_create (size, hash_f, eq_f, del_f) … … 168 206 htab_del del_f; 169 207 { 170 htab_t result; 171 172 size = higher_prime_number (size); 173 result = (htab_t) xcalloc (1, sizeof (struct htab)); 174 result->entries = (PTR *) xcalloc (size, sizeof (PTR)); 175 result->size = size; 176 result->hash_f = hash_f; 177 result->eq_f = eq_f; 178 result->del_f = del_f; 179 result->return_allocation_failure = 0; 180 return result; 181 } 182 183 /* This function creates table with length slightly longer than given 184 source length. The created hash table is initiated as empty (all the 185 hash table entries are EMPTY_ENTRY). The function returns the created 186 hash table. Memory allocation may fail; it may return NULL. */ 208 return htab_create_alloc (size, hash_f, eq_f, del_f, xcalloc, free); 209 } 187 210 188 211 htab_t … … 193 216 htab_del del_f; 194 217 { 195 htab_t result; 196 197 size = higher_prime_number (size); 198 result = (htab_t) calloc (1, sizeof (struct htab)); 199 if (result == NULL) 200 return NULL; 201 202 result->entries = (PTR *) calloc (size, sizeof (PTR)); 203 if (result->entries == NULL) 204 { 205 free (result); 206 return NULL; 207 } 208 209 result->size = size; 210 result->hash_f = hash_f; 211 result->eq_f = eq_f; 212 result->del_f = del_f; 213 result->return_allocation_failure = 1; 214 return result; 218 return htab_create_alloc (size, hash_f, eq_f, del_f, calloc, free); 215 219 } 216 220 … … 230 234 (*htab->del_f) (htab->entries[i]); 231 235 232 free (htab->entries); 233 free (htab); 236 if (htab->free_f != NULL) 237 { 238 (*htab->free_f) (htab->entries); 239 (*htab->free_f) (htab); 240 } 234 241 } 235 242 … … 303 310 PTR *olimit; 304 311 PTR *p; 312 PTR *nentries; 305 313 size_t nsize; 306 314 … … 310 318 nsize = higher_prime_number (htab->size * 2); 311 319 312 if (htab->return_allocation_failure) 313 { 314 PTR *nentries = (PTR *) calloc (nsize, sizeof (PTR)); 315 if (nentries == NULL) 316 return 0; 317 htab->entries = nentries; 318 } 319 else 320 htab->entries = (PTR *) xcalloc (nsize, sizeof (PTR)); 321 320 nentries = (PTR *) (*htab->alloc_f) (nsize, sizeof (PTR)); 321 if (nentries == NULL) 322 return 0; 323 htab->entries = nentries; 322 324 htab->size = nsize; 325 323 326 htab->n_elements -= htab->n_deleted; 324 327 htab->n_deleted = 0; … … 340 343 while (p < olimit); 341 344 342 free (oentries); 345 if (htab->free_f != NULL) 346 (*htab->free_f) (oentries); 343 347 return 1; 344 348 } -
Property cvs2svn:cvs-rev
changed from
Note:
See TracChangeset
for help on using the changeset viewer.