bfd.info: Write the Derived Creation Routine
Go forward to Write Other Derived Routines
Go backward to Define the Derived Structures
Go up to Deriving a New Hash Table Type
Go to the top op bfd
Write the derived creation routine
You must write a routine which will create and initialize an entry
in the hash table. This routine is passed as the function argument to
`bfd_hash_table_init'.
In order to permit other hash tables to be derived from the hash
table you are creating, this routine must be written in a standard way.
The first argument to the creation routine is a pointer to a hash
table entry. This may be `NULL', in which case the routine should
allocate the right amount of space. Otherwise the space has already
been allocated by a hash table type derived from this one.
After allocating space, the creation routine must call the creation
routine of the hash table type it is derived from, passing in a pointer
to the space it just allocated. This will initialize any fields used
by the base hash table.
Finally the creation routine must initialize any local fields for
the new hash table type.
Here is a boilerplate example of a creation routine. FUNCTION_NAME
is the name of the routine. ENTRY_TYPE is the type of an entry in the
hash table you are creating. BASE_NEWFUNC is the name of the creation
routine of the hash table type your hash table is derived from.
struct bfd_hash_entry *
FUNCTION_NAME (entry, table, string)
struct bfd_hash_entry *entry;
struct bfd_hash_table *table;
const char *string;
{
struct ENTRY_TYPE *ret = (ENTRY_TYPE *) entry;
/* Allocate the structure if it has not already been allocated by a
derived class. */
if (ret == (ENTRY_TYPE *) NULL)
{
ret = ((ENTRY_TYPE *)
bfd_hash_allocate (table, sizeof (ENTRY_TYPE)));
if (ret == (ENTRY_TYPE *) NULL)
return NULL;
}
/* Call the allocation method of the base class. */
ret = ((ENTRY_TYPE *)
BASE_NEWFUNC ((struct bfd_hash_entry *) ret, table, string));
/* Initialize the local fields here. */
return (struct bfd_hash_entry *) ret;
}
*Description*
The creation routine for the linker hash table, which is in `linker.c',
looks just like this example. FUNCTION_NAME is
`_bfd_link_hash_newfunc'. ENTRY_TYPE is `struct bfd_link_hash_entry'.
BASE_NEWFUNC is `bfd_hash_newfunc', the creation routine for a basic
hash table.
`_bfd_link_hash_newfunc' also initializes the local fields in a
linker hash table entry: `type', `written' and `next'.
Created Wed Sep 1 16:41:34 2004 on bee with info_to_html version 0.9.6.