]> granicus.if.org Git - openssl/commitdiff
Add lh_new() inlining
authorDr. Stephen Henson <steve@openssl.org>
Thu, 24 Dec 2015 15:51:23 +0000 (15:51 +0000)
committerDr. Stephen Henson <steve@openssl.org>
Mon, 11 Jan 2016 17:50:27 +0000 (17:50 +0000)
Reviewed-by: Rich Salz <rsalz@openssl.org>
apps/openssl.c
crypto/conf/conf_api.c
crypto/engine/eng_table.c
crypto/err/err.c
crypto/mem_dbg.c
crypto/objects/o_names.c
crypto/objects/obj_dat.c
include/openssl/lhash.h
include/openssl/safestack.h
ssl/ssl_lib.c
util/mkstack.pl

index 539de761f0fe061ebae6ee55e841d959ae27b6e3..6bd14ffce89001df8673cc599c1308baa9e25d12 100644 (file)
@@ -700,15 +700,11 @@ static int function_cmp(const FUNCTION * a, const FUNCTION * b)
     return strncmp(a->name, b->name, 8);
 }
 
-static IMPLEMENT_LHASH_COMP_FN(function, FUNCTION)
-
 static unsigned long function_hash(const FUNCTION * a)
 {
     return lh_strhash(a->name);
 }
 
-static IMPLEMENT_LHASH_HASH_FN(function, FUNCTION)
-
 static int SortFnByName(const void *_f1, const void *_f2)
 {
     const FUNCTION *f1 = _f1;
@@ -860,7 +856,7 @@ static LHASH_OF(FUNCTION) *prog_init(void)
     for (i = 0, f = functions; f->name != NULL; ++f, ++i) ;
     qsort(functions, i, sizeof(*functions), SortFnByName);
 
-    if ((ret = lh_FUNCTION_new()) == NULL)
+    if ((ret = lh_FUNCTION_new(function_hash, function_cmp)) == NULL)
         return (NULL);
 
     for (f = functions; f->name != NULL; f++)
index 3421ee3d00e8d0f592cf00fc12452d33053ed7a4..408e49725c5bcc14d3ad4554459d11abb2e1213f 100644 (file)
@@ -162,8 +162,6 @@ static unsigned long conf_value_hash(const CONF_VALUE *v)
     return (lh_strhash(v->section) << 2) ^ lh_strhash(v->name);
 }
 
-static IMPLEMENT_LHASH_HASH_FN(conf_value, CONF_VALUE)
-
 static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b)
 {
     int i;
@@ -183,17 +181,16 @@ static int conf_value_cmp(const CONF_VALUE *a, const CONF_VALUE *b)
         return ((a->name == NULL) ? -1 : 1);
 }
 
-static IMPLEMENT_LHASH_COMP_FN(conf_value, CONF_VALUE)
-
 int _CONF_new_data(CONF *conf)
 {
     if (conf == NULL) {
         return 0;
     }
-    if (conf->data == NULL)
-        if ((conf->data = lh_CONF_VALUE_new()) == NULL) {
+    if (conf->data == NULL) {
+        conf->data = lh_CONF_VALUE_new(conf_value_hash, conf_value_cmp);
+        if (conf->data == NULL)
             return 0;
-        }
+    }
     return 1;
 }
 
index 73e72fe3d341cec88e33487e92a403a4e89443b2..220d632bda8f075dd95e130b068800a373fa23f5 100644 (file)
@@ -106,9 +106,6 @@ static int engine_pile_cmp(const ENGINE_PILE *a, const ENGINE_PILE *b)
     return a->nid - b->nid;
 }
 
