Commit 2bcb4836 authored by Hallvard Furuseth's avatar Hallvard Furuseth
Browse files

Remove casts of AVL function pointers.

parent ff2a3201
......@@ -18,6 +18,7 @@
static void ravl_print LDAP_P(( Avlnode *root, int depth ));
static void myprint LDAP_P(( Avlnode *root ));
static int avl_strcmp LDAP_P(( const void *s, const void *t ));
int
main( int argc, char **argv )
......@@ -54,7 +55,7 @@ main( int argc, char **argv )
if ( fgets( name, sizeof( name ), stdin ) == NULL )
exit( EXIT_SUCCESS );
name[ strlen( name ) - 1 ] = '\0';
if ( (p = (char *) avl_find( tree, name, (AVL_CMP) strcmp ))
if ( (p = (char *) avl_find( tree, name, avl_strcmp ))
== NULL )
printf( "Not found.\n\n" );
else
......@@ -65,7 +66,7 @@ main( int argc, char **argv )
if ( fgets( name, sizeof( name ), stdin ) == NULL )
exit( EXIT_SUCCESS );
name[ strlen( name ) - 1 ] = '\0';
if ( avl_insert( &tree, strdup( name ), (AVL_CMP) strcmp,
if ( avl_insert( &tree, strdup( name ), avl_strcmp,
avl_dup_error ) != 0 )
printf( "\nNot inserted!\n" );
break;
......@@ -74,7 +75,7 @@ main( int argc, char **argv )
if ( fgets( name, sizeof( name ), stdin ) == NULL )
exit( EXIT_SUCCESS );
name[ strlen( name ) - 1 ] = '\0';
if ( avl_delete( &tree, name, (AVL_CMP) strcmp ) == NULL )
if ( avl_delete( &tree, name, avl_strcmp ) == NULL )
printf( "\nNot found!\n" );
break;
case 'q': /* quit */
......@@ -119,3 +120,8 @@ static void myprint( Avlnode *root )
printf( "********\n" );
}
static int avl_strcmp( const void *s, const void *t )
{
return strcmp( s, t );
}
......@@ -173,9 +173,10 @@ rewrite_var_set(
*/
static void
rewrite_var_free(
struct rewrite_var *var
void *v_var
)
{
struct rewrite_var *var = v_var;
assert( var != NULL );
assert( var->lv_name != NULL );
......@@ -193,7 +194,7 @@ rewrite_var_delete(
Avlnode *tree
)
{
avl_free( tree, ( AVL_FREE )rewrite_var_free );
avl_free( tree, rewrite_var_free );
return REWRITE_SUCCESS;
}
......@@ -53,10 +53,12 @@ static AttributeType *attr_list = NULL;
static int
attr_index_cmp(
struct aindexrec *air1,
struct aindexrec *air2
const void *v_air1,
const void *v_air2
)
{
const struct aindexrec *air1 = v_air1;
const struct aindexrec *air2 = v_air2;
int i = air1->air_name.bv_len - air2->air_name.bv_len;
if (i)
return i;
......@@ -65,10 +67,12 @@ attr_index_cmp(
static int
attr_index_name_cmp(
struct berval *type,
struct aindexrec *air
const void *v_type,
const void *v_air
)
{
const struct berval *type = v_type;
const struct aindexrec *air = v_air;
int i = type->bv_len - air->air_name.bv_len;
if (i)
return i;
......@@ -96,8 +100,7 @@ at_bvfind(
{
struct aindexrec *air;
air = (struct aindexrec *) avl_find( attr_index, name,
(AVL_CMP) attr_index_name_cmp );
air = avl_find( attr_index, name, attr_index_name_cmp );
return air != NULL ? air->air_at : NULL;
}
......@@ -267,8 +270,7 @@ at_insert(
air->air_name.bv_len = strlen(sat->sat_oid);
air->air_at = sat;
if ( avl_insert( &attr_index, (caddr_t) air,
(AVL_CMP) attr_index_cmp,
(AVL_DUP) avl_dup_error ) ) {
attr_index_cmp, avl_dup_error ) ) {
*err = sat->sat_oid;
ldap_memfree(air);
return SLAP_SCHERR_ATTR_DUP;
......@@ -285,8 +287,7 @@ at_insert(
air->air_name.bv_len = strlen(*names);
air->air_at = sat;
if ( avl_insert( &attr_index, (caddr_t) air,
(AVL_CMP) attr_index_cmp,
(AVL_DUP) avl_dup_error ) ) {
attr_index_cmp, avl_dup_error ) ) {
*err = *names;
ldap_memfree(air);
return SLAP_SCHERR_ATTR_DUP;
......@@ -567,9 +568,9 @@ at_add(
#ifdef LDAP_DEBUG
static int
at_index_printnode( struct aindexrec *air )
at_index_printnode( void *v_air, void *ignore )
{
struct aindexrec *air = v_air;
printf("%s = %s\n",
air->air_name.bv_val,
ldap_attributetype2str(&air->air_at->sat_atype) );
......@@ -580,8 +581,7 @@ static void
at_index_print( void )
{
printf("Printing attribute type index:\n");
(void) avl_apply( attr_index, (AVL_APPLY) at_index_printnode,
0, -1, AVL_INORDER );
(void) avl_apply( attr_index, at_index_printnode, 0, -1, AVL_INORDER );
}
#endif
......
......@@ -23,19 +23,22 @@ typedef struct bdb_attrinfo {
static int
ainfo_type_cmp(
AttributeDescription *desc,
AttrInfo *a
const void *v_desc,
const void *v_a
)
{
const AttributeDescription *desc = v_desc;
const AttrInfo *a = v_a;
return desc - a->ai_desc;
}
static int
ainfo_cmp(
AttrInfo *a,
AttrInfo *b
const void *v_a,
const void *v_b
)
{
const AttrInfo *a = v_a, *b = v_b;
return a->ai_desc - b->ai_desc;
}
......@@ -47,8 +50,7 @@ bdb_attr_mask(
{
AttrInfo *a;
a = (AttrInfo *) avl_find( bdb->bi_attrs, desc,
(AVL_CMP) ainfo_type_cmp );
a = (AttrInfo *) avl_find( bdb->bi_attrs, desc, ainfo_type_cmp );
*indexmask = a != NULL ? a->ai_indexmask : 0;
}
......@@ -194,7 +196,7 @@ bdb_attr_index_config(
a->ai_indexmask = mask;
rc = avl_insert( &bdb->bi_attrs, (caddr_t) a,
(AVL_CMP) ainfo_cmp, (AVL_DUP) avl_dup_error );
ainfo_cmp, avl_dup_error );
if( rc ) {
fprintf( stderr, "%s: line %d: duplicate index definition "
......
......@@ -491,7 +491,7 @@ bdb_cache_add_entry_rw(
}
if ( avl_insert( &cache->c_dntree, (caddr_t) e,
(AVL_CMP) entry_dn_cmp, avl_dup_error ) != 0 )
entry_dn_cmp, avl_dup_error ) != 0 )
{
/* free cache write lock */
ldap_pvt_thread_rdwr_wunlock( &cache->c_rwlock );
......@@ -513,7 +513,7 @@ bdb_cache_add_entry_rw(
/* id tree */
if ( avl_insert( &cache->c_idtree, (caddr_t) e,
(AVL_CMP) entry_id_cmp, avl_dup_error ) != 0 )
entry_id_cmp, avl_dup_error ) != 0 )
{
#ifdef NEW_LOGGING
LDAP_LOG( CACHE, DETAIL1,
......@@ -527,7 +527,7 @@ bdb_cache_add_entry_rw(
/* delete from dn tree inserted above */
if ( avl_delete( &cache->c_dntree, (caddr_t) e,
(AVL_CMP) entry_dn_cmp ) == NULL )
entry_dn_cmp ) == NULL )
{
#ifdef NEW_LOGGING
LDAP_LOG( CACHE, INFO,
......@@ -554,7 +554,7 @@ bdb_cache_add_entry_rw(
case DB_LOCK_NOTGRANTED :
/* undo avl changes immediately */
if ( avl_delete( &cache->c_idtree, (caddr_t) e,
(AVL_CMP) entry_id_cmp ) == NULL ) {
entry_id_cmp ) == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG( CACHE, INFO,
"bdb_cache_add_entry: can't delete (%s) from cache.\n",
......@@ -564,7 +564,7 @@ bdb_cache_add_entry_rw(
#endif
}
if ( avl_delete( &cache->c_dntree, (caddr_t) e,
(AVL_CMP) entry_dn_cmp ) == NULL ) {
entry_dn_cmp ) == NULL ) {
#ifdef NEW_LOGGING
LDAP_LOG( CACHE, INFO,
"bdb_cache_add_entry: can't delete (%s) from cache.\n",
......@@ -653,7 +653,7 @@ bdb_cache_update_entry(
assert( e->e_private );
if ( avl_insert( &cache->c_dntree, (caddr_t) e,
(AVL_CMP) entry_dn_cmp, avl_dup_error ) != 0 )
entry_dn_cmp, avl_dup_error ) != 0 )
{
#ifdef NEW_LOGGING
LDAP_LOG( CACHE, DETAIL1,
......@@ -672,7 +672,7 @@ bdb_cache_update_entry(
/* id tree */
if ( avl_insert( &cache->c_idtree, (caddr_t) e,
(AVL_CMP) entry_id_cmp, avl_dup_error ) != 0 )
entry_id_cmp, avl_dup_error ) != 0 )
{
#ifdef NEW_LOGGING
LDAP_LOG( CACHE, DETAIL1,
......@@ -686,7 +686,7 @@ bdb_cache_update_entry(
/* delete from dn tree inserted above */
if ( avl_delete( &cache->c_dntree, (caddr_t) e,
(AVL_CMP) entry_dn_cmp ) == NULL )
entry_dn_cmp ) == NULL )
{
#ifdef NEW_LOGGING
LDAP_LOG( CACHE, INFO,
......@@ -774,7 +774,7 @@ try_again:
ldap_pvt_thread_rdwr_rlock( &cache->c_rwlock );
if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
(AVL_CMP) entry_dn_cmp )) != NULL )
entry_dn_cmp )) != NULL )
{
int state;
count++;
......@@ -874,7 +874,7 @@ try_again:
ldap_pvt_thread_rdwr_rlock( &cache->c_rwlock );
if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
(AVL_CMP) entry_id_cmp )) != NULL )
entry_id_cmp )) != NULL )
{
int state;
ID ep_id;
......@@ -1029,15 +1029,13 @@ bdb_cache_delete_entry_internal(
int rc = 0; /* return code */
/* dn tree */
if ( avl_delete( &cache->c_dntree, (caddr_t) e, (AVL_CMP) entry_dn_cmp )
== NULL )
if ( avl_delete( &cache->c_dntree, (caddr_t) e, entry_dn_cmp ) == NULL )
{
rc = -1;
}
/* id tree */
if ( avl_delete( &cache->c_idtree, (caddr_t) e, (AVL_CMP) entry_id_cmp )
== NULL )
if ( avl_delete( &cache->c_idtree, (caddr_t) e, entry_id_cmp ) == NULL )
{
rc = -1;
}
......
......@@ -622,28 +622,32 @@ node_find_cmp(
static int
node_frdn_cmp(
struct berval *nrdn,
idNode *n
const void *v_nrdn,
const void *v_n
)
{
const struct berval *nrdn = v_nrdn;
const idNode *n = v_n;
return ber_bvcmp(nrdn, &n->i_rdn->nrdn);
}
static int
node_add_cmp(
idNode *a,
idNode *b
const void *v_a,
const void *v_b
)
{
const idNode *a = v_a, *b = v_b;
return a->i_id - b->i_id;
}
static int
node_rdn_cmp(
idNode *a,
idNode *b
const void *v_a,
const void *v_b
)
{
const idNode *a = v_a, *b = v_b;
/* should be slightly better without ordering drawbacks */
return ber_bvcmp(&a->i_rdn->nrdn, &b->i_rdn->nrdn);
}
......@@ -661,15 +665,17 @@ idNode * bdb_find_rdn_node(
Avlnode *tree
)
{
return avl_find(tree, (const void *)nrdn, (AVL_CMP)node_frdn_cmp);
return avl_find(tree, nrdn, node_frdn_cmp);
}
/* This function links a node into its parent's i_kids tree. */
int bdb_insert_kid(
idNode *a,
Avlnode *tree
static int bdb_insert_kid(
void *v_a,
void *v_tree
)
{
idNode *a = v_a;
Avlnode *tree = v_tree;
int rc;
if (a->i_rdn->parent == 0)
......@@ -679,7 +685,7 @@ int bdb_insert_kid(
return -1;
ldap_pvt_thread_rdwr_wlock(&a->i_parent->i_kids_rdwr);
rc = avl_insert( &a->i_parent->i_kids, (caddr_t) a,
(AVL_CMP)node_rdn_cmp, (AVL_DUP) avl_dup_error );
node_rdn_cmp, avl_dup_error );
ldap_pvt_thread_rdwr_wunlock(&a->i_parent->i_kids_rdwr);
return rc;
}
......@@ -701,8 +707,7 @@ idNode *bdb_add_node(
node->i_rdn->rdn.bv_val += (long)d;
node->i_rdn->nrdn.bv_val += (long)d;
ldap_pvt_thread_rdwr_init(&node->i_kids_rdwr);
avl_insert( &bdb->bi_tree, (caddr_t) node,
(AVL_CMP)node_add_cmp, (AVL_DUP) avl_dup_error );
avl_insert( &bdb->bi_tree, (caddr_t) node, node_add_cmp, avl_dup_error );
if (id == 1)
bdb->bi_troot = node;
return node;
......@@ -741,7 +746,7 @@ int bdb_build_tree(
}
cursor->c_close( cursor );
rc = avl_apply(bdb->bi_tree, (AVL_APPLY)bdb_insert_kid, bdb->bi_tree,
rc = avl_apply(bdb->bi_tree, bdb_insert_kid, bdb->bi_tree,
-1, AVL_INORDER );
return rc;
......@@ -880,8 +885,7 @@ bdb_dn2id_delete(
if (n) {
if (n->i_parent) {
ldap_pvt_thread_rdwr_wlock(&n->i_parent->i_kids_rdwr);
avl_delete(&n->i_parent->i_kids, &n->i_rdn->nrdn,
(AVL_CMP)node_frdn_cmp);
avl_delete(&n->i_parent->i_kids, &n->i_rdn->nrdn, node_frdn_cmp);
ldap_pvt_thread_rdwr_wunlock(&n->i_parent->i_kids_rdwr);
}
free(n->i_rdn);
......@@ -986,26 +990,29 @@ bdb_dn2id_children(
*/
static int
insert_one(
idNode *n,
ID *ids
void *v_n,
void *v_ids
)
{
idNode *n = v_n;
ID *ids = v_ids;
return bdb_idl_insert(ids, n->i_id);
}
static int
insert_sub(
idNode *n,
ID *ids
void *v_n,
void *v_ids
)
{
idNode *n = v_n;
ID *ids = v_ids;
int rc;
rc = bdb_idl_insert(ids, n->i_id);
if (rc == 0) {
ldap_pvt_thread_rdwr_rlock(&n->i_kids_rdwr);
rc = avl_apply(n->i_kids, (AVL_APPLY)insert_sub, ids, -1,
AVL_INORDER);
rc = avl_apply(n->i_kids, insert_sub, ids, -1, AVL_INORDER);
ldap_pvt_thread_rdwr_runlock(&n->i_kids_rdwr);
}
return rc;
......@@ -1038,11 +1045,9 @@ bdb_dn2idl(
ids[0] = 0;
ldap_pvt_thread_rdwr_rlock(&n->i_kids_rdwr);
if (prefix == DN_ONE_PREFIX) {
rc = avl_apply(n->i_kids, (AVL_APPLY)insert_one, ids, -1,
AVL_INORDER);
rc = avl_apply(n->i_kids, insert_one, ids, -1, AVL_INORDER);
} else {
rc = avl_apply(n->i_kids, (AVL_APPLY)insert_sub, ids, -1,
AVL_INORDER);
rc = avl_apply(n->i_kids, insert_sub, ids, -1, AVL_INORDER);
}
ldap_pvt_thread_rdwr_runlock(&n->i_kids_rdwr);
return rc;
......
......@@ -45,8 +45,9 @@
} while ( 0 )
static int
bdb_idl_entry_cmp( bdb_idl_cache_entry_t* idl1, bdb_idl_cache_entry_t* idl2 )
bdb_idl_entry_cmp( const void *v_idl1, const void *v_idl2 )
{
const bdb_idl_cache_entry_t *idl1 = v_idl1, *idl2 = v_idl2;
int rc;
if ((rc = idl1->db - idl2->db )) return rc;
......@@ -333,7 +334,8 @@ bdb_idl_fetch_key(
DBT2bv( key, &idl_tmp.kstr );
idl_tmp.db = db;
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp, (AVL_CMP) bdb_idl_entry_cmp );
matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
bdb_idl_entry_cmp );
if ( matched_idl_entry != NULL ) {
BDB_IDL_CPY( ids, matched_idl_entry->idl );
IDL_LRU_DELETE( bdb, matched_idl_entry );
......@@ -469,7 +471,8 @@ bdb_idl_fetch_key(
BDB_IDL_CPY( ee->idl, ids );
ber_dupbv( &ee->kstr, &idl_tmp.kstr );
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
if ( avl_insert( &bdb->bi_idl_tree, (caddr_t) ee, (AVL_CMP) bdb_idl_entry_cmp, avl_dup_error )) {
if ( avl_insert( &bdb->bi_idl_tree, (caddr_t) ee,
bdb_idl_entry_cmp, avl_dup_error )) {
free( ee->kstr.bv_val );
free( ee->idl );
free( ee );
......@@ -479,7 +482,8 @@ bdb_idl_fetch_key(
int i = 0;
while ( bdb->bi_idl_lru_tail != NULL && i < 10 ) {
ee = bdb->bi_idl_lru_tail;
avl_delete( &bdb->bi_idl_tree, (caddr_t) ee, (AVL_CMP) bdb_idl_entry_cmp );
avl_delete( &bdb->bi_idl_tree, (caddr_t) ee,
bdb_idl_entry_cmp );
IDL_LRU_DELETE( bdb, ee );
i++;
--bdb->bi_idl_cache_size;
......@@ -533,9 +537,11 @@ bdb_idl_insert_key(
DBT2bv( key, &idl_tmp.kstr );
idl_tmp.db = db;
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp, (AVL_CMP) bdb_idl_entry_cmp );
matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
bdb_idl_entry_cmp );
if ( matched_idl_entry != NULL ) {
avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry, (AVL_CMP) bdb_idl_entry_cmp );
avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry,
bdb_idl_entry_cmp );
--bdb->bi_idl_cache_size;
IDL_LRU_DELETE( bdb, matched_idl_entry );
free( matched_idl_entry->kstr.bv_val );
......@@ -743,9 +749,11 @@ bdb_idl_delete_key(
DBT2bv( key, &idl_tmp.kstr );
idl_tmp.db = db;
ldap_pvt_thread_mutex_lock( &bdb->bi_idl_tree_mutex );
matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp, (AVL_CMP) bdb_idl_entry_cmp );
matched_idl_entry = avl_find( bdb->bi_idl_tree, &idl_tmp,
bdb_idl_entry_cmp );
if ( matched_idl_entry != NULL ) {
avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry, (AVL_CMP) bdb_idl_entry_cmp );
avl_delete( &bdb->bi_idl_tree, (caddr_t) matched_idl_entry,
bdb_idl_entry_cmp );
--bdb->bi_idl_cache_size;
IDL_LRU_DELETE( bdb, matched_idl_entry );
free( matched_idl_entry->kstr.bv_val );
......
......@@ -120,7 +120,7 @@ ldap_back_map_attrs(
int remap
);
extern void mapping_free ( struct ldapmapping *mapping );
extern void mapping_free ( void *mapping );
#ifdef ENABLE_REWRITE
extern int suffix_massage_config( struct rewrite_info *info,
......
......@@ -131,9 +131,10 @@ ldap_back_db_init(
static void
conn_free(
struct ldapconn *lc
void *v_lc
)
{
struct ldapconn *lc = v_lc;
ldap_unbind( lc->ld );
if ( lc->bound_dn.bv_val ) {
ch_free( lc->bound_dn.bv_val );
......@@ -145,8 +146,9 @@ conn_free(
}
void
mapping_free ( struct ldapmapping *mapping )
mapping_free( void *v_mapping )
{
struct ldapmapping *mapping = v_mapping;
ch_free( mapping->src.bv_val );
ch_free( mapping->dst.bv_val );
ch_free( mapping );
......@@ -177,7 +179,7 @@ ldap_back_db_destroy(
li->bindpw = NULL;
}
if (li->conntree) {
avl_free( li->conntree, (AVL_FREE) conn_free );
avl_free( li->conntree, conn_free );
}
#ifdef ENABLE_REWRITE
if (li->rwinfo) {
......@@ -190,9 +192,9 @@ ldap_back_db_destroy(
#endif /* !ENABLE_REWRITE */
avl_free( li->oc_map.remap, NULL );
avl_free( li->oc_map.map, (AVL_FREE) mapping_free );
avl_free( li->oc_map.map, mapping_free );
avl_free( li->at_map.remap, NULL );
avl_free( li->at_map.map, (AVL_FREE) mapping_free );
avl_free( li->at_map.map, mapping_free );
ldap_pvt_thread_mutex_unlock( &li->conn_mutex );
ldap_pvt_thread_mutex_destroy( &li->conn_mutex );
......
......@@ -23,19 +23,22 @@ typedef struct ldbm_attrinfo {
static int
ainfo_type_cmp(
AttributeDescription *desc,
AttrInfo *a
const void *v_desc,
const void *v_a
)
{
const AttributeDescription *desc = v_desc;
const AttrInfo *a = v_a;
return desc - a->ai_desc;
}
static int
ainfo_cmp(
AttrInfo *a,
AttrInfo *b
const void *v_a,
const void *v_b
)
{
const AttrInfo *a = v_a, *b = v_b;
return a->ai_desc - b->ai_desc;
}
......@@ -47,8 +50,7 @@ attr_mask(
{
AttrInfo *a;
a = (AttrInfo *) avl_find( li->li_attrs, desc,
(AVL_CMP) ainfo_type_cmp );
a = avl_find( li->li_attrs, desc, ainfo_type_cmp );
*indexmask = a != NULL ? a->ai_indexmask : 0;
}
......@@ -195,7 +197,7 @@ attr_index_config(
a->ai_indexmask = mask;
rc = avl_insert( &li->li_attrs, (caddr_t) a,
(AVL_CMP) ainfo_cmp, (AVL_DUP) avl_dup_error );
ainfo_cmp, avl_dup_error );
if( rc ) {
fprintf( stderr, "%s: line %d: duplicate index definition "
......
......@@ -244,7 +244,7 @@ cache_add_entry_rw(
}