View | Details | Raw Unified | Return to bug 193964
Collapse All | Expand All

(-)devel/gperf/files/patch-offsetof (+26 lines)
Line 0 Link Here
1
--- src/output.cc	2007-03-31 08:16:05.000000000 -0700
2
+++ src/output.cc	2008-05-27 16:07:01.000000000 -0700
3
@@ -1106,9 +1106,7 @@ output_keyword_entry (KeywordExt *temp, 
4
   if (option[TYPE])
5
     printf ("{");
6
   if (option[SHAREDLIB])
7
-    printf ("(int)(long)&((struct %s_t *)0)->%s_str%d",
8
-            option.get_stringpool_name (), option.get_stringpool_name (),
9
-            stringpool_index);
10
+    printf("offsetof(struct %s_t, %s_str%d)", option.get_stringpool_name (), option.get_stringpool_name (), stringpool_index);
11
   else
12
     output_string (temp->_allchars, temp->_allchars_length);
13
   if (option[TYPE])
14
@@ -2035,8 +2033,11 @@ Output::output ()
15
       printf ("%s\n", _struct_decl);
16
     }
17
 
18
-  if (option[INCLUDE])
19
+  if (option[INCLUDE]) {
20
     printf ("#include <string.h>\n"); /* Declare strlen(), strcmp(), strncmp(). */
21
+    if (option[SHAREDLIB])
22
+      printf("#include <stddef.h>\n"); /* Declare offsetof() */
23
+  }
24
 
25
   if (!option[ENUM])
26
     {
(-)devel/gperf/files/patch-size_type (+307 lines)
Line 0 Link Here
1
diff -up -r ./doc/gperf.1 ./doc/gperf.1
2
--- ./doc/gperf.1	2007-05-02 09:01:25.000000000 -0700
3
+++ ./doc/gperf.1	2011-10-06 14:21:41.000000000 -0700
4
@@ -1,7 +1,7 @@
5
 .\" DO NOT MODIFY THIS FILE!  It was generated by help2man 1.23.
6
-.TH GPERF "1" "May 2007" "GNU gperf 3.0.3" FSF
7
+.TH GPERF "1" "October 2011" "GNU gperf 3.0.3" FSF
8
 .SH NAME
9
-gperf \- generate a perfect hash function from a key set
10
+gperf \- manual page for gperf 3.0.3
11
 .SH SYNOPSIS
12
 .B gperf
13
 [\fIOPTION\fR]... [\fIINPUT-FILE\fR]
14
@@ -129,6 +129,10 @@ binary search.
15
 Prevents the transfer of the type declaration to the
16
 output file. Use this option if the type is already
17
 defined elsewhere.
18
+.TP
19
+\fB\-\-size\-type\fR=\fITYPE\fR
20
+Specify the type for length parameters. Default type is
21
+\&'unsigned int'.
22
 .SS "Algorithm employed by gperf:"
23
 .TP
24
 \fB\-k\fR, \fB\-\-key\-positions\fR=\fIKEYS\fR
25
diff -up -r ./src/options.cc ./src/options.cc
26
--- ./src/options.cc	2007-03-31 08:22:16.000000000 -0700
27
+++ ./src/options.cc	2011-10-06 14:13:41.000000000 -0700
28
@@ -67,6 +67,8 @@ static const char *const DEFAULT_STRINGP
29
 /* Default delimiters that separate keywords from their attributes.  */
30
 static const char *const DEFAULT_DELIMITERS = ",";
31
 
32
+static const char *const DEFAULT_SIZE_TYPE = "unsigned int";
33
+
34
 /* Prints program usage to given stream.  */
35
 
36
 void
37
@@ -202,6 +204,9 @@ Options::long_usage (FILE * stream)
38
            "                         Prevents the transfer of the type declaration to the\n"
39
            "                         output file. Use this option if the type is already\n"
40
            "                         defined elsewhere.\n");
41
+  fprintf (stream,
42
+           "      --size-type=TYPE   Specify the type for length parameters. Default type is\n"
43
+	   "                         'unsigned int'.\n");
44
   fprintf (stream, "\n");
