From a69898aad0d92d44881d16b6d5d835c3af53b9c1 Mon Sep 17 00:00:00 2001 From: Alan Modra Date: Wed, 19 Sep 2007 12:08:34 +0000 Subject: [PATCH] * bfd-in.h (bfd_hash_insert): Declare. * bfd-in2.h: Regenerate. * hash.c (bfd_hash_insert): New function. Split out from.. (bfd_hash_lookup): ..here. * merge.c (sec_merge_hash_lookup): Use bfd_hash_insert. --- bfd/ChangeLog | 9 +++++++++ bfd/bfd-in.h | 4 ++++ bfd/bfd-in2.h | 4 ++++ bfd/hash.c | 27 +++++++++++++++++++++++---- bfd/merge.c | 7 +------ 5 files changed, 41 insertions(+), 10 deletions(-) diff --git a/bfd/ChangeLog b/bfd/ChangeLog index 76d7bbb5d38..279e70ef91d 100644 --- a/bfd/ChangeLog +++ b/bfd/ChangeLog @@ -1,3 +1,12 @@ +2007-09-19 Alan Modra + Doug Kwan + + * bfd-in.h (bfd_hash_insert): Declare. + * bfd-in2.h: Regenerate. + * hash.c (bfd_hash_insert): New function. Split out from.. + (bfd_hash_lookup): ..here. + * merge.c (sec_merge_hash_lookup): Use bfd_hash_insert. + 2007-09-18 Alan Modra * elf.c (bfd_section_from_shdr): Check bfd_alloc return. diff --git a/bfd/bfd-in.h b/bfd/bfd-in.h index 2e70a7391fd..07fdf036497 100644 --- a/bfd/bfd-in.h +++ b/bfd/bfd-in.h @@ -464,6 +464,10 @@ extern struct bfd_hash_entry *bfd_hash_lookup (struct bfd_hash_table *, const char *, bfd_boolean create, bfd_boolean copy); +/* Insert an entry in a hash table. */ +extern struct bfd_hash_entry *bfd_hash_insert + (struct bfd_hash_table *, const char *, unsigned long); + /* Replace an entry in a hash table. */ extern void bfd_hash_replace (struct bfd_hash_table *, struct bfd_hash_entry *old, diff --git a/bfd/bfd-in2.h b/bfd/bfd-in2.h index d3228d05e41..09432780ae6 100644 --- a/bfd/bfd-in2.h +++ b/bfd/bfd-in2.h @@ -471,6 +471,10 @@ extern struct bfd_hash_entry *bfd_hash_lookup (struct bfd_hash_table *, const char *, bfd_boolean create, bfd_boolean copy); +/* Insert an entry in a hash table. */ +extern struct bfd_hash_entry *bfd_hash_insert + (struct bfd_hash_table *, const char *, unsigned long); + /* Replace an entry in a hash table. */ extern void bfd_hash_replace (struct bfd_hash_table *, struct bfd_hash_entry *old, diff --git a/bfd/hash.c b/bfd/hash.c index 5edccac350a..14fc4030150 100644 --- a/bfd/hash.c +++ b/bfd/hash.c @@ -451,9 +451,6 @@ bfd_hash_lookup (struct bfd_hash_table *table, if (! create) return NULL; - hashp = (*table->newfunc) (NULL, table, string); - if (hashp == NULL) - return NULL; if (copy) { char *new; @@ -467,8 +464,26 @@ bfd_hash_lookup (struct bfd_hash_table *table, memcpy (new, string, len + 1); string = new; } + + return bfd_hash_insert (table, string, hash); +} + +/* Insert an entry in a hash table. */ + +struct bfd_hash_entry * +bfd_hash_insert (struct bfd_hash_table *table, + const char *string, + unsigned long hash) +{ + struct bfd_hash_entry *hashp; + unsigned int index; + + hashp = (*table->newfunc) (NULL, table, string); + if (hashp == NULL) + return NULL; hashp->string = string; hashp->hash = hash; + index = hash % table->size; hashp->next = table->table[index]; table->table[index] = hashp; table->count++; @@ -490,6 +505,11 @@ bfd_hash_lookup (struct bfd_hash_table *table, newtable = ((struct bfd_hash_entry **) objalloc_alloc ((struct objalloc *) table->memory, alloc)); + if (newtable == NULL) + { + table->frozen = 1; + return hashp; + } memset ((PTR) newtable, 0, alloc); for (hi = 0; hi < table->size; hi ++) @@ -497,7 +517,6 @@ bfd_hash_lookup (struct bfd_hash_table *table, { struct bfd_hash_entry *chain = table->table[hi]; struct bfd_hash_entry *chain_end = chain; - int index; while (chain_end->next && chain_end->next->hash == chain->hash) chain_end = chain_end->next; diff --git a/bfd/merge.c b/bfd/merge.c index 2e805c770e3..32994c3cba8 100644 --- a/bfd/merge.c +++ b/bfd/merge.c @@ -220,16 +220,11 @@ sec_merge_hash_lookup (struct sec_merge_hash *table, const char *string, return NULL; hashp = ((struct sec_merge_hash_entry *) - sec_merge_hash_newfunc (NULL, &table->table, string)); + bfd_hash_insert (&table->table, string, hash)); if (hashp == NULL) return NULL; - hashp->root.string = string; - hashp->root.hash = hash; hashp->len = len; hashp->alignment = alignment; - hashp->root.next = table->table.table[index]; - table->table.table[index] = (struct bfd_hash_entry *) hashp; - return hashp; } -- 2.30.2