Nie możesz wybrać więcej, niż 25 tematów Tematy muszą się zaczynać od litery lub cyfry, mogą zawierać myślniki ('-') i mogą mieć do 35 znaków.

158 lines
7.0KB

  1. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
  2. <html>
  3. <!-- This file documents the BFD library.
  4. Copyright (C) 1991-2020 Free Software Foundation, Inc.
  5. Permission is granted to copy, distribute and/or modify this document
  6. under the terms of the GNU Free Documentation License, Version 1.3 or
  7. any later version published by the Free Software Foundation; with the
  8. Invariant Sections being "GNU General Public License" and "Funding
  9. Free Software", the Front-Cover texts being (a) (see below), and with
  10. the Back-Cover Texts being (b) (see below). A copy of the license is
  11. included in the section entitled "GNU Free Documentation License".
  12. (a) The FSF's Front-Cover Text is:
  13. A GNU Manual
  14. (b) The FSF's Back-Cover Text is:
  15. You have freedom to copy and modify this GNU Manual, like GNU
  16. software. Copies published by the Free Software Foundation raise
  17. funds for GNU development. -->
  18. <!-- Created by GNU Texinfo 6.5, http://www.gnu.org/software/texinfo/ -->
  19. <head>
  20. <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
  21. <title>Write the Derived Creation Routine (Untitled Document)</title>
  22. <meta name="description" content="Write the Derived Creation Routine (Untitled Document)">
  23. <meta name="keywords" content="Write the Derived Creation Routine (Untitled Document)">
  24. <meta name="resource-type" content="document">
  25. <meta name="distribution" content="global">
  26. <meta name="Generator" content="makeinfo">
  27. <link href="index.html#Top" rel="start" title="Top">
  28. <link href="BFD-Index.html#BFD-Index" rel="index" title="BFD Index">
  29. <link href="index.html#SEC_Contents" rel="contents" title="Table of Contents">
  30. <link href="Deriving-a-New-Hash-Table-Type.html#Deriving-a-New-Hash-Table-Type" rel="up" title="Deriving a New Hash Table Type">
  31. <link href="Write-Other-Derived-Routines.html#Write-Other-Derived-Routines" rel="next" title="Write Other Derived Routines">
  32. <link href="Define-the-Derived-Structures.html#Define-the-Derived-Structures" rel="prev" title="Define the Derived Structures">
  33. <style type="text/css">
  34. <!--
  35. a.summary-letter {text-decoration: none}
  36. blockquote.indentedblock {margin-right: 0em}
  37. blockquote.smallindentedblock {margin-right: 0em; font-size: smaller}
  38. blockquote.smallquotation {font-size: smaller}
  39. div.display {margin-left: 3.2em}
  40. div.example {margin-left: 3.2em}
  41. div.lisp {margin-left: 3.2em}
  42. div.smalldisplay {margin-left: 3.2em}
  43. div.smallexample {margin-left: 3.2em}
  44. div.smalllisp {margin-left: 3.2em}
  45. kbd {font-style: oblique}
  46. pre.display {font-family: inherit}
  47. pre.format {font-family: inherit}
  48. pre.menu-comment {font-family: serif}
  49. pre.menu-preformatted {font-family: serif}
  50. pre.smalldisplay {font-family: inherit; font-size: smaller}
  51. pre.smallexample {font-size: smaller}
  52. pre.smallformat {font-family: inherit; font-size: smaller}
  53. pre.smalllisp {font-size: smaller}
  54. span.nolinebreak {white-space: nowrap}
  55. span.roman {font-family: initial; font-weight: normal}
  56. span.sansserif {font-family: sans-serif; font-weight: normal}
  57. ul.no-bullet {list-style: none}
  58. -->
  59. </style>
  60. </head>
  61. <body lang="en">
  62. <a name="Write-the-Derived-Creation-Routine"></a>
  63. <div class="header">
  64. <p>
  65. Next: <a href="Write-Other-Derived-Routines.html#Write-Other-Derived-Routines" accesskey="n" rel="next">Write Other Derived Routines</a>, Previous: <a href="Define-the-Derived-Structures.html#Define-the-Derived-Structures" accesskey="p" rel="prev">Define the Derived Structures</a>, Up: <a href="Deriving-a-New-Hash-Table-Type.html#Deriving-a-New-Hash-Table-Type" accesskey="u" rel="up">Deriving a New Hash Table Type</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="BFD-Index.html#BFD-Index" title="Index" rel="index">Index</a>]</p>
  66. </div>
  67. <hr>
  68. <a name="Write-the-derived-creation-routine"></a>
  69. <h4 class="subsubsection">2.18.4.2 Write the derived creation routine</h4>
  70. <p>You must write a routine which will create and initialize an
  71. entry in the hash table. This routine is passed as the
  72. function argument to <code>bfd_hash_table_init</code>.
  73. </p>
  74. <p>In order to permit other hash tables to be derived from the
  75. hash table you are creating, this routine must be written in a
  76. standard way.
  77. </p>
  78. <p>The first argument to the creation routine is a pointer to a
  79. hash table entry. This may be <code>NULL</code>, in which case the
  80. routine should allocate the right amount of space. Otherwise
  81. the space has already been allocated by a hash table type
  82. derived from this one.
  83. </p>
  84. <p>After allocating space, the creation routine must call the
  85. creation routine of the hash table type it is derived from,
  86. passing in a pointer to the space it just allocated. This
  87. will initialize any fields used by the base hash table.
  88. </p>
  89. <p>Finally the creation routine must initialize any local fields
  90. for the new hash table type.
  91. </p>
  92. <p>Here is a boilerplate example of a creation routine.
  93. <var>function_name</var> is the name of the routine.
  94. <var>entry_type</var> is the type of an entry in the hash table you
  95. are creating. <var>base_newfunc</var> is the name of the creation
  96. routine of the hash table type your hash table is derived
  97. from.
  98. </p>
  99. <div class="example">
  100. <pre class="example">struct bfd_hash_entry *
  101. <var>function_name</var> (struct bfd_hash_entry *entry,
  102. struct bfd_hash_table *table,
  103. const char *string)
  104. {
  105. struct <var>entry_type</var> *ret = (<var>entry_type</var> *) entry;
  106. /* Allocate the structure if it has not already been allocated by a
  107. derived class. */
  108. if (ret == NULL)
  109. {
  110. ret = bfd_hash_allocate (table, sizeof (* ret));
  111. if (ret == NULL)
  112. return NULL;
  113. }
  114. /* Call the allocation method of the base class. */
  115. ret = ((<var>entry_type</var> *)
  116. <var>base_newfunc</var> ((struct bfd_hash_entry *) ret, table, string));
  117. /* Initialize the local fields here. */
  118. return (struct bfd_hash_entry *) ret;
  119. }
  120. </pre></div>
  121. <p><strong>Description</strong><br>
  122. The creation routine for the linker hash table, which is in
  123. <code>linker.c</code>, looks just like this example.
  124. <var>function_name</var> is <code>_bfd_link_hash_newfunc</code>.
  125. <var>entry_type</var> is <code>struct bfd_link_hash_entry</code>.
  126. <var>base_newfunc</var> is <code>bfd_hash_newfunc</code>, the creation
  127. routine for a basic hash table.
  128. </p>
  129. <p><code>_bfd_link_hash_newfunc</code> also initializes the local fields
  130. in a linker hash table entry: <code>type</code>, <code>written</code> and
  131. <code>next</code>.
  132. </p>
  133. <hr>
  134. <div class="header">
  135. <p>
  136. Next: <a href="Write-Other-Derived-Routines.html#Write-Other-Derived-Routines" accesskey="n" rel="next">Write Other Derived Routines</a>, Previous: <a href="Define-the-Derived-Structures.html#Define-the-Derived-Structures" accesskey="p" rel="prev">Define the Derived Structures</a>, Up: <a href="Deriving-a-New-Hash-Table-Type.html#Deriving-a-New-Hash-Table-Type" accesskey="u" rel="up">Deriving a New Hash Table Type</a> &nbsp; [<a href="index.html#SEC_Contents" title="Table of contents" rel="contents">Contents</a>][<a href="BFD-Index.html#BFD-Index" title="Index" rel="index">Index</a>]</p>
  137. </div>
  138. </body>
  139. </html>