45
   fprintf (stream,
46
            "Algorithm employed by gperf:\n");
47
@@ -468,6 +473,7 @@ Options::Options ()
48
     _lengthtable_name (DEFAULT_LENGTHTABLE_NAME),
49
     _stringpool_name (DEFAULT_STRINGPOOL_NAME),
50
     _delimiters (DEFAULT_DELIMITERS),
51
+    _size_type (DEFAULT_SIZE_TYPE),
52
     _key_positions ()
53
 {
54
 }
55
@@ -512,6 +518,7 @@ Options::~Options ()
56
                "\nhash table size multiplier = %g"
57
                "\ninitial associated value = %d"
58
                "\ndelimiters = %s"
59
+	       "\nsize type = %s"
60
                "\nnumber of switch statements = %d\n",
61
                _option_word & TYPE ? "enabled" : "disabled",
62
                _option_word & UPPERLOWER ? "enabled" : "disabled",
63
@@ -537,7 +544,7 @@ Options::~Options ()
64
                _function_name, _hash_name, _wordlist_name, _lengthtable_name,
65
                _stringpool_name, _slot_name, _initializer_suffix,
66
                _asso_iterations, _jump, _size_multiple, _initial_asso_value,
67
-               _delimiters, _total_switches);
68
+               _delimiters, _size_type, _total_switches);
69
       if (_key_positions.is_useall())
70
         fprintf (stderr, "all characters are used in the hash function\n");
71
       else
72
@@ -666,6 +673,12 @@ Options::set_delimiters (const char *del
73
     _delimiters = delimiters;
74
 }
75
 
76
+void
77
+Options::set_size_type (const char *size_type)
78
+{
79
+  if (_size_type == DEFAULT_SIZE_TYPE) 
80
+    _size_type = size_type;
81
+}
82
 
83
 /* Parses the command line Options and sets appropriate flags in option_word.  */
84
 
85
@@ -691,6 +704,7 @@ static const struct option long_options[
86
   { "global-table", no_argument, NULL, 'G' },
87
   { "word-array-name", required_argument, NULL, 'W' },
88
   { "length-table-name", required_argument, NULL, CHAR_MAX + 4 },
89
+  { "size-type", required_argument, NULL, CHAR_MAX + 5 },
90
   { "switch", required_argument, NULL, 'S' },
91
   { "omit-struct-type", no_argument, NULL, 'T' },
92
   { "key-positions", required_argument, NULL, 'k' },
93
@@ -1044,6 +1058,11 @@ warranty; not even for MERCHANTABILITY o
94
             _lengthtable_name = /*getopt*/optarg;
95
             break;
96
           }
97
+        case CHAR_MAX + 5:      /* Sets the name for the length table array.  */
98
+          {
99
+            _size_type = /*getopt*/optarg;
100
+            break;
101
+          }
102
         default:
103
           short_usage (stderr);
104
           exit (1);
105
Only in ./src: options.cc~
106
diff -up -r ./src/options.h ./src/options.h
107
--- ./src/options.h	2005-05-14 07:22:36.000000000 -0700
108
+++ ./src/options.h	2011-10-06 13:29:28.000000000 -0700
109
@@ -209,6 +209,9 @@ public:
110
   /* Sets the delimiters string, if not already set.  */
111
   void                  set_delimiters (const char *delimiters);
112
 
113
+  const char *		get_size_type() const;
114
+  void			set_size_type(const char*);
115
+
116
   /* Returns key positions.  */
117
   const Positions&      get_key_positions () const;
118
 
119
@@ -279,6 +282,8 @@ private:
120
   /* Separates keywords from other attributes.  */
121
   const char *          _delimiters;
122
 
123
+  const char *		_size_type;
124
+
125
   /* Contains user-specified key choices.  */
126
   Positions             _key_positions;
127
 };
128
Only in ./src: options.h~
129
diff -up -r ./src/options.icc ./src/options.icc
130
--- ./src/options.icc	2005-05-14 07:22:36.000000000 -0700
131
+++ ./src/options.icc	2011-10-06 13:42:59.000000000 -0700
132
@@ -155,3 +155,9 @@ Options::get_key_positions () const
133
 {
134
   return _key_positions;
135
 }
