From 2eb1573f01710832bbe60a4ece89cb301727612a Mon Sep 17 00:00:00 2001 From: Mike Frysinger Date: Wed, 8 Dec 2010 06:26:04 -0500 Subject: 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 --- lib/hashtable.c | 40 ++-------------------------------------- 1 file changed, 2 insertions(+), 38 deletions(-) (limited to 'lib') diff --git a/lib/hashtable.c b/lib/hashtable.c index 7ac3dddda6..b47f3b69b0 100644 --- a/lib/hashtable.c +++ b/lib/hashtable.c @@ -59,11 +59,6 @@ * [Knuth] The Art of Computer Programming, part 3 (6.4) */ -/* - * The non-reentrant version use a global space for storing the hash table. - */ -static struct hsearch_data htab; - /* * The reentrant version has no static variables to maintain the state. * Instead the interface of all functions is extended to take an argument @@ -97,11 +92,6 @@ static int isprime(unsigned int number) return number % div != 0; } -int hcreate(size_t nel) -{ - return hcreate_r(nel, &htab); -} - /* * Before using the hash table we must allocate memory for it. * Test for an existing table are done. We allocate one element @@ -110,6 +100,7 @@ int hcreate(size_t nel) * The contents of the table is zeroed, especially the field used * becomes zero. */ + int hcreate_r(size_t nel, struct hsearch_data *htab) { /* Test for correct arguments. */ @@ -143,15 +134,12 @@ int hcreate_r(size_t nel, struct hsearch_data *htab) /* * hdestroy() */ -void hdestroy(void) -{ - hdestroy_r(&htab); -} /* * After using the hash table it has to be destroyed. The used memory can * be freed and the local static variable can be marked as not used. */ + void hdestroy_r(struct hsearch_data *htab) { int i; @@ -214,15 +202,6 @@ void hdestroy_r(struct hsearch_data *htab) * example for functions like hdelete(). */ -ENTRY *hsearch(ENTRY item, ACTION action) -{ - ENTRY *result; - - (void) hsearch_r(item, action, &result, &htab); - - return result; -} - int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval, struct hsearch_data *htab) { @@ -369,11 +348,6 @@ int hsearch_r(ENTRY item, ACTION action, ENTRY ** retval, * do that. */ -int hdelete(const char *key) -{ - return hdelete_r(key, &htab); -} - int hdelete_r(const char *key, struct hsearch_data *htab) { ENTRY e, *ep; @@ -442,11 +416,6 @@ int hdelete_r(const char *key, struct hsearch_data *htab) * bytes in the string will be '\0'-padded. */ -ssize_t hexport(const char sep, char **resp, size_t size) -{ - return hexport_r(&htab, sep, resp, size); -} - static int cmpkey(const void *p1, const void *p2) { ENTRY *e1 = *(ENTRY **) p1; @@ -605,11 +574,6 @@ ssize_t hexport_r(struct hsearch_data *htab, const char sep, * '\0' and '\n' have really been tested. */ -int himport(const char *env, size_t size, const char sep, int flag) -{ - return himport_r(&htab, env, size, sep, flag); -} - int himport_r(struct hsearch_data *htab, const char *env, size_t size, const char sep, int flag) { -- cgit v1.2.1