Ignore:
Timestamp:
Apr 27, 2004, 8:39:34 PM (21 years ago)
Author:
bird
Message:

GCC v3.3.3 sources.

Location:
branches/GNU/src/gcc
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • branches/GNU/src/gcc

    • Property svn:ignore
      •  

        old new  
        2626configure.vr
        2727configure.vrs
         28dir.info
        2829Makefile
        29 dir.info
        3030lost+found
        3131update.out
  • branches/GNU/src/gcc/libiberty/hashtab.c

    • Property cvs2svn:cvs-rev changed from 1.1 to 1.1.1.2
    r1390 r1391  
    4444#ifdef HAVE_STRING_H
    4545#include <string.h>
     46#endif
     47
     48#ifdef HAVE_MALLOC_H
     49#include <malloc.h>
    4650#endif
    4751
     
    159163   source length.  Created hash table is initiated as empty (all the
    160164   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
     167htab_t
     168htab_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
    163201htab_t
    164202htab_create (size, hash_f, eq_f, del_f)
     
    168206     htab_del del_f;
    169207{
    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}
    187210
    188211htab_t
     
    193216     htab_del del_f;
    194217{
    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);
    215219}
    216220
     
    230234        (*htab->del_f) (htab->entries[i]);
    231235
    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    }
    234241}
    235242
     
    303310  PTR *olimit;
    304311  PTR *p;
     312  PTR *nentries;
    305313  size_t nsize;
    306314
     
    310318  nsize = higher_prime_number (htab->size * 2);
    311319
    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;
    322324  htab->size = nsize;
     325
    323326  htab->n_elements -= htab->n_deleted;
    324327  htab->n_deleted = 0;
     
    340343  while (p < olimit);
    341344
    342   free (oentries);
     345  if (htab->free_f != NULL)
     346    (*htab->free_f) (oentries);
    343347  return 1;
    344348}
Note: See TracChangeset for help on using the changeset viewer.