136
+
137
+INLINE const char *
138
+Options::get_size_type() const
139
+{
140
+	return _size_type;
141
+}
142
Only in ./src: options.icc~
143
diff -up -r ./src/output.cc ./src/output.cc
144
--- ./src/output.cc	2011-10-06 14:23:05.000000000 -0700
145
+++ ./src/output.cc	2011-10-06 13:41:53.000000000 -0700
146
@@ -772,14 +772,14 @@ Output::output_hash_function () const
147
   printf (option[KRC] ?
148
                  "(str, len)\n"
149
             "     register char *str;\n"
150
-            "     register unsigned int len;\n" :
151
+            "     register %s len;\n" :
152
           option[C] ?
153
                  "(str, len)\n"
154
             "     register const char *str;\n"
155
-            "     register unsigned int len;\n" :
156
+            "     register %s len;\n" :
157
           option[ANSIC] | option[CPLUSPLUS] ?
158
-                 "(register const char *str, register unsigned int len)\n" :
159
-          "");
160
+                 "(register const char *str, register %s len)\n" :
161
+          "", option.get_size_type());
162
 
163
   /* Note that when the hash function is called, it has already been verified
164
      that  min_key_len <= len <= max_key_len.  */
165
@@ -875,7 +875,7 @@ Output::output_hash_function () const
166
                   "  switch (%s)\n"
167
                   "    {\n"
168
                   "      default:\n",
169
-                  option[NOLENGTH] ? "0" : "len",
170
+                  option[NOLENGTH] ? "0" : "(int)len",
171
                   option[NOLENGTH] ? "len" : "hval");
172
 
173
           while (key_pos != Positions::LASTCHAR && key_pos >= _max_key_len)
174
@@ -1900,14 +1900,14 @@ Output::output_lookup_function () const
175
   printf (option[KRC] ?
176
                  "(str, len)\n"
177
             "     register char *str;\n"
178
-            "     register unsigned int len;\n" :
179
+            "     register %s len;\n" :
180
           option[C] ?
181
                  "(str, len)\n"
182
             "     register const char *str;\n"
183
-            "     register unsigned int len;\n" :
184
+            "     register %s len;\n" :
185
           option[ANSIC] | option[CPLUSPLUS] ?
186
-                 "(register const char *str, register unsigned int len)\n" :
187
-          "");
188
+                 "(register const char *str, register %s len)\n" :
189
+          "", option.get_size_type());
190
 
191
   /* Output the function's body.  */
192
   printf ("{\n");
193
@@ -2074,13 +2073,14 @@ Output::output ()
194
     printf ("class %s\n"
195
             "{\n"
196
             "private:\n"
197
-            "  static inline unsigned int %s (const char *str, unsigned int len);\n"
198
+            "  static inline unsigned int %s (const char *str, %s len);\n"
199
             "public:\n"
200
-            "  static %s%s%s (const char *str, unsigned int len);\n"
201
+            "  static %s%s%s (const char *str, %s len);\n"
202
             "};\n"
203
             "\n",
204
-            option.get_class_name (), option.get_hash_name (),
205
-            const_for_struct, _return_type, option.get_function_name ());
206
+            option.get_class_name (), option.get_hash_name (), option.get_size_type(),
207
+            const_for_struct, _return_type, option.get_function_name (),
208
+	    option.get_size_type());
209
 
210
   output_hash_function ();
211
 
212
Only in ./src: output.cc~
213
diff -up -r ./tests/c-parse.exp ./tests/c-parse.exp
214
--- ./tests/c-parse.exp	2007-04-06 08:38:50.000000000 -0700
215
+++ ./tests/c-parse.exp	2011-10-06 13:45:57.000000000 -0700
216
@@ -80,7 +80,7 @@ hash (str, len)
217
       126, 126, 126, 126, 126, 126, 126, 126, 126, 126,
218
       126, 126, 126, 126, 126, 126
219
     };
220
-  register int hval = len;
221
+  register int hval = (int)len;
222
 
223
   switch (hval)
