- {
- if (names_lh != NULL) return(1);
- MemCheck_off();
- names_lh=lh_OBJ_NAME_new();
- MemCheck_on();
- return(names_lh != NULL);
- }
-
-int OBJ_NAME_new_index(unsigned long (*hash_func)(const char *),
- int (*cmp_func)(const char *, const char *),
- void (*free_func)(const char *, int, const char *))
- {
- int ret;
- int i;
- NAME_FUNCS *name_funcs;
-
- if (name_funcs_stack == NULL)
- {
- MemCheck_off();
- name_funcs_stack=sk_NAME_FUNCS_new_null();
- MemCheck_on();
- }
- if (name_funcs_stack == NULL)
- {
- /* ERROR */
- return(0);
- }
- ret=names_type_num;
- names_type_num++;
- for (i=sk_NAME_FUNCS_num(name_funcs_stack); i<names_type_num; i++)
- {
- MemCheck_off();
- name_funcs = OPENSSL_malloc(sizeof(NAME_FUNCS));
- MemCheck_on();
- if (!name_funcs)
- {
- OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX,ERR_R_MALLOC_FAILURE);
- return(0);
- }
- name_funcs->hash_func = lh_strhash;
- name_funcs->cmp_func = OPENSSL_strcmp;
- name_funcs->free_func = 0; /* NULL is often declared to
- * ((void *)0), which according
- * to Compaq C is not really
- * compatible with a function
- * pointer. -- Richard Levitte*/
- MemCheck_off();
- sk_NAME_FUNCS_push(name_funcs_stack,name_funcs);
- MemCheck_on();
- }
- name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
- if (hash_func != NULL)
- name_funcs->hash_func = hash_func;
- if (cmp_func != NULL)
- name_funcs->cmp_func = cmp_func;
- if (free_func != NULL)
- name_funcs->free_func = free_func;
- 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)
- {
- 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)
- {
- if ((name_funcs_stack != NULL)
- && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type))
- {
- ret=sk_NAME_FUNCS_value(name_funcs_stack,
- a->type)->cmp_func(a->name,b->name);
- }
- else
- ret=strcmp(a->name,b->name);
- }
- return(ret);
- }
-
-/* static unsigned long obj_name_hash(OBJ_NAME *a) */
-static unsigned long obj_name_hash(const void *a_void)
- {
- 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))
- {
- ret=sk_NAME_FUNCS_value(name_funcs_stack,
- a->type)->hash_func(a->name);
- }
- else
- {
- ret=lh_strhash(a->name);
- }
- ret^=a->type;
- return(ret);
- }
+{
+ if (names_lh != NULL)
+ return (1);
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
+ names_lh = lh_OBJ_NAME_new(obj_name_hash, obj_name_cmp);
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
+ return (names_lh != NULL);
+}
+
+int OBJ_NAME_new_index(unsigned long (*hash_func) (const char *),
+ int (*cmp_func) (const char *, const char *),
+ void (*free_func) (const char *, int, const char *))
+{
+ int ret, i, push;
+ NAME_FUNCS *name_funcs;
+
+ if (name_funcs_stack == NULL) {
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
+ name_funcs_stack = sk_NAME_FUNCS_new_null();
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
+ }
+ if (name_funcs_stack == NULL) {
+ /* ERROR */
+ return (0);
+ }
+ ret = names_type_num;
+ names_type_num++;
+ for (i = sk_NAME_FUNCS_num(name_funcs_stack); i < names_type_num; i++) {
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
+ name_funcs = OPENSSL_zalloc(sizeof(*name_funcs));
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
+ if (name_funcs == NULL) {
+ OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
+ return (0);
+ }
+ name_funcs->hash_func = OPENSSL_LH_strhash;
+ name_funcs->cmp_func = obj_strcmp;
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_DISABLE);
+
+ push = sk_NAME_FUNCS_push(name_funcs_stack, name_funcs);
+ CRYPTO_mem_ctrl(CRYPTO_MEM_CHECK_ENABLE);
+
+ if (!push) {
+ OBJerr(OBJ_F_OBJ_NAME_NEW_INDEX, ERR_R_MALLOC_FAILURE);
+ OPENSSL_free(name_funcs);
+ return 0;
+ }
+ }
+ name_funcs = sk_NAME_FUNCS_value(name_funcs_stack, ret);
+ if (hash_func != NULL)
+ name_funcs->hash_func = hash_func;
+ if (cmp_func != NULL)
+ name_funcs->cmp_func = cmp_func;
+ if (free_func != NULL)
+ name_funcs->free_func = free_func;
+ return (ret);
+}
+
+static int obj_name_cmp(const OBJ_NAME *a, const OBJ_NAME *b)
+{
+ int ret;
+
+ ret = a->type - b->type;
+ if (ret == 0) {
+ if ((name_funcs_stack != NULL)
+ && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) {
+ ret = sk_NAME_FUNCS_value(name_funcs_stack,
+ a->type)->cmp_func(a->name, b->name);
+ } else
+ ret = strcmp(a->name, b->name);
+ }
+ return (ret);
+}
+
+static unsigned long obj_name_hash(const OBJ_NAME *a)
+{
+ unsigned long ret;
+
+ if ((name_funcs_stack != NULL)
+ && (sk_NAME_FUNCS_num(name_funcs_stack) > a->type)) {
+ ret =
+ sk_NAME_FUNCS_value(name_funcs_stack,
+ a->type)->hash_func(a->name);
+ } else {
+ ret = OPENSSL_LH_strhash(a->name);
+ }
+ ret ^= a->type;
+ return (ret);
+}