OpenCores
URL https://opencores.org/ocsvn/openrisc_me/openrisc_me/trunk

Subversion Repositories openrisc_me

[/] [openrisc/] [trunk/] [gnu-src/] [gdb-6.8/] [bfd/] [hash.c] - Diff between revs 157 and 225

Go to most recent revision | Show entire file | Details | Blame | View Log

Rev 157 Rev 225
Line 1... Line 1...
/* hash.c -- hash table routines for BFD
/* hash.c -- hash table routines for BFD
   Copyright 1993, 1994, 1995, 1997, 1999, 2001, 2002, 2003, 2004, 2005,
   Copyright 1993, 1994, 1995, 1997, 1999, 2001, 2002, 2003, 2004, 2005,
   2006, 2007 Free Software Foundation, Inc.
   2006, 2007, 2009 Free Software Foundation, Inc.
   Written by Steve Chamberlain <sac@cygnus.com>
   Written by Steve Chamberlain <sac@cygnus.com>
 
 
   This file is part of BFD, the Binary File Descriptor library.
   This file is part of BFD, the Binary File Descriptor library.
 
 
   This program is free software; you can redistribute it and/or modify
   This program is free software; you can redistribute it and/or modify
Line 372... Line 372...
  if (table->memory == NULL)
  if (table->memory == NULL)
    {
    {
      bfd_set_error (bfd_error_no_memory);
      bfd_set_error (bfd_error_no_memory);
      return FALSE;
      return FALSE;
    }
    }
  table->table = objalloc_alloc ((struct objalloc *) table->memory, alloc);
  table->table = (struct bfd_hash_entry **)
 
      objalloc_alloc ((struct objalloc *) table->memory, alloc);
  if (table->table == NULL)
  if (table->table == NULL)
    {
    {
      bfd_set_error (bfd_error_no_memory);
      bfd_set_error (bfd_error_no_memory);
      return FALSE;
      return FALSE;
    }
    }
Line 405... Line 406...
/* Free a hash table.  */
/* Free a hash table.  */
 
 
void
void
bfd_hash_table_free (struct bfd_hash_table *table)
bfd_hash_table_free (struct bfd_hash_table *table)
{
{
  objalloc_free (table->memory);
  objalloc_free ((struct objalloc *) table->memory);
  table->memory = NULL;
  table->memory = NULL;
}
}
 
 
/* Look up a string in a hash table.  */
/* Look up a string in a hash table.  */
 
 
Line 451... Line 452...
  if (! create)
  if (! create)
    return NULL;
    return NULL;
 
 
  if (copy)
  if (copy)
    {
    {
      char *new;
      char *new_string;
 
 
      new = objalloc_alloc ((struct objalloc *) table->memory, len + 1);
      new_string = (char *) objalloc_alloc ((struct objalloc *) table->memory,
      if (!new)
                                            len + 1);
 
      if (!new_string)
        {
        {
          bfd_set_error (bfd_error_no_memory);
          bfd_set_error (bfd_error_no_memory);
          return NULL;
          return NULL;
        }
        }
      memcpy (new, string, len + 1);
      memcpy (new_string, string, len + 1);
      string = new;
      string = new_string;
    }
    }
 
 
  return bfd_hash_insert (table, string, hash);
  return bfd_hash_insert (table, string, hash);
}
}
 
 
Line 578... Line 580...
bfd_hash_newfunc (struct bfd_hash_entry *entry,
bfd_hash_newfunc (struct bfd_hash_entry *entry,
                  struct bfd_hash_table *table,
                  struct bfd_hash_table *table,
                  const char *string ATTRIBUTE_UNUSED)
                  const char *string ATTRIBUTE_UNUSED)
{
{
  if (entry == NULL)
  if (entry == NULL)
    entry = bfd_hash_allocate (table, sizeof (* entry));
    entry = (struct bfd_hash_entry *) bfd_hash_allocate (table,
 
                                                         sizeof (* entry));
  return entry;
  return entry;
}
}
 
 
/* Traverse a hash table.  */
/* Traverse a hash table.  */
 
 
Line 673... Line 676...
  struct strtab_hash_entry *ret = (struct strtab_hash_entry *) entry;
  struct strtab_hash_entry *ret = (struct strtab_hash_entry *) entry;
 
 
  /* Allocate the structure if it has not already been allocated by a
  /* Allocate the structure if it has not already been allocated by a
     subclass.  */
     subclass.  */
  if (ret == NULL)
  if (ret == NULL)
    ret = bfd_hash_allocate (table, sizeof (* ret));
    ret = (struct strtab_hash_entry *) bfd_hash_allocate (table,
 
                                                          sizeof (* ret));
  if (ret == NULL)
  if (ret == NULL)
    return NULL;
    return NULL;
 
 
  /* Call the allocation method of the superclass.  */
  /* Call the allocation method of the superclass.  */
  ret = (struct strtab_hash_entry *)
  ret = (struct strtab_hash_entry *)
Line 705... Line 709...
_bfd_stringtab_init (void)
_bfd_stringtab_init (void)
{
{
  struct bfd_strtab_hash *table;
  struct bfd_strtab_hash *table;
  bfd_size_type amt = sizeof (* table);
  bfd_size_type amt = sizeof (* table);
 
 
  table = bfd_malloc (amt);
  table = (struct bfd_strtab_hash *) bfd_malloc (amt);
  if (table == NULL)
  if (table == NULL)
    return NULL;
    return NULL;
 
 
  if (!bfd_hash_table_init (&table->table, strtab_hash_newfunc,
  if (!bfd_hash_table_init (&table->table, strtab_hash_newfunc,
                            sizeof (struct strtab_hash_entry)))
                            sizeof (struct strtab_hash_entry)))
Line 768... Line 772...
      if (entry == NULL)
      if (entry == NULL)
        return (bfd_size_type) -1;
        return (bfd_size_type) -1;
    }
    }
  else
  else
    {
    {
      entry = bfd_hash_allocate (&tab->table, sizeof (* entry));
      entry = (struct strtab_hash_entry *) bfd_hash_allocate (&tab->table,
 
                                                              sizeof (* entry));
      if (entry == NULL)
      if (entry == NULL)
        return (bfd_size_type) -1;
        return (bfd_size_type) -1;
      if (! copy)
      if (! copy)
        entry->root.string = str;
        entry->root.string = str;
      else
      else
        {
        {
          char *n;
          char *n;
 
 
          n = bfd_hash_allocate (&tab->table, strlen (str) + 1);
          n = (char *) bfd_hash_allocate (&tab->table, strlen (str) + 1);
          if (n == NULL)
          if (n == NULL)
            return (bfd_size_type) -1;
            return (bfd_size_type) -1;
          entry->root.string = n;
          entry->root.string = n;
        }
        }
      entry->index = (bfd_size_type) -1;
      entry->index = (bfd_size_type) -1;

powered by: WebSVN 2.1.0

© copyright 1999-2024 OpenCores.org, equivalent to Oliscience, all rights reserved. OpenCores®, registered trademark.