AVL_CMP, AVL_DUP, AVL_FREE, AVL_APPLY.
Apply casts as needed.
Change data pointer from caddr_t to void *.
LDAP_BEGIN_DECL
typedef struct avlnode {
- caddr_t avl_data;
+ void* avl_data;
signed char avl_bf;
struct avlnode *avl_left;
struct avlnode *avl_right;
#define avl_getone(x) ((x) == 0 ? 0 : (x)->avl_data)
#define avl_onenode(x) ((x) == 0 || ((x)->avl_left == 0 && (x)->avl_right == 0))
-/* looks like this function pointer is not used consistently */
-/* typedef int (*IFP)LDAP_P((caddr_t, caddr_t)); */
-typedef int (*IFP)();
+typedef int (*AVL_APPLY) LDAP_P((void *, void*));
+typedef int (*AVL_CMP) LDAP_P((void*, void*));
+typedef int (*AVL_DUP) LDAP_P((void*, void*));
+typedef void (*AVL_FREE) LDAP_P((void*));
LDAP_F int
-avl_free LDAP_P(( Avlnode *root, IFP dfree ));
+avl_free LDAP_P(( Avlnode *root, AVL_FREE dfree ));
LDAP_F int
-avl_insert LDAP_P((Avlnode **, caddr_t, IFP, IFP));
+avl_insert LDAP_P((Avlnode **, void*, AVL_CMP, AVL_DUP));
-LDAP_F caddr_t
-avl_delete LDAP_P((Avlnode **, caddr_t, IFP));
+LDAP_F void*
+avl_delete LDAP_P((Avlnode **, void*, AVL_CMP));
-LDAP_F caddr_t
-avl_find LDAP_P((Avlnode *, caddr_t, IFP));
+LDAP_F void*
+avl_find LDAP_P((Avlnode *, void*, AVL_CMP));
-LDAP_F caddr_t
-avl_find_lin LDAP_P((Avlnode *, caddr_t, IFP));
+LDAP_F void*
+avl_find_lin LDAP_P((Avlnode *, void*, AVL_CMP));
-LDAP_F caddr_t
+LDAP_F void*
avl_getfirst LDAP_P((Avlnode *));
#ifdef AVL_REENTRANT
/* ??? avl.c does not provide this version ??? */
-LDAP_F caddr_t
-avl_getnext LDAP_P((Avlnode *, caddr_t ));
+LDAP_F void*
+avl_getnext LDAP_P((Avlnode *, void* ));
#else
-LDAP_F caddr_t
+LDAP_F void*
avl_getnext LDAP_P((void));
#endif
LDAP_F int
-avl_dup_error LDAP_P((void));
+avl_dup_error LDAP_P((void*, void*));
LDAP_F int
-avl_dup_ok LDAP_P((void));
+avl_dup_ok LDAP_P((void*, void*));
LDAP_F int
-avl_apply LDAP_P((Avlnode *, IFP, caddr_t, int, int));
+avl_apply LDAP_P((Avlnode *, AVL_APPLY, void*, int, int));
LDAP_F int
-avl_prefixapply LDAP_P((Avlnode *, caddr_t, IFP, caddr_t, IFP, caddr_t, int));
+avl_prefixapply LDAP_P((Avlnode *, void*, AVL_CMP, void*, AVL_CMP, void*, int));
/* apply traversal types */
#define AVL_PREORDER 1
static int
ravl_insert(
Avlnode **iroot,
- caddr_t data,
+ void* data,
int *taller,
- IFP fcmp, /* comparison function */
- IFP fdup, /* function to call for duplicates */
+ AVL_CMP fcmp, /* comparison function */
+ AVL_DUP fdup, /* function to call for duplicates */
int depth
)
{
*/
int
-avl_insert( Avlnode **root, caddr_t data, IFP fcmp, IFP fdup )
+avl_insert( Avlnode **root, void* data, AVL_CMP fcmp, AVL_DUP fdup )
{
int taller;
* rebalancing.
*/
-static caddr_t
-ravl_delete( Avlnode **root, caddr_t data, IFP fcmp, int *shorter )
+static void*
+ravl_delete( Avlnode **root, void* data, AVL_CMP fcmp, int *shorter )
{
int shortersubtree = 0;
int cmp;
- caddr_t savedata;
+ void* savedata;
Avlnode *minnode, *savenode;
if ( *root == NULLAVL )
* the avl tree rooted at root.
*/
-caddr_t
-avl_delete( Avlnode **root, caddr_t data, IFP fcmp )
+void*
+avl_delete( Avlnode **root, void* data, AVL_CMP fcmp )
{
int shorter;
}
static int
-avl_inapply( Avlnode *root, IFP fn, caddr_t arg, int stopflag )
+avl_inapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
{
if ( root == 0 )
return( AVL_NOMORE );
}
static int
-avl_postapply( Avlnode *root, IFP fn, caddr_t arg, int stopflag )
+avl_postapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
{
if ( root == 0 )
return( AVL_NOMORE );
}
static int
-avl_preapply( Avlnode *root, IFP fn, caddr_t arg, int stopflag )
+avl_preapply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag )
{
if ( root == 0 )
return( AVL_NOMORE );
*/
int
-avl_apply( Avlnode *root, IFP fn, caddr_t arg, int stopflag, int type )
+avl_apply( Avlnode *root, AVL_APPLY fn, void* arg, int stopflag, int type )
{
switch ( type ) {
case AVL_INORDER:
int
avl_prefixapply(
Avlnode *root,
- caddr_t data,
- IFP fmatch,
- caddr_t marg,
- IFP fcmp,
- caddr_t carg,
+ void* data,
+ AVL_CMP fmatch,
+ void* marg,
+ AVL_CMP fcmp,
+ void* carg,
int stopflag
)
{
if ( root == 0 )
return( AVL_NOMORE );
- cmp = (*fcmp)( data, root->avl_data, carg );
+ cmp = (*fcmp)( data, root->avl_data /* , carg */);
if ( cmp == 0 ) {
if ( (*fmatch)( root->avl_data, marg ) == stopflag )
return( stopflag );
*/
int
-avl_free( Avlnode *root, IFP dfree )
+avl_free( Avlnode *root, AVL_FREE dfree )
{
int nleft, nright;
* < 0 if arg1 is less than arg2 and > 0 if arg1 is greater than arg2.
*/
-caddr_t
-avl_find( Avlnode *root, caddr_t data, IFP fcmp )
+void*
+avl_find( Avlnode *root, void* data, AVL_CMP fcmp )
{
int cmp;
* they match, non-zero otherwise.
*/
-caddr_t
-avl_find_lin( Avlnode *root, caddr_t data, IFP fcmp )
+void*
+avl_find_lin( Avlnode *root, void* data, AVL_CMP fcmp )
{
- caddr_t res;
+ void* res;
if ( root == 0 )
return( NULL );
return( avl_find_lin( root->avl_right, data, fcmp ) );
}
-static caddr_t *avl_list;
+static void* *avl_list;
static int avl_maxlist;
static int avl_nextlist;
/* ARGSUSED */
static int
-avl_buildlist( caddr_t data, int arg )
+avl_buildlist( void* data, void* arg )
{
static int slots;
- if ( avl_list == (caddr_t *) 0 ) {
- avl_list = (caddr_t *) malloc(AVL_GRABSIZE * sizeof(caddr_t));
+ if ( avl_list == (void* *) 0 ) {
+ avl_list = (void* *) malloc(AVL_GRABSIZE * sizeof(void*));
slots = AVL_GRABSIZE;
avl_maxlist = 0;
} else if ( avl_maxlist == slots ) {
slots += AVL_GRABSIZE;
- avl_list = (caddr_t *) realloc( (char *) avl_list,
- (unsigned) slots * sizeof(caddr_t));
+ avl_list = (void* *) realloc( (char *) avl_list,
+ (unsigned) slots * sizeof(void*));
}
avl_list[ avl_maxlist++ ] = data;
* different trees) cannot be active at once.
*/
-caddr_t
+void*
avl_getfirst( Avlnode *root )
{
if ( avl_list ) {
free( (char *) avl_list);
- avl_list = (caddr_t *) 0;
+ avl_list = (void* *) 0;
}
avl_maxlist = 0;
avl_nextlist = 0;
if ( root == 0 )
return( 0 );
- (void) avl_apply( root, avl_buildlist, (caddr_t) 0, -1, AVL_INORDER );
+ (void) avl_apply( root, avl_buildlist, (void*) 0, -1, AVL_INORDER );
return( avl_list[ avl_nextlist++ ] );
}
-caddr_t
+void*
avl_getnext( void )
{
if ( avl_list == 0 )
return( 0 );
if ( avl_nextlist == avl_maxlist ) {
- free( (caddr_t) avl_list);
- avl_list = (caddr_t *) 0;
+ free( (void*) avl_list);
+ avl_list = (void* *) 0;
return( 0 );
}
}
int
-avl_dup_error( void )
+avl_dup_error( void* left, void* right )
{
return( -1 );
}
int
-avl_dup_ok( void )
+avl_dup_ok( void* left, void* right )
{
return( 0 );
}
while ( fgets( command, sizeof( command ), stdin ) != NULL ) {
switch( *command ) {
case 'n': /* new tree */
- ( void ) avl_free( tree, (IFP) free );
+ ( void ) avl_free( tree, (AVL_FREE) free );
tree = NULLAVL;
break;
case 'p': /* print */
if ( fgets( name, sizeof( name ), stdin ) == NULL )
exit( 0 );
name[ strlen( name ) - 1 ] = '\0';
- if ( (p = (char *) avl_find( tree, name, strcmp ))
+ if ( (p = (char *) avl_find( tree, name, (AVL_CMP) strcmp ))
== NULL )
printf( "Not found.\n\n" );
else
if ( fgets( name, sizeof( name ), stdin ) == NULL )
exit( 0 );
name[ strlen( name ) - 1 ] = '\0';
- if ( avl_insert( &tree, strdup( name ), strcmp,
+ if ( avl_insert( &tree, strdup( name ), (AVL_CMP) strcmp,
avl_dup_error ) != 0 )
printf( "\nNot inserted!\n" );
break;
if ( fgets( name, sizeof( name ), stdin ) == NULL )
exit( 0 );
name[ strlen( name ) - 1 ] = '\0';
- if ( avl_delete( &tree, name, strcmp ) == NULL )
+ if ( avl_delete( &tree, name, (AVL_CMP) strcmp ) == NULL )
printf( "\nNot found!\n" );
break;
case 'q': /* quit */
struct asyntaxinfo *asi = NULL;
if ( (asi = (struct asyntaxinfo *) avl_find( attr_syntaxes, type,
- attr_syntax_name_cmp )) != NULL || (asi = (struct asyntaxinfo *)
- avl_find_lin( attr_syntaxes, type, attr_syntax_names_cmp ))
- != NULL )
+ (AVL_CMP) attr_syntax_name_cmp )) != NULL ||
+ (asi = (struct asyntaxinfo *) avl_find_lin( attr_syntaxes, type,
+ (AVL_CMP) attr_syntax_names_cmp )) != NULL )
{
return( asi->asi_syntax );
}
a->asi_names = charray_dup( argv );
argv[lasti] = save;
- switch ( avl_insert( &attr_syntaxes, (caddr_t) a, attr_syntax_cmp,
- attr_syntax_dup ) ) {
+ switch ( avl_insert( &attr_syntaxes, (caddr_t) a,
+ (AVL_CMP) attr_syntax_cmp,
+ (AVL_DUP) attr_syntax_dup ) ) {
case -1: /* duplicate - different syntaxes */
Debug( LDAP_DEBUG_ARGS, "%s: line %d: duplicate attribute\n",
fname, lineno, 0 );
static void
attr_syntax_print( void )
{
- (void) avl_apply( attr_syntaxes, attr_syntax_printnode, 0, -1,
- AVL_INORDER );
+ (void) avl_apply( attr_syntaxes, (AVL_APPLY) attr_syntax_printnode,
+ 0, -1, AVL_INORDER );
}
#endif
*indexmask = 0;
*syntaxmask = 0;
if ( (a = (struct attrinfo *) avl_find( li->li_attrs, type,
- ainfo_type_cmp )) == NULL ) {
+ (AVL_CMP) ainfo_type_cmp )) == NULL ) {
if ( (a = (struct attrinfo *) avl_find( li->li_attrs, "default",
- ainfo_type_cmp )) == NULL ) {
+ (AVL_CMP) ainfo_type_cmp )) == NULL ) {
return;
}
}
bdb2i_txn_attr_config( li, a->ai_type, 0 );
}
- switch (avl_insert( &li->li_attrs, (caddr_t) a, ainfo_cmp, ainfo_dup )) {
+ switch (avl_insert( &li->li_attrs, (caddr_t) a,
+ (AVL_CMP) ainfo_cmp, (AVL_DUP) ainfo_dup ))
+ {
case 1: /* duplicate - updating init version */
free( a->ai_type );
free( (char *) a );
}
if ( avl_insert( &cache->c_dntree, (caddr_t) e,
- entry_dn_cmp, avl_dup_error ) != 0 )
+ (AVL_CMP) entry_dn_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_TRACE,
"====> bdb2i_cache_add_entry( %ld ): \"%s\": already in dn cache\n",
/* id tree */
if ( avl_insert( &cache->c_idtree, (caddr_t) e,
- entry_id_cmp, avl_dup_error ) != 0 )
+ (AVL_CMP) entry_id_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_ANY,
"====> bdb2i_cache_add_entry( %ld ): \"%s\": already in id cache\n",
/* delete from dn tree inserted above */
if ( avl_delete( &cache->c_dntree, (caddr_t) e,
- entry_dn_cmp ) == NULL )
+ (AVL_CMP) entry_dn_cmp ) == NULL )
{
Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
0, 0, 0 );
#endif
if ( avl_insert( &cache->c_dntree, (caddr_t) e,
- entry_dn_cmp, avl_dup_error ) != 0 )
+ (AVL_CMP) entry_dn_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_TRACE,
"====> bdb2i_cache_add_entry( %ld ): \"%s\": already in dn cache\n",
/* id tree */
if ( avl_insert( &cache->c_idtree, (caddr_t) e,
- entry_id_cmp, avl_dup_error ) != 0 )
+ (AVL_CMP) entry_id_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_ANY,
"====> bdb2i_cache_update_entry( %ld ): \"%s\": already in id cache\n",
/* delete from dn tree inserted above */
if ( avl_delete( &cache->c_dntree, (caddr_t) e,
- entry_dn_cmp ) == NULL )
+ (AVL_CMP) entry_dn_cmp ) == NULL )
{
Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
0, 0, 0 );
e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
- entry_dn_cmp )) != NULL )
+ (AVL_CMP) entry_dn_cmp )) != NULL )
{
/*
* ep now points to an unlocked entry
ldap_pvt_thread_mutex_lock( &cache->c_mutex );
if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
- entry_id_cmp )) != NULL )
+ (AVL_CMP) entry_id_cmp )) != NULL )
{
#ifdef LDAP_DEBUG
assert( ep->e_private );
int rc = 0; /* return code */
/* dn tree */
- if ( avl_delete( &cache->c_dntree, (caddr_t) e, entry_dn_cmp )
+ if ( avl_delete( &cache->c_dntree, (caddr_t) e, (AVL_CMP) entry_dn_cmp )
== NULL )
{
rc = -1;
}
/* id tree */
- if ( avl_delete( &cache->c_idtree, (caddr_t) e, entry_id_cmp )
+ if ( avl_delete( &cache->c_idtree, (caddr_t) e, (AVL_CMP) entry_id_cmp )
== NULL )
{
rc = -1;
*indexmask = 0;
*syntaxmask = 0;
if ( (a = (struct attrinfo *) avl_find( li->li_attrs, type,
- ainfo_type_cmp )) == NULL ) {
+ (AVL_CMP) ainfo_type_cmp )) == NULL ) {
if ( (a = (struct attrinfo *) avl_find( li->li_attrs, "default",
- ainfo_type_cmp )) == NULL ) {
+ (AVL_CMP) ainfo_type_cmp )) == NULL ) {
return;
}
}
a->ai_indexmask |= INDEX_FROMINIT;
}
- switch (avl_insert( &li->li_attrs, (caddr_t) a, ainfo_cmp, ainfo_dup )) {
+ switch (avl_insert( &li->li_attrs, (caddr_t) a,
+ (AVL_CMP) ainfo_cmp, (AVL_DUP) ainfo_dup ))
+ {
case 1: /* duplicate - updating init version */
free( a->ai_type );
free( (char *) a );
}
if ( avl_insert( &cache->c_dntree, (caddr_t) e,
- entry_dn_cmp, avl_dup_error ) != 0 )
+ (AVL_CMP) entry_dn_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_TRACE,
"====> cache_add_entry( %ld ): \"%s\": already in dn cache\n",
/* id tree */
if ( avl_insert( &cache->c_idtree, (caddr_t) e,
- entry_id_cmp, avl_dup_error ) != 0 )
+ (AVL_CMP) entry_id_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_ANY,
"====> cache_add_entry( %ld ): \"%s\": already in id cache\n",
/* delete from dn tree inserted above */
if ( avl_delete( &cache->c_dntree, (caddr_t) e,
- entry_dn_cmp ) == NULL )
+ (AVL_CMP) entry_dn_cmp ) == NULL )
{
Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
0, 0, 0 );
#endif
if ( avl_insert( &cache->c_dntree, (caddr_t) e,
- entry_dn_cmp, avl_dup_error ) != 0 )
+ (AVL_CMP) entry_dn_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_TRACE,
"====> cache_update_entry( %ld ): \"%s\": already in dn cache\n",
/* id tree */
if ( avl_insert( &cache->c_idtree, (caddr_t) e,
- entry_id_cmp, avl_dup_error ) != 0 )
+ (AVL_CMP) entry_id_cmp, avl_dup_error ) != 0 )
{
Debug( LDAP_DEBUG_ANY,
"====> cache_update_entry( %ld ): \"%s\": already in id cache\n",
/* delete from dn tree inserted above */
if ( avl_delete( &cache->c_dntree, (caddr_t) e,
- entry_dn_cmp ) == NULL )
+ (AVL_CMP) entry_dn_cmp ) == NULL )
{
Debug( LDAP_DEBUG_ANY, "====> can't delete from dn cache\n",
0, 0, 0 );
e.e_ndn = dn_normalize_case( ch_strdup( dn ) );
if ( (ep = (Entry *) avl_find( cache->c_dntree, (caddr_t) &e,
- entry_dn_cmp )) != NULL )
+ (AVL_CMP) entry_dn_cmp )) != NULL )
{
/*
* ep now points to an unlocked entry
ldap_pvt_thread_mutex_lock( &cache->c_mutex );
if ( (ep = (Entry *) avl_find( cache->c_idtree, (caddr_t) &e,
- entry_id_cmp )) != NULL )
+ (AVL_CMP) entry_id_cmp )) != NULL )
{
#ifdef LDAP_DEBUG
assert( ep->e_private );
int rc = 0; /* return code */
/* dn tree */
- if ( avl_delete( &cache->c_dntree, (caddr_t) e, entry_dn_cmp )
+ if ( avl_delete( &cache->c_dntree, (caddr_t) e, (AVL_CMP) entry_dn_cmp )
== NULL )
{
rc = -1;
}
/* id tree */
- if ( avl_delete( &cache->c_idtree, (caddr_t) e, entry_id_cmp )
+ if ( avl_delete( &cache->c_idtree, (caddr_t) e, (AVL_CMP) entry_id_cmp )
== NULL )
{
rc = -1;