-static IMPLEMENT_LHASH_HASH_FN(engine_pile, ENGINE_PILE)
-static IMPLEMENT_LHASH_COMP_FN(engine_pile, ENGINE_PILE)
-
 static int int_table_check(ENGINE_TABLE **t, int create)
 {
     LHASH_OF(ENGINE_PILE) *lh;
@@ -117,7 +114,7 @@ static int int_table_check(ENGINE_TABLE **t, int create)
         return 1;
     if (!create)
         return 0;
-    if ((lh = lh_ENGINE_PILE_new()) == NULL)
+    if ((lh = lh_ENGINE_PILE_new(engine_pile_hash, engine_pile_cmp)) == NULL)
         return 0;
     *t = (ENGINE_TABLE *)lh;
     return 1;
index 5ad5487b8f79bbf4573f0837c0b99caa8baf2aaa..c78e810cdfaecd8b681c813f148ae687a23a1b73 100644 (file)
@@ -240,11 +240,6 @@ static LHASH_OF(ERR_STATE) *int_thread_hash = NULL;
 static int int_thread_hash_references = 0;
 static int int_err_library_number = ERR_LIB_USER;
 
-/*
- * These are the callbacks provided to "lh_new()" when creating the LHASH
- * tables internal to the "err_defaults" implementation.
- */
-
 static unsigned long get_error_values(int inc, int top, const char **file,
                                       int *line, const char **data,
                                       int *flags);
@@ -258,16 +253,12 @@ static unsigned long err_string_data_hash(const ERR_STRING_DATA *a)
     return (ret ^ ret % 19 * 13);
 }
 
-static IMPLEMENT_LHASH_HASH_FN(err_string_data, ERR_STRING_DATA)
-
 static int err_string_data_cmp(const ERR_STRING_DATA *a,
                                const ERR_STRING_DATA *b)
 {
     return (int)(a->error - b->error);
 }
 
-static IMPLEMENT_LHASH_COMP_FN(err_string_data, ERR_STRING_DATA)
-
 static LHASH_OF(ERR_STRING_DATA) *get_hash(int create, int lockit)
 {
     LHASH_OF(ERR_STRING_DATA) *ret = NULL;
@@ -275,7 +266,8 @@ static LHASH_OF(ERR_STRING_DATA) *get_hash(int create, int lockit)
     if (lockit)
         CRYPTO_w_lock(CRYPTO_LOCK_ERR);
     if (!int_error_hash && create) {
-        int_error_hash = lh_ERR_STRING_DATA_new();
+        int_error_hash = lh_ERR_STRING_DATA_new(err_string_data_hash,
+                                                err_string_data_cmp);
     }
     if (int_error_hash != NULL)
         ret = int_error_hash;
@@ -304,15 +296,11 @@ static unsigned long err_state_hash(const ERR_STATE *a)
     return CRYPTO_THREADID_hash(&a->tid) * 13;
 }
 
-static IMPLEMENT_LHASH_HASH_FN(err_state, ERR_STATE)
-
 static int err_state_cmp(const ERR_STATE *a, const ERR_STATE *b)
 {
     return CRYPTO_THREADID_cmp(&a->tid, &b->tid);
 }
 
