You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
127 lines
5.4 KiB
HTML
127 lines
5.4 KiB
HTML
4 years ago
|
<html lang="en">
|
||
|
<head>
|
||
|
<title>Write the Derived Creation Routine - Untitled</title>
|
||
|
<meta http-equiv="Content-Type" content="text/html">
|
||
|
<meta name="description" content="Untitled">
|
||
|
<meta name="generator" content="makeinfo 4.13">
|
||
|
<link title="Top" rel="start" href="index.html#Top">
|
||
|
<link rel="up" href="Deriving-a-New-Hash-Table-Type.html#Deriving-a-New-Hash-Table-Type" title="Deriving a New Hash Table Type">
|
||
|
<link rel="prev" href="Define-the-Derived-Structures.html#Define-the-Derived-Structures" title="Define the Derived Structures">
|
||
|
<link rel="next" href="Write-Other-Derived-Routines.html#Write-Other-Derived-Routines" title="Write Other Derived Routines">
|
||
|
<link href="http://www.gnu.org/software/texinfo/" rel="generator-home" title="Texinfo Homepage">
|
||
|
<!--
|
||
|
This file documents the BFD library.
|
||
|
|
||
|
Copyright (C) 1991-2015 Free Software Foundation, Inc.
|
||
|
|
||
|
Permission is granted to copy, distribute and/or modify this document
|
||
|
under the terms of the GNU Free Documentation License, Version 1.3 or
|
||
|
any later version published by the Free Software Foundation; with the
|
||
|
Invariant Sections being ``GNU General Public License'' and ``Funding
|
||
|
Free Software'', the Front-Cover texts being (a) (see below), and with
|
||
|
the Back-Cover Texts being (b) (see below). A copy of the license is
|
||
|
included in the section entitled ``GNU Free Documentation License''.
|
||
|
|
||
|
(a) The FSF's Front-Cover Text is:
|
||
|
|
||
|
A GNU Manual
|
||
|
|
||
|
(b) The FSF's Back-Cover Text is:
|
||
|
|
||
|
You have freedom to copy and modify this GNU Manual, like GNU
|
||
|
software. Copies published by the Free Software Foundation raise
|
||
|
funds for GNU development.-->
|
||
|
<meta http-equiv="Content-Style-Type" content="text/css">
|
||
|
<style type="text/css"><!--
|
||
|
pre.display { font-family:inherit }
|
||
|
pre.format { font-family:inherit }
|
||
|
pre.smalldisplay { font-family:inherit; font-size:smaller }
|
||
|
pre.smallformat { font-family:inherit; font-size:smaller }
|
||
|
pre.smallexample { font-size:smaller }
|
||
|
pre.smalllisp { font-size:smaller }
|
||
|
span.sc { font-variant:small-caps }
|
||
|
span.roman { font-family:serif; font-weight:normal; }
|
||
|
span.sansserif { font-family:sans-serif; font-weight:normal; }
|
||
|
--></style>
|
||
|
</head>
|
||
|
<body>
|
||
|
<div class="node">
|
||
|
<a name="Write-the-Derived-Creation-Routine"></a>
|
||
|
<p>
|
||
|
Next: <a rel="next" accesskey="n" href="Write-Other-Derived-Routines.html#Write-Other-Derived-Routines">Write Other Derived Routines</a>,
|
||
|
Previous: <a rel="previous" accesskey="p" href="Define-the-Derived-Structures.html#Define-the-Derived-Structures">Define the Derived Structures</a>,
|
||
|
Up: <a rel="up" accesskey="u" href="Deriving-a-New-Hash-Table-Type.html#Deriving-a-New-Hash-Table-Type">Deriving a New Hash Table Type</a>
|
||
|
<hr>
|
||
|
</div>
|
||
|
|
||
|
<h5 class="subsubsection">2.18.4.2 Write the derived creation routine</h5>
|
||
|
|
||
|
<p>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 <code>bfd_hash_table_init</code>.
|
||
|
|
||
|
<p>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.
|
||
|
|
||
|
<p>The first argument to the creation routine is a pointer to a
|
||
|
hash table entry. This may be <code>NULL</code>, 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.
|
||
|
|
||
|
<p>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.
|
||
|
|
||
|
<p>Finally the creation routine must initialize any local fields
|
||
|
for the new hash table type.
|
||
|
|
||
|
<p>Here is a boilerplate example of a creation routine.
|
||
|
<var>function_name</var> is the name of the routine.
|
||
|
<var>entry_type</var> is the type of an entry in the hash table you
|
||
|
are creating. <var>base_newfunc</var> is the name of the creation
|
||
|
routine of the hash table type your hash table is derived
|
||
|
from.
|
||
|
|
||
|
<pre class="example"> struct bfd_hash_entry *
|
||
|
<var>function_name</var> (struct bfd_hash_entry *entry,
|
||
|
struct bfd_hash_table *table,
|
||
|
const char *string)
|
||
|
{
|
||
|
struct <var>entry_type</var> *ret = (<var>entry_type</var> *) entry;
|
||
|
|
||
|
/* Allocate the structure if it has not already been allocated by a
|
||
|
derived class. */
|
||
|
if (ret == NULL)
|
||
|
{
|
||
|
ret = bfd_hash_allocate (table, sizeof (* ret));
|
||
|
if (ret == NULL)
|
||
|
return NULL;
|
||
|
}
|
||
|
|
||
|
/* Call the allocation method of the base class. */
|
||
|
ret = ((<var>entry_type</var> *)
|
||
|
<var>base_newfunc</var> ((struct bfd_hash_entry *) ret, table, string));
|
||
|
|
||
|
/* Initialize the local fields here. */
|
||
|
|
||
|
return (struct bfd_hash_entry *) ret;
|
||
|
}
|
||
|
</pre>
|
||
|
<p><strong>Description</strong><br>
|
||
|
The creation routine for the linker hash table, which is in
|
||
|
<code>linker.c</code>, looks just like this example.
|
||
|
<var>function_name</var> is <code>_bfd_link_hash_newfunc</code>.
|
||
|
<var>entry_type</var> is <code>struct bfd_link_hash_entry</code>.
|
||
|
<var>base_newfunc</var> is <code>bfd_hash_newfunc</code>, the creation
|
||
|
routine for a basic hash table.
|
||
|
|
||
|
<p><code>_bfd_link_hash_newfunc</code> also initializes the local fields
|
||
|
in a linker hash table entry: <code>type</code>, <code>written</code> and
|
||
|
<code>next</code>.
|
||
|
|
||
|
</body></html>
|
||
|
|