aboutsummaryrefslogtreecommitdiff
path: root/crypto/lhash/lhash.c
diff options
context:
space:
mode:
authorGeoff Thorpe <geoff@openssl.org>2000-12-01 20:31:52 +0000
committerGeoff Thorpe <geoff@openssl.org>2000-12-01 20:31:52 +0000
commit385d81380cb8aa062b9d7e2c678419623c7db484 (patch)
treef866963b5b03410694d03a37d20695327a72a460 /crypto/lhash/lhash.c
parent862e973b50e56d9510cfebc220cf410d3d5e99bc (diff)
downloadopenssl-385d81380cb8aa062b9d7e2c678419623c7db484.zip
openssl-385d81380cb8aa062b9d7e2c678419623c7db484.tar.gz
openssl-385d81380cb8aa062b9d7e2c678419623c7db484.tar.bz2
First step in tidying up the LHASH code. The callback prototypes (and
casts) used in the lhash code are about as horrible and evil as they can be. For starters, the callback prototypes contain empty parameter lists. Yuck. This first change defines clearer prototypes - including "typedef"'d function pointer types to use as "hash" and "compare" callbacks, as well as the callbacks passed to the lh_doall and lh_doall_arg iteration functions. Now at least more explicit (and clear) casting is required in all of the dependant code - and that should be included in this commit. The next step will be to hunt down and obliterate some of the function pointer casting being used when it's not necessary - a particularly evil variant exists in the implementation of lh_doall.
Diffstat (limited to 'crypto/lhash/lhash.c')
-rw-r--r--crypto/lhash/lhash.c23
1 files changed, 15 insertions, 8 deletions
diff --git a/crypto/lhash/lhash.c b/crypto/lhash/lhash.c
index cdcc3b6..60699f4 100644
--- a/crypto/lhash/lhash.c
+++ b/crypto/lhash/lhash.c
@@ -111,7 +111,7 @@ static void expand(LHASH *lh);
static void contract(LHASH *lh);
static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash);
-LHASH *lh_new(unsigned long (*h)(), int (*c)())
+LHASH *lh_new(LHASH_HASH_FN_TYPE h, LHASH_COMP_FN_TYPE c)
{
LHASH *ret;
int i;
@@ -122,8 +122,8 @@ LHASH *lh_new(unsigned long (*h)(), int (*c)())
goto err1;
for (i=0; i<MIN_NODES; i++)
ret->b[i]=NULL;
- ret->comp=((c == NULL)?(int (*)())strcmp:c);
- ret->hash=((h == NULL)?(unsigned long (*)())lh_strhash:h);
+ ret->comp=((c == NULL)?(LHASH_COMP_FN_TYPE)strcmp:c);
+ ret->hash=((h == NULL)?(LHASH_HASH_FN_TYPE)lh_strhash:h);
ret->num_nodes=MIN_NODES/2;
ret->num_alloc_nodes=MIN_NODES;
ret->p=0;
@@ -267,12 +267,19 @@ void *lh_retrieve(LHASH *lh, void *data)
return(ret);
}
-void lh_doall(LHASH *lh, void (*func)())
+void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func)
{
- lh_doall_arg(lh,func,NULL);
+ /* Yikes that's bad - we're accepting a function that accepts 2
+ * parameters (albeit we have to waive type-safety here) and then
+ * forcibly calling that callback with *3* parameters leaving the 3rd
+ * NULL. Obviously this "works" otherwise it wouldn't have survived so
+ * long, but is it "good"??
+ * FIXME: Use an internal function from this and the "_arg" version that
+ * doesn't assume the ability to mutate function prototypes so badly. */
+ lh_doall_arg(lh, (LHASH_DOALL_ARG_FN_TYPE)func, NULL);
}
-void lh_doall_arg(LHASH *lh, void (*func)(), void *arg)
+void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, void *arg)
{
int i;
LHASH_NODE *a,*n;
@@ -312,7 +319,7 @@ static void expand(LHASH *lh)
#ifndef NO_HASH_COMP
hash=np->hash;
#else
- hash=(*(lh->hash))(np->data);
+ hash=lh->hash(np->data);
lh->num_hash_calls++;
#endif
if ((hash%nni) != p)
@@ -415,7 +422,7 @@ static LHASH_NODE **getrn(LHASH *lh, void *data, unsigned long *rhash)
}
#endif
lh->num_comp_calls++;
- if ((*cf)(n1->data,data) == 0)
+ if(cf(n1->data,data) == 0)
break;
ret= &(n1->next);
}