Next step in tidying up the LHASH code.
DECLARE/IMPLEMENT macros now exist to create type (and prototype) safe
wrapper functions that avoid the use of function pointer casting yet retain
type-safety for type-specific callbacks. However, most of the usage within
OpenSSL itself doesn't really require the extra function because the hash
and compare callbacks are internal functions declared only for use by the
hash table. So this change catches all those cases and reimplements the
functions using the base-level LHASH prototypes and does per-variable
casting inside those functions to convert to the appropriate item type.
The exception so far is in ssl_lib.c where the hash and compare callbacks
are not static - they're exposed in ssl.h so their prototypes should not be
changed. In this last case, the IMPLEMENT_LHASH_*** macros have been left
intact.
diff --git a/apps/openssl.c b/apps/openssl.c
index b7e50c7..14cb93e 100644
--- a/apps/openssl.c
+++ b/apps/openssl.c
@@ -73,8 +73,15 @@
#include "s_apps.h"
#include <openssl/err.h>
-static unsigned long MS_CALLBACK hash(FUNCTION *a);
-static int MS_CALLBACK cmp(FUNCTION *a,FUNCTION *b);
+/* The LHASH callbacks ("hash" & "cmp") have been replaced by functions with the
+ * base prototypes (we cast each variable inside the function to the required
+ * type of "FUNCTION*"). This removes the necessity for macro-generated wrapper
+ * functions. */
+
+/* static unsigned long MS_CALLBACK hash(FUNCTION *a); */
+static unsigned long MS_CALLBACK hash(void *a_void);
+/* static int MS_CALLBACK cmp(FUNCTION *a,FUNCTION *b); */
+static int MS_CALLBACK cmp(void *a_void,void *b_void);
static LHASH *prog_init(void );
static int do_cmd(LHASH *prog,int argc,char *argv[]);
LHASH *config=NULL;
@@ -85,9 +92,6 @@
BIO *bio_err=NULL;
#endif
-static IMPLEMENT_LHASH_HASH_FN(hash,FUNCTION *)
-static IMPLEMENT_LHASH_COMP_FN(cmp,FUNCTION *)
-
int main(int Argc, char *Argv[])
{
ARGS arg;
@@ -354,8 +358,7 @@
;
qsort(functions,i,sizeof *functions,SortFnByName);
- if ((ret=lh_new(LHASH_HASH_FN(hash),
- LHASH_COMP_FN(cmp))) == NULL)
+ if ((ret=lh_new(hash, cmp)) == NULL)
return(NULL);
for (f=functions; f->name != NULL; f++)
@@ -363,12 +366,15 @@
return(ret);
}
-static int MS_CALLBACK cmp(FUNCTION *a, FUNCTION *b)
+/* static int MS_CALLBACK cmp(FUNCTION *a, FUNCTION *b) */
+static int MS_CALLBACK cmp(void *a_void, void *b_void)
{
- return(strncmp(a->name,b->name,8));
+ return(strncmp(((FUNCTION *)a_void)->name,
+ ((FUNCTION *)b_void)->name,8));
}
-static unsigned long MS_CALLBACK hash(FUNCTION *a)
+/* static unsigned long MS_CALLBACK hash(FUNCTION *a) */
+static unsigned long MS_CALLBACK hash(void *a_void)
{
- return(lh_strhash(a->name));
+ return(lh_strhash(((FUNCTION *)a_void)->name));
}