Replace IFP() with appropriate full prototypes:

AVL_CMP, AVL_DUP, AVL_FREE, AVL_APPLY.
Apply casts as needed.
Change data pointer from caddr_t to void *.
This commit is contained in:
Kurt Zeilenga 1999-03-02 00:32:59 +00:00
parent a8a05cbe48
commit 4e160e83b6
8 changed files with 102 additions and 96 deletions

View file

@ -33,7 +33,7 @@
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;
@ -50,48 +50,49 @@ typedef struct avlnode {
#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

View file

@ -53,10 +53,10 @@ static char avl_version[] = "AVL library version 1.0\n";
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
)
{
@ -206,7 +206,7 @@ ravl_insert(
*/
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;
@ -348,12 +348,12 @@ left_balance( Avlnode **root )
* 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 )
@ -437,8 +437,8 @@ ravl_delete( Avlnode **root, caddr_t data, IFP fcmp, int *shorter )
* 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;
@ -446,7 +446,7 @@ avl_delete( Avlnode **root, caddr_t data, IFP fcmp )
}
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 );
@ -466,7 +466,7 @@ avl_inapply( Avlnode *root, IFP fn, caddr_t arg, int stopflag )
}
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 );
@ -485,7 +485,7 @@ avl_postapply( Avlnode *root, IFP fn, caddr_t arg, int stopflag )
}
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 );
@ -513,7 +513,7 @@ avl_preapply( Avlnode *root, IFP fn, caddr_t arg, int stopflag )
*/
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:
@ -544,11 +544,11 @@ avl_apply( Avlnode *root, IFP fn, caddr_t arg, int stopflag, int type )
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
)
{
@ -557,7 +557,7 @@ avl_prefixapply(
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 );
@ -593,7 +593,7 @@ avl_prefixapply(
*/
int
avl_free( Avlnode *root, IFP dfree )
avl_free( Avlnode *root, AVL_FREE dfree )
{
int nleft, nright;
@ -620,8 +620,8 @@ avl_free( Avlnode *root, IFP dfree )
* < 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;
@ -642,10 +642,10 @@ avl_find( Avlnode *root, caddr_t data, IFP fcmp )
* 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 );
@ -664,7 +664,7 @@ avl_find_lin( Avlnode *root, caddr_t data, IFP fcmp )
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;
@ -672,18 +672,18 @@ 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;
@ -703,12 +703,12 @@ avl_buildlist( caddr_t data, int arg )
* 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;
@ -716,20 +716,20 @@ avl_getfirst( Avlnode *root )
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 );
}
@ -737,13 +737,13 @@ avl_getnext( void )
}
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 );
}

View file

@ -25,7 +25,7 @@ main( int argc, char **argv )
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 */
@ -43,7 +43,7 @@ main( int argc, char **argv )
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
@ -54,7 +54,7 @@ main( int argc, char **argv )
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;
@ -63,7 +63,7 @@ main( int argc, char **argv )
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 */

View file

@ -239,9 +239,9 @@ attr_syntax( char *type )
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 );
}
@ -304,8 +304,9 @@ attr_syntax_config(
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 );
@ -338,8 +339,8 @@ attr_syntax_printnode( struct asyntaxinfo *a )
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

View file

@ -67,9 +67,9 @@ bdb2i_attr_masks(
*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;
}
}
@ -147,7 +147,9 @@ bdb2i_attr_index_config(
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 );

View file

@ -168,7 +168,7 @@ bdb2i_cache_add_entry_rw(
}
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",
@ -183,7 +183,7 @@ bdb2i_cache_add_entry_rw(
/* 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",
@ -191,7 +191,7 @@ bdb2i_cache_add_entry_rw(
/* 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 );
@ -274,7 +274,7 @@ bdb2i_cache_update_entry(
#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",
@ -287,7 +287,7 @@ bdb2i_cache_update_entry(
/* 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",
@ -295,7 +295,7 @@ bdb2i_cache_update_entry(
/* 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 );
@ -374,7 +374,7 @@ bdb2i_cache_find_entry_dn2id(
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
@ -449,7 +449,7 @@ try_again:
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 );
@ -538,14 +538,14 @@ cache_delete_entry_internal(
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;

View file

@ -67,9 +67,9 @@ attr_masks(
*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;
}
}
@ -142,7 +142,9 @@ attr_index_config(
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 );

View file

@ -226,7 +226,7 @@ cache_add_entry_rw(
}
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",
@ -241,7 +241,7 @@ cache_add_entry_rw(
/* 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",
@ -250,7 +250,7 @@ cache_add_entry_rw(
/* 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 );
@ -336,7 +336,7 @@ cache_update_entry(
#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",
@ -349,7 +349,7 @@ cache_update_entry(
/* 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",
@ -357,7 +357,7 @@ cache_update_entry(
/* 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 );
@ -438,7 +438,7 @@ cache_find_entry_dn2id(
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
@ -512,7 +512,7 @@ try_again:
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 );
@ -613,14 +613,14 @@ cache_delete_entry_internal(
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;