This is the first of two commits (didn't want to dump them all into the
same one). However, the first will temporarily break things until the second comes through. :-) The safestack.h handling was mapping compare callbacks that externally are of the type (int (*)(type **,type **)) into the underlying callback type used by stack.[ch], which is (int (*)(void *,void *)). After some degree of digging, it appears that the callback type in the underlying stack code should use double pointers too - when the compare operations are invoked (from sk_find and sk_sort), they are being used by bsearch and qsort to compare two pointers to pointers. This change corrects the prototyping (by only casting to the (void*,void*) form at the moment it is needed by bsearch and qsort) and makes the mapping in safestack.h more transparent. It also changes from "void*" to "char*" to stay in keeping with stack.[ch]'s assumed base type of "char". Also - the "const" situation was that safestack.h was throwing away "const"s, and to compound the problem - a close examination of stack.c showed that (const char **) is not really achieving what it is supposed to when the callback is being invoked, what is needed is (const char * const *). So the underlying stack.[ch] and the mapping macros in safestack.h have all been altered to correct this. What will follow are the vast quantities of "const" corrections required in stack-dependant code that was being let "slip" through when safestack.h was discarding "const"s. These now all come up as compiler warnings.
This commit is contained in:
@@ -70,11 +70,11 @@ typedef struct stack_st
|
||||
int sorted;
|
||||
|
||||
int num_alloc;
|
||||
int (*comp)(const void *, const void *);
|
||||
int (*comp)(const char * const *, const char * const *);
|
||||
} STACK;
|
||||
|
||||
|
||||
#define sk_new_null() sk_new(NULL)
|
||||
#define sk_new_null() sk_new((int (*)(const char * const *, \
|
||||
const char * const *))NULL)
|
||||
|
||||
#define M_sk_num(sk) ((sk) ? (sk)->num:-1)
|
||||
#define M_sk_value(sk,n) ((sk) ? (sk)->data[n] : NULL)
|
||||
@@ -84,7 +84,7 @@ char *sk_value(const STACK *, int);
|
||||
|
||||
char *sk_set(STACK *, int, char *);
|
||||
|
||||
STACK *sk_new(int (*cmp)(const void *, const void *));
|
||||
STACK *sk_new(int (*cmp)(const char * const *, const char * const *));
|
||||
void sk_free(STACK *);
|
||||
void sk_pop_free(STACK *st, void (*func)(void *));
|
||||
int sk_insert(STACK *sk,char *data,int where);
|
||||
@@ -96,7 +96,9 @@ int sk_unshift(STACK *st,char *data);
|
||||
char *sk_shift(STACK *st);
|
||||
char *sk_pop(STACK *st);
|
||||
void sk_zero(STACK *st);
|
||||
int (*sk_set_cmp_func(STACK *sk, int (*c)(const void *,const void *)))(const void *, const void *);
|
||||
int (*sk_set_cmp_func(STACK *sk, int (*c)(const char * const *,
|
||||
const char * const *)))
|
||||
(const char * const *, const char * const *);
|
||||
STACK *sk_dup(STACK *st);
|
||||
void sk_sort(STACK *st);
|
||||
|
||||
|
Reference in New Issue
Block a user