Commit 2eb1573f01710832bbe60a4ece89cb301727612a

Authored by Mike Frysinger
Committed by Wolfgang Denk
1 parent c22a711d24

hashtable: drop all non-reentrant versions

The non-reentrant versions of the hashtable functions operate on a single
shared hashtable.  So if two different people try using these funcs for
two different purposes, they'll cause problems for the other.

Avoid this by converting all existing hashtable consumers over to the
reentrant versions and then punting the non-reentrant ones.

Signed-off-by: Mike Frysinger <vapier@gentoo.org>

Showing 13 changed files with 35 additions and 77 deletions Side-by-side Diff

... ... @@ -111,7 +111,7 @@
111 111  
112 112 e.key = name;
113 113 e.data = NULL;
114   - ep = hsearch (e, FIND);
  114 + hsearch_r(e, FIND, &ep, &env_htab);
115 115 if (ep == NULL)
116 116 return 0;
117 117 len = printf ("%s=%s\n", ep->key, ep->data);
... ... @@ -119,7 +119,7 @@
119 119 }
120 120  
121 121 /* print whole list */
122   - len = hexport('\n', &res, 0);
  122 + len = hexport_r(&env_htab, '\n', &res, 0);
123 123  
124 124 if (len > 0) {
125 125 puts(res);
... ... @@ -184,7 +184,7 @@
184 184 */
185 185 e.key = name;
186 186 e.data = NULL;
187   - ep = hsearch (e, FIND);
  187 + hsearch_r(e, FIND, &ep, &env_htab);
188 188  
189 189 /* Check for console redirection */
190 190 if (strcmp(name,"stdin") == 0) {
... ... @@ -267,7 +267,7 @@
267 267  
268 268 /* Delete only ? */
269 269 if ((argc < 3) || argv[2] == NULL) {
270   - int rc = hdelete(name);
  270 + int rc = hdelete_r(name, &env_htab);
271 271 return !rc;
272 272 }
273 273  
... ... @@ -293,7 +293,7 @@
293 293  
294 294 e.key = name;
295 295 e.data = value;
296   - ep = hsearch(e, ENTER);
  296 + hsearch_r(e, ENTER, &ep, &env_htab);
297 297 free(value);
298 298 if (!ep) {
299 299 printf("## Error inserting \"%s\" variable, errno=%d\n",
... ... @@ -456,7 +456,7 @@
456 456  
457 457 e.key = name;
458 458 e.data = NULL;
459   - ep = hsearch (e, FIND);
  459 + hsearch_r(e, FIND, &ep, &env_htab);
460 460  
461 461 return (ep ? ep->data : NULL);
462 462 }
... ... @@ -651,7 +651,7 @@
651 651 }
652 652  
653 653 if (sep) { /* export as text file */
654   - len = hexport(sep, &addr, size);
  654 + len = hexport_r(&env_htab, sep, &addr, size);
655 655 if (len < 0) {
656 656 error("Cannot export environment: errno = %d\n",
657 657 errno);
... ... @@ -670,7 +670,7 @@
670 670 else /* export as raw binary data */
671 671 res = addr;
672 672  
673   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  673 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
674 674 if (len < 0) {
675 675 error("Cannot export environment: errno = %d\n",
676 676 errno);
... ... @@ -790,7 +790,7 @@
790 790 addr = (char *)ep->data;
791 791 }
792 792  
793   - if (himport(addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
  793 + if (himport_r(&env_htab, addr, size, sep, del ? 0 : H_NOCLEAR) == 0) {
794 794 error("Environment import failed: errno = %d\n", errno);
795 795 return 1;
796 796 }
... ... @@ -129,6 +129,8 @@
129 129 "\0"
130 130 };
131 131  
  132 +struct hsearch_data env_htab;
  133 +
132 134 static uchar env_get_char_init (int index)
133 135 {
134 136 uchar c;
... ... @@ -187,7 +189,7 @@
187 189 puts("Using default environment\n\n");
188 190 }
189 191  
190   - if (himport((char *)default_environment,
  192 + if (himport_r(&env_htab, (char *)default_environment,
191 193 sizeof(default_environment), '\0', 0) == 0) {
192 194 error("Environment import failed: errno = %d\n", errno);
193 195 }
... ... @@ -213,7 +215,7 @@
213 215 }
214 216 }
215 217  
216   - if (himport((char *)ep->data, ENV_SIZE, '(char *)ep->data, ENV_SIZE, '\0', 0)) {', 0)) {
  218 + if (himport_r(&env_htab, (char *)ep->data, ENV_SIZE, '(char *)ep->data, ENV_SIZE, '\0', 0)) {', 0)) {
217 219 gd->flags |= GD_FLG_ENV_READY;
218 220 return 1;
219 221 }
common/env_dataflash.c
... ... @@ -68,7 +68,7 @@
68 68 char *res;
69 69  
70 70 res = (char *)&env_new.data;
71   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  71 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
72 72 if (len < 0) {
73 73 error("Cannot export environment: errno = %d\n", errno);
74 74 return 1;
... ... @@ -143,7 +143,7 @@
143 143 BUG_ON(env_ptr != NULL);
144 144  
145 145 res = (char *)&env_new.data;
146   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  146 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
147 147 if (len < 0) {
148 148 error("Cannot export environment: errno = %d\n", errno);
149 149 return 1;
... ... @@ -155,7 +155,7 @@
155 155 }
156 156  
157 157 res = (char *)&env_new.data;
158   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  158 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
159 159 if (len < 0) {
160 160 error("Cannot export environment: errno = %d\n", errno);
161 161 goto done;
... ... @@ -289,7 +289,7 @@
289 289 goto done;
290 290  
291 291 res = (char *)&env_new.data;
292   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  292 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
293 293 if (len < 0) {
294 294 error("Cannot export environment: errno = %d\n", errno);
295 295 goto done;
... ... @@ -107,7 +107,7 @@
107 107 return 1;
108 108  
109 109 res = (char *)&env_new.data;
110   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  110 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
111 111 if (len < 0) {
112 112 error("Cannot export environment: errno = %d\n", errno);
113 113 return 1;
... ... @@ -199,7 +199,7 @@
199 199 return 1;
200 200  
201 201 res = (char *)&env_new.data;
202   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  202 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
203 203 if (len < 0) {
204 204 error("Cannot export environment: errno = %d\n", errno);
205 205 return 1;
... ... @@ -256,7 +256,7 @@
256 256 return 1;
257 257  
258 258 res = (char *)&env_new.data;
259   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  259 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
260 260 if (len < 0) {
261 261 error("Cannot export environment: errno = %d\n", errno);
262 262 return 1;
... ... @@ -94,7 +94,7 @@
94 94 int rcode = 0;
95 95  
96 96 res = (char *)&env_new.data;
97   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  97 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
98 98 if (len < 0) {
99 99 error("Cannot export environment: errno = %d\n", errno);
100 100 return 1;
common/env_onenand.c
... ... @@ -109,7 +109,7 @@
109 109 };
110 110  
111 111 res = (char *)&env_new.data;
112   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  112 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
113 113 if (len < 0) {
114 114 error("Cannot export environment: errno = %d\n", errno);
115 115 return 1;
... ... @@ -92,7 +92,7 @@
92 92 }
93 93  
94 94 res = (char *)&env_new.data;
95   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  95 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
96 96 if (len < 0) {
97 97 error("Cannot export environment: errno = %d\n", errno);
98 98 return 1;
... ... @@ -308,7 +308,7 @@
308 308 }
309 309  
310 310 res = (char *)&env_new.data;
311   - len = hexport(''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
  311 + len = hexport_r(&env_htab, ''\0', &res, ENV_SIZE);', &res, ENV_SIZE);
312 312 if (len < 0) {
313 313 error("Cannot export environment: errno = %d\n", errno);
314 314 goto done;
include/environment.h
... ... @@ -149,6 +149,12 @@
149 149 unsigned char data[ENV_SIZE]; /* Environment data */
150 150 } env_t;
151 151  
  152 +#ifndef DO_DEPS_ONLY
  153 +
  154 +#include <search.h>
  155 +
  156 +extern struct hsearch_data env_htab;
  157 +
152 158 /* Function that returns a character from the environment */
153 159 unsigned char env_get_char (int);
154 160  
... ... @@ -164,6 +170,8 @@
164 170  
165 171 /* Import from binary representation into hash table */
166 172 int env_import(const char *buf, int check);
  173 +
  174 +#endif
167 175  
168 176 #endif /* _ENVIRONMENT_H_ */
... ... @@ -32,15 +32,6 @@
32 32  
33 33 #define __set_errno(val) do { errno = val; } while (0)
34 34  
35   -/*
36   - * Prototype structure for a linked-list data structure.
37   - * This is the type used by the `insque' and `remque' functions.
38   - */
39   -
40   -/* For use with hsearch(3). */
41   -typedef int (*__compar_fn_t) (__const void *, __const void *);
42   -typedef __compar_fn_t comparison_fn_t;
43   -
44 35 /* Action which shall be performed in the call the hsearch. */
45 36 typedef enum {
46 37 FIND,
47 38  
... ... @@ -69,11 +60,9 @@
69 60 };
70 61  
71 62 /* Create a new hashing table which will at most contain NEL elements. */
72   -extern int hcreate(size_t __nel);
73 63 extern int hcreate_r(size_t __nel, struct hsearch_data *__htab);
74 64  
75 65 /* Destroy current internal hashing table. */
76   -extern void hdestroy(void);
77 66 extern void hdestroy_r(struct hsearch_data *__htab);
78 67  
79 68 /*
80 69  
81 70  
82 71  
83 72  
... ... @@ -82,25 +71,20 @@
82 71 * NULL. If ACTION is `ENTER' replace existing data (if any) with
83 72 * ITEM.data.
84 73 * */
85   -extern ENTRY *hsearch(ENTRY __item, ACTION __action);
86 74 extern int hsearch_r(ENTRY __item, ACTION __action, ENTRY ** __retval,
87 75 struct hsearch_data *__htab);
88 76  
89 77 /* Search and delete entry matching ITEM.key in internal hash table. */
90   -extern int hdelete(const char *__key);
91 78 extern int hdelete_r(const char *__key, struct hsearch_data *__htab);
92 79  
93   -extern ssize_t hexport(const char __sep, char **__resp, size_t __size);
94 80 extern ssize_t hexport_r(struct hsearch_data *__htab,
95 81 const char __sep, char **__resp, size_t __size);
96 82  
97   -extern int himport(const char *__env, size_t __size, const char __sep,
98   - int __flag);
99 83 extern int himport_r(struct hsearch_data *__htab,
100 84 const char *__env, size_t __size, const char __sep,
101 85 int __flag);
102 86  
103   -/* Flags for himport() / himport_r() */
  87 +/* Flags for himport_r() */
104 88 #define H_NOCLEAR 1 /* do not clear hash table before importing */
105 89  
106 90 #endif /* search.h */
... ... @@ -60,11 +60,6 @@
60 60 */
61 61  
62 62 /*
63   - * The non-reentrant version use a global space for storing the hash table.
64   - */
65   -static struct hsearch_data htab;
66   -
67   -/*
68 63 * The reentrant version has no static variables to maintain the state.
69 64 * Instead the interface of all functions is extended to take an argument
70 65 * which describes the current status.
... ... @@ -97,11 +92,6 @@
97 92 return number % div != 0;
98 93 }
99 94  
100   -int hcreate(size_t nel)
101   -{
102   - return hcreate_r(nel, &htab);
103   -}
104   -
105 95 /*
106 96 * Before using the hash table we must allocate memory for it.
107 97 * Test for an existing table are done. We allocate one element
... ... @@ -110,6 +100,7 @@
110 100 * The contents of the table is zeroed, especially the field used
111 101 * becomes zero.
112 102 */
  103 +
113 104 int hcreate_r(size_t nel, struct hsearch_data *htab)
114 105 {
115 106 /* Test for correct arguments. */
116 107  
... ... @@ -143,15 +134,12 @@
143 134 /*
144 135 * hdestroy()
145 136 */
146   -void hdestroy(void)
147   -{
148   - hdestroy_r(&htab);
149   -}
150 137  
151 138 /*
152 139 * After using the hash table it has to be destroyed. The used memory can
153 140 * be freed and the local static variable can be marked as not used.
154 141 */
  142 +
155 143 void hdestroy_r(struct hsearch_data *htab)
156 144 {
157 145 int i;
... ... @@ -214,15 +202,6 @@
214 202 * example for functions like hdelete().
215 203 */
216 204  
217   -ENTRY *hsearch(ENTRY item, ACTION action)
218   -{
219   - ENTRY *result;
220   -
221   - (void) hsearch_r(item, action, &result, &htab);
222   -
223   - return result;
224   -}
225   -
226 205 int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval,
227 206 struct hsearch_data *htab)
228 207 {
... ... @@ -369,11 +348,6 @@
369 348 * do that.
370 349 */
371 350  
372   -int hdelete(const char *key)
373   -{
374   - return hdelete_r(key, &htab);
375   -}
376   -
377 351 int hdelete_r(const char *key, struct hsearch_data *htab)
378 352 {
379 353 ENTRY e, *ep;
... ... @@ -442,11 +416,6 @@
442 416 * bytes in the string will be '\0'-padded.
443 417 */
444 418  
445   -ssize_t hexport(const char sep, char **resp, size_t size)
446   -{
447   - return hexport_r(&htab, sep, resp, size);
448   -}
449   -
450 419 static int cmpkey(const void *p1, const void *p2)
451 420 {
452 421 ENTRY *e1 = *(ENTRY **) p1;
... ... @@ -604,11 +573,6 @@
604 573 * In theory, arbitrary separator characters can be used, but only
605 574 * '\0' and '\n' have really been tested.
606 575 */
607   -
608   -int himport(const char *env, size_t size, const char sep, int flag)
609   -{
610   - return himport_r(&htab, env, size, sep, flag);
611   -}
612 576  
613 577 int himport_r(struct hsearch_data *htab,
614 578 const char *env, size_t size, const char sep, int flag)