-static IMPLEMENT_LHASH_COMP_FN(err_state, ERR_STATE)
-
 static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit)
 {
     LHASH_OF(ERR_STATE) *ret = NULL;
@@ -320,7 +308,7 @@ static LHASH_OF(ERR_STATE) *int_thread_get(int create, int lockit)
     if (lockit)
         CRYPTO_w_lock(CRYPTO_LOCK_ERR);
     if (!int_thread_hash && create) {
-        int_thread_hash = lh_ERR_STATE_new();
+        int_thread_hash = lh_ERR_STATE_new(err_state_hash, err_state_cmp);
     }
     if (int_thread_hash != NULL) {
         int_thread_hash_references++;
index 36ce5f4eb41c6d764de2dc21b92e00c04ddfe151..2bdfbffba27e152e69b91c3dfc50dd497408893d 100644 (file)
@@ -306,8 +306,6 @@ static int mem_cmp(const MEM *a, const MEM *b)
 #endif
 }
 
-static IMPLEMENT_LHASH_COMP_FN(mem, MEM)
-
 static unsigned long mem_hash(const MEM *a)
 {
     size_t ret;
@@ -318,17 +316,11 @@ static unsigned long mem_hash(const MEM *a)
     return (ret);
 }
 
-static IMPLEMENT_LHASH_HASH_FN(mem, MEM)
-
-/* static int app_info_cmp(APP_INFO *a, APP_INFO *b) */
-static int app_info_cmp(const void *a_void, const void *b_void)
+static int app_info_cmp(const APP_INFO *a, const APP_INFO *b)
 {
-    return CRYPTO_THREADID_cmp(&((const APP_INFO *)a_void)->threadid,
-                               &((const APP_INFO *)b_void)->threadid);
+    return CRYPTO_THREADID_cmp(&a->threadid, &b->threadid);
 }
 
-static IMPLEMENT_LHASH_COMP_FN(app_info, APP_INFO)
-
 static unsigned long app_info_hash(const APP_INFO *a)
 {
     unsigned long ret;
@@ -339,8 +331,6 @@ static unsigned long app_info_hash(const APP_INFO *a)
     return (ret);
 }
 
-static IMPLEMENT_LHASH_HASH_FN(app_info, APP_INFO)
-
 static APP_INFO *pop_info(void)
 {
     APP_INFO tmp;
@@ -377,7 +367,7 @@ int CRYPTO_mem_debug_push(const char *info, const char *file, int line)
         if ((ami = OPENSSL_malloc(sizeof(*ami))) == NULL)
             goto err;
         if (amih == NULL) {
-            if ((amih = lh_APP_INFO_new()) == NULL) {
+            if ((amih = lh_APP_INFO_new(app_info_hash, app_info_cmp)) == NULL) {
                 OPENSSL_free(ami);
                 goto err;
             }
@@ -435,7 +425,7 @@ void CRYPTO_mem_debug_malloc(void *addr, size_t num, int before_p,
                 return;
             }
             if (mh == NULL) {
-                if ((mh = lh_MEM_new()) == NULL) {
+                if ((mh = lh_MEM_new(mem_hash, mem_cmp)) == NULL) {
                     OPENSSL_free(addr);
                     OPENSSL_free(m);
                     addr = NULL;
index df6240bfd00cb006a8be305e60dc17ba8e792705..f7216f210e70105923701b189ef09f6e3144d1d1 100644 (file)
@@ -42,20 +42,15 @@ static STACK_OF(NAME_FUNCS) *name_funcs_stack;
  * casting without the need for macro-generated wrapper functions.
  */
 
-/* static unsigned long obj_name_hash(OBJ_NAME *a); */
-static unsigned long obj_name_hash(const void *a_void);
-/* static int obj_name_cmp(OBJ_NAME *a,OBJ_NAME *b); */
-static int obj_name_cmp(const void *a_void, const void *b_void);
-
-static IMPLEMENT_LHASH_HASH_FN(obj_name, OBJ_NAME)
-static IMPLEMENT_LHASH_COMP_FN(obj_name, OBJ_NAME)
+static unsigned long obj_name_hash(const OBJ_NAME *a);
+static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b);
 
 int OBJ_NAME_init(void)
 {
     if (names_lh != NULL)
         return (1);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
-    names_lh = lh_OBJ_NAME_new();
+    names_lh = lh_OBJ_NAME_new(obj_name_hash, obj_name_cmp);
     CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
     return (names_lh != NULL);
 }
@@ -103,12 +98,9 @@ int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
     return (ret);
 }
 
-/* static int obj_name_cmp(OBJ_NAME *a, OBJ_NAME *b) */
-static int obj_name_cmp(const void *a_void, const void *b_void)
+static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b)
 {
     int ret;
-    const OBJ_NAME *a = (const OBJ_NAME *)a_void;
-    const OBJ_NAME *b = (const OBJ_NAME *)b_void;
 
     ret = a->type - b->type;
     if (ret == 0) {
@@ -122,11 +114,9 @@ static int obj_name_cmp(const void *a_void, const void *b_void)
     return (ret);
 }
 
-/* static unsigned long obj_name_hash(OBJ_NAME *a) */
-static unsigned long obj_name_hash(const void *a_void)
+static unsigned long obj_name_hash(const OBJ_NAME *a)
 {
     unsigned long ret;
-    const OBJ_NAME *a = (const OBJ_NAME *)a_void;
 
     if ((name_funcs_stack != NULL)
         && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) {
index 51a44a285f2766beba5f724b1a507c852bb61cd0..cbd6e346c188de1ed856f127e1ef8c7259cdecfb 100644 (file)
@@ -134,8 +134,6 @@ static unsigned long added_obj_hash(const ADDED_OBJ *ca)
     return (ret);
 }
 
-static IMPLEMENT_LHASH_HASH_FN(added_obj, ADDED_OBJ)
-
 static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
 {
     ASN1_OBJECT *a, *b;
@@ -174,13 +172,11 @@ static int added_obj_cmp(const ADDED_OBJ *ca, const ADDED_OBJ *cb)
     }
 }
 
-static IMPLEMENT_LHASH_COMP_FN(added_obj, ADDED_OBJ)
-
 static int init_added(void)
 {
     if (added != NULL)
         return (1);
-    added = lh_ADDED_OBJ_new();
+    added = lh_ADDED_OBJ_new(added_obj_hash, added_obj_cmp);
     return (added != NULL);
 }
 
index d5097cddd61a57497f704c6e6f1c73b9ea0cff49..057c831dd834145283c754f3931515929868971a 100644 (file)
@@ -195,6 +195,13 @@ void lh_node_usage_stats_bio(const _LHASH *lh, BIO *out);
 
 # define DECLARE_LHASH_OF(type) \
     LHASH_OF(type) { int dummy; }; \
+    static inline LHASH_OF(type) * \
+        lh_##type##_new(unsigned long (*hfn)(const type *), \
+                        int (*cfn)(const type *, const type *)) \
+    { \
+        return (LHASH_OF(type) *) \
+            lh_new((LHASH_HASH_FN_TYPE) hfn, (LHASH_COMP_FN_TYPE)cfn); \
+    } \
     static inline void lh_##type##_free(LHASH_OF(type) *lh) \
     { \
         lh_free((_LHASH *)lh); \
@@ -245,8 +252,6 @@ void lh_node_usage_stats_bio(const _LHASH *lh, BIO *out);
   ((_LHASH *)CHECKED_PTR_OF(LHASH_OF(type),lh))
 
 /* Define wrapper functions. */
-# define LHM_lh_new(type, name) \
-  ((LHASH_OF(type) *)lh_new(LHASH_HASH_FN(name), LHASH_COMP_FN(name)))
 # define LHM_lh_doall(type, lh,fn) lh_doall(CHECKED_LHASH_OF(type, lh), fn)
 # define LHM_lh_doall_arg(type, lh, fn, arg_type, arg) \
   lh_doall_arg(CHECKED_LHASH_OF(type, lh), fn, CHECKED_PTR_OF(arg_type, arg))
index 5fc1a449a9c98136b06527884102a0a6f65037c1..43493fc1e0cc61f126ffbd7564d09cbba49daa3c 100644 (file)
@@ -231,62 +231,50 @@ DEFINE_SPECIAL_STACK_OF(OPENSSL_BLOCK, void)
  */
 
 
-# define lh_ADDED_OBJ_new() LHM_lh_new(ADDED_OBJ,added_obj)
 # define lh_ADDED_OBJ_doall(lh,fn) LHM_lh_doall(ADDED_OBJ,lh,fn)
 # define lh_ADDED_OBJ_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(ADDED_OBJ,lh,fn,arg_type,arg)
 
-# define lh_APP_INFO_new() LHM_lh_new(APP_INFO,app_info)
 # define lh_APP_INFO_doall(lh,fn) LHM_lh_doall(APP_INFO,lh,fn)
 # define lh_APP_INFO_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(APP_INFO,lh,fn,arg_type,arg)
 
-# define lh_CONF_VALUE_new() LHM_lh_new(CONF_VALUE,conf_value)
 # define lh_CONF_VALUE_doall(lh,fn) LHM_lh_doall(CONF_VALUE,lh,fn)
 # define lh_CONF_VALUE_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(CONF_VALUE,lh,fn,arg_type,arg)
 
-# define lh_ENGINE_PILE_new() LHM_lh_new(ENGINE_PILE,engine_pile)
 # define lh_ENGINE_PILE_doall(lh,fn) LHM_lh_doall(ENGINE_PILE,lh,fn)
 # define lh_ENGINE_PILE_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(ENGINE_PILE,lh,fn,arg_type,arg)
 
-# define lh_ERR_STATE_new() LHM_lh_new(ERR_STATE,err_state)
 # define lh_ERR_STATE_doall(lh,fn) LHM_lh_doall(ERR_STATE,lh,fn)
 # define lh_ERR_STATE_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(ERR_STATE,lh,fn,arg_type,arg)
 
-# define lh_ERR_STRING_DATA_new() LHM_lh_new(ERR_STRING_DATA,err_string_data)
 # define lh_ERR_STRING_DATA_doall(lh,fn) LHM_lh_doall(ERR_STRING_DATA,lh,fn)
 # define lh_ERR_STRING_DATA_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(ERR_STRING_DATA,lh,fn,arg_type,arg)
 
-# define lh_FUNCTION_new() LHM_lh_new(FUNCTION,function)
 # define lh_FUNCTION_doall(lh,fn) LHM_lh_doall(FUNCTION,lh,fn)
 # define lh_FUNCTION_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(FUNCTION,lh,fn,arg_type,arg)
 
-# define lh_MEM_new() LHM_lh_new(MEM,mem)
 # define lh_MEM_doall(lh,fn) LHM_lh_doall(MEM,lh,fn)
 # define lh_MEM_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(MEM,lh,fn,arg_type,arg)
 
-# define lh_OBJ_NAME_new() LHM_lh_new(OBJ_NAME,obj_name)
 # define lh_OBJ_NAME_doall(lh,fn) LHM_lh_doall(OBJ_NAME,lh,fn)
 # define lh_OBJ_NAME_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(OBJ_NAME,lh,fn,arg_type,arg)
 
-# define lh_OPENSSL_CSTRING_new() LHM_lh_new(OPENSSL_CSTRING,openssl_cstring)
 # define lh_OPENSSL_CSTRING_doall(lh,fn) LHM_lh_doall(OPENSSL_CSTRING,lh,fn)
 # define lh_OPENSSL_CSTRING_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(OPENSSL_CSTRING,lh,fn,arg_type,arg)
 
-# define lh_OPENSSL_STRING_new() LHM_lh_new(OPENSSL_STRING,openssl_string)
 # define lh_OPENSSL_STRING_doall(lh,fn) LHM_lh_doall(OPENSSL_STRING,lh,fn)
 # define lh_OPENSSL_STRING_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(OPENSSL_STRING,lh,fn,arg_type,arg)
 
-# define lh_SSL_SESSION_new() LHM_lh_new(SSL_SESSION,ssl_session)
 # define lh_SSL_SESSION_doall(lh,fn) LHM_lh_doall(SSL_SESSION,lh,fn)
 # define lh_SSL_SESSION_doall_arg(lh,fn,arg_type,arg) \
   LHM_lh_doall_arg(SSL_SESSION,lh,fn,arg_type,arg)
index 1666cd28801723371a4708bfe6bd758e6bd8474f..f3eb5b043ff67ffa34435c80ca1452a6895baf5d 100644 (file)
@@ -2228,8 +2228,6 @@ static int ssl_session_cmp(const SSL_SESSION *a, const SSL_SESSION *b)
  * variable. The reason is that the functions aren't static, they're exposed
  * via ssl.h.
  */
-static IMPLEMENT_LHASH_HASH_FN(ssl_session, SSL_SESSION)
-static IMPLEMENT_LHASH_COMP_FN(ssl_session, SSL_SESSION)
 
 SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)
 {
@@ -2266,7 +2264,7 @@ SSL_CTX *SSL_CTX_new(const SSL_METHOD *meth)
     if ((ret->cert = ssl_cert_new()) == NULL)
         goto err;
 
-    ret->sessions = lh_SSL_SESSION_new();
+    ret->sessions = lh_SSL_SESSION_new(ssl_session_hash, ssl_session_cmp);
     if (ret->sessions == NULL)
         goto err;
     ret->cert_store = X509_STORE_new();
index 5ddd3bdf8309ab92f8989c8ae817236e9dc99c23..e188840595a3d371fc38caa93615441b0302e502 100755 (executable)
@@ -275,7 +275,6 @@ foreach $type_thing (sort @lhashlst) {
     my $lc_tt = lc $type_thing;
     $new_stackfile .= <<EOF;
 
-# define lh_${type_thing}_new() LHM_lh_new(${type_thing},${lc_tt})
 # define lh_${type_thing}_doall(lh,fn) LHM_lh_doall(${type_thing},lh,fn)
 # define lh_${type_thing}_doall_arg(lh,fn,arg_type,arg) \\
   LHM_lh_doall_arg(${type_thing},lh,fn,arg_type,arg)