diff options
author | Geoff Thorpe <geoff@openssl.org> | 2001-01-09 00:02:09 +0000 |
---|---|---|
committer | Geoff Thorpe <geoff@openssl.org> | 2001-01-09 00:02:09 +0000 |
commit | 18602745de52e5869f3865245c3c72986831dae2 (patch) | |
tree | ca4bb29660efd441b1d3498ec670d1fe9191a5a3 /crypto/lhash/lhash.c | |
parent | ad2e032049d8e9460372e273eddb192c300b46dc (diff) |
This adds macros to implement (and/or declare) type-safe wrapper functions
around the callbacks required in the LHASH code for the "doall" functions.
Also - fix the evil function pointer casting in the two lh_doall functions
by deferring to a static utility function. Previously lh_doall() was
invoking lh_doall_arg() by casting the callback to the 2-parameter
prototype and passing in a NULL argument. This appears to have been working
thus far but it's not a hot idea. If the extra level of indirection becomes
a performance hit, we can just provide two virtually identical
implementations for each variant later on.
Diffstat (limited to 'crypto/lhash/lhash.c')
-rw-r--r-- | crypto/lhash/lhash.c | 30 |
1 files changed, 16 insertions, 14 deletions
diff --git a/crypto/lhash/lhash.c b/crypto/lhash/lhash.c index 874647af6b..9d815f0ca0 100644 --- a/crypto/lhash/lhash.c +++ b/crypto/lhash/lhash.c @@ -267,19 +267,8 @@ void *lh_retrieve(LHASH *lh, const void *data) return((void *)ret); } -void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func) - { - /* 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, LHASH_DOALL_ARG_FN_TYPE func, const void *arg) +static void doall_util_fn(LHASH *lh, int use_arg, LHASH_DOALL_FN_TYPE func, + LHASH_DOALL_ARG_FN_TYPE func_arg, const void *arg) { int i; LHASH_NODE *a,*n; @@ -294,12 +283,25 @@ void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, const void *arg) /* 28/05/91 - eay - n added so items can be deleted * via lh_doall */ n=a->next; - func(a->data,arg); + if(use_arg) + func_arg(a->data,arg); + else + func(a->data); a=n; } } } +void lh_doall(LHASH *lh, LHASH_DOALL_FN_TYPE func) + { + doall_util_fn(lh, 0, func, (LHASH_DOALL_ARG_FN_TYPE)NULL, NULL); + } + +void lh_doall_arg(LHASH *lh, LHASH_DOALL_ARG_FN_TYPE func, const void *arg) + { + doall_util_fn(lh, 1, (LHASH_DOALL_FN_TYPE)NULL, func, arg); + } + static void expand(LHASH *lh) { LHASH_NODE **n,**n1,**n2,*np; |