224
     {
225
diff -up -r ./tests/charsets.exp ./tests/charsets.exp
226
--- ./tests/charsets.exp	2007-04-19 04:13:42.000000000 -0700
227
+++ ./tests/charsets.exp	2011-10-06 13:47:31.000000000 -0700
228
@@ -89,7 +90,7 @@ hash (str, len)
229
       5046, 5046, 5046, 5046, 5046, 5046, 5046, 5046, 5046, 5046,
230
       5046, 5046, 5046, 5046, 5046, 5046, 5046, 5046, 5046
231
     };
232
-  register int hval = len;
233
+  register int hval = (int)len;
234
 
235
   switch (hval)
236
     {
237
diff -up -r ./tests/chill.exp ./tests/chill.exp
238
--- ./tests/chill.exp	2007-04-19 04:13:42.000000000 -0700
239
+++ ./tests/chill.exp	2011-10-06 13:46:47.000000000 -0700
240
@@ -78,7 +78,7 @@ hash (str, len)
241
       1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050, 1050,
242
       1050, 1050, 1050, 1050, 1050, 1050, 1050
243
     };
244
-  register int hval = len;
245
+  register int hval = (int)len;
246
 
247
   switch (hval)
248
     {
249
diff -up -r ./tests/cplusplus.exp ./tests/cplusplus.exp
250
--- ./tests/cplusplus.exp	2007-04-19 03:16:41.000000000 -0700
251
+++ ./tests/cplusplus.exp	2011-10-06 13:47:03.000000000 -0700
252
@@ -80,7 +80,7 @@ hash (str, len)
253
       164, 164, 164, 164, 164, 164, 164, 164, 164, 164,
254
       164, 164, 164, 164, 164, 164
255
     };
256
-  register int hval = len;
257
+  register int hval = (int)len;
258
 
259
   switch (hval)
260
     {
261
diff -up -r ./tests/java.exp ./tests/java.exp
262
--- ./tests/java.exp	2007-04-19 03:16:41.000000000 -0700
263
+++ ./tests/java.exp	2011-10-06 13:47:19.000000000 -0700
264
@@ -104,7 +104,7 @@ hash (str, len)
265
       77, 77, 77, 77, 77, 77, 77, 77, 77, 77,
266
       77, 77, 77, 77, 77, 77
267
     };
268
-  register int hval = len;
269
+  register int hval = (int)len;
270
 
271
   switch (hval)
272
     {
273
diff -up -r ./tests/languages.exp ./tests/languages.exp
274
--- ./tests/languages.exp	2007-04-19 03:16:41.000000000 -0700
275
+++ ./tests/languages.exp	2011-10-06 13:47:47.000000000 -0700
276
@@ -93,7 +94,7 @@ hash (str, len)
277
       3861, 3861, 3861, 3861, 3861, 3861, 3861, 3861, 3861, 3861,
278
       3861, 3861, 3861, 3861, 3861
279
     };
280
-  register int hval = len;
281
+  register int hval = (int)len;
282
 
283
   switch (hval)
284
     {
285
diff -up -r ./tests/objc.exp ./tests/objc.exp
286
--- ./tests/objc.exp	2007-04-19 03:16:41.000000000 -0700
287
+++ ./tests/objc.exp	2011-10-06 13:46:34.000000000 -0700
288
@@ -80,7 +80,7 @@ hash (str, len)
289
       96, 96, 96, 96, 96, 96, 96, 96, 96, 96,
290
       96, 96, 96, 96, 96, 96
291
     };
292
-  register int hval = len;
293
+  register int hval = (int)len;
294
 
295
   switch (hval)
296
     {
297
--- tests/test-6.exp	2004-08-22 09:04:17.000000000 -0700
298
+++ tests/test-6.out	2011-10-06 14:31:09.000000000 -0700
299
@@ -88,6 +88,8 @@ Details in the output code:
300
                          Prevents the transfer of the type declaration to the
301
                          output file. Use this option if the type is already
302
                          defined elsewhere.
303
+      --size-type=TYPE   Specify the type for length parameters. Default type is
304
+                         'unsigned int'.
305
 
306
 Algorithm employed by gperf:
307
   -k, --key-positions=KEYS

Return to bug 193964