From: John Darrington Date: Sun, 29 Oct 2006 09:51:35 +0000 (+0000) Subject: Made array.h const correct, and dealt with the consequences. X-Git-Tag: v0.6.0~716 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=a1a4228b112a6aca97fef5aaaf9ffa21271a1f72;p=pspp-builds.git Made array.h const correct, and dealt with the consequences. --- diff --git a/src/data/dictionary.c b/src/data/dictionary.c index ac9c7d63..f7e52e3f 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -424,7 +424,7 @@ dict_contains_var (const struct dictionary *d, const struct variable *v) /* Compares two double pointers to variables, which should point to elements of a struct dictionary's `var' member array. */ static int -compare_var_ptrs (const void *a_, const void *b_, void *aux UNUSED) +compare_var_ptrs (const void *a_, const void *b_, const void *aux UNUSED) { struct variable *const *a = a_; struct variable *const *b = b_; @@ -1164,14 +1164,14 @@ dict_clear_vectors (struct dictionary *d) /* Compares two strings. */ static int -compare_strings (const void *a, const void *b, void *aux UNUSED) +compare_strings (const void *a, const void *b, const void *aux UNUSED) { return strcmp (a, b); } /* Hashes a string. */ static unsigned -hash_string (const void *s, void *aux UNUSED) +hash_string (const void *s, const void *aux UNUSED) { return hsh_hash_string (s); } diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index 20713a56..246448a1 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -215,7 +215,7 @@ struct name_pair }; static int -pair_sn_compare(const void *_p1, const void *_p2, void *aux UNUSED) +pair_sn_compare(const void *_p1, const void *_p2, const void *aux UNUSED) { int i; @@ -246,7 +246,7 @@ pair_sn_compare(const void *_p1, const void *_p2, void *aux UNUSED) } static unsigned int -pair_sn_hash(const void *_p, void *aux UNUSED) +pair_sn_hash(const void *_p, const void *aux UNUSED) { int i; const struct name_pair *p = _p; @@ -264,7 +264,7 @@ pair_sn_hash(const void *_p, void *aux UNUSED) } static void -pair_sn_free(void *p, void *aux UNUSED) +pair_sn_free(void *p, const void *aux UNUSED) { free(p); } diff --git a/src/data/value-labels.c b/src/data/value-labels.c index f3a9d24f..ad7f3b81 100644 --- a/src/data/value-labels.c +++ b/src/data/value-labels.c @@ -395,7 +395,7 @@ val_labs_done (struct val_labs_iterator **ip) /* Compares two value labels and returns a strcmp()-type result. */ int -compare_int_val_lab (const void *a_, const void *b_, void *vls_) +compare_int_val_lab (const void *a_, const void *b_, const void *vls_) { const struct int_val_lab *a = a_; const struct int_val_lab *b = b_; @@ -409,7 +409,7 @@ compare_int_val_lab (const void *a_, const void *b_, void *vls_) /* Hash a value label. */ unsigned -hash_int_val_lab (const void *vl_, void *vls_) +hash_int_val_lab (const void *vl_, const void *vls_) { const struct int_val_lab *vl = vl_; const struct val_labs *vls = vls_; @@ -422,7 +422,7 @@ hash_int_val_lab (const void *vl_, void *vls_) /* Free a value label. */ void -free_int_val_lab (void *vl_, void *vls_ UNUSED) +free_int_val_lab (void *vl_, const void *vls_ UNUSED) { struct int_val_lab *vl = vl_; @@ -500,7 +500,7 @@ atom_to_string (const struct atom *atom) /* A hsh_compare_func that compares A and B. */ static int -compare_atoms (const void *a_, const void *b_, void *aux UNUSED) +compare_atoms (const void *a_, const void *b_, const void *aux UNUSED) { const struct atom *a = a_; const struct atom *b = b_; @@ -510,7 +510,7 @@ compare_atoms (const void *a_, const void *b_, void *aux UNUSED) /* A hsh_hash_func that hashes ATOM. */ static unsigned -hash_atom (const void *atom_, void *aux UNUSED) +hash_atom (const void *atom_, const void *aux UNUSED) { const struct atom *atom = atom_; @@ -519,7 +519,7 @@ hash_atom (const void *atom_, void *aux UNUSED) /* A hsh_free_func that destroys ATOM. */ static void -free_atom (void *atom_, void *aux UNUSED) +free_atom (void *atom_, const void *aux UNUSED) { struct atom *atom = atom_; diff --git a/src/data/variable.c b/src/data/variable.c index 7a631a73..fc81c01e 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -216,7 +216,7 @@ var_is_plausible_name (const char *name, bool issue_error) /* A hsh_compare_func that orders variables A and B by their names. */ int -compare_var_names (const void *a_, const void *b_, void *foo UNUSED) +compare_var_names (const void *a_, const void *b_, const void *aux UNUSED) { const struct variable *a = a_; const struct variable *b = b_; @@ -226,7 +226,7 @@ compare_var_names (const void *a_, const void *b_, void *foo UNUSED) /* A hsh_hash_func that hashes variable V based on its name. */ unsigned -hash_var_name (const void *v_, void *foo UNUSED) +hash_var_name (const void *v_, const void *aux UNUSED) { const struct variable *v = v_; @@ -236,7 +236,7 @@ hash_var_name (const void *v_, void *foo UNUSED) /* A hsh_compare_func that orders pointers to variables A and B by their names. */ int -compare_var_ptr_names (const void *a_, const void *b_, void *foo UNUSED) +compare_var_ptr_names (const void *a_, const void *b_, const void *aux UNUSED) { struct variable *const *a = a_; struct variable *const *b = b_; @@ -247,7 +247,7 @@ compare_var_ptr_names (const void *a_, const void *b_, void *foo UNUSED) /* A hsh_hash_func that hashes pointer to variable V based on its name. */ unsigned -hash_var_ptr_name (const void *v_, void *foo UNUSED) +hash_var_ptr_name (const void *v_, const void *aux UNUSED) { struct variable *const *v = v_; diff --git a/src/data/variable.h b/src/data/variable.h index 8668119b..a3005cf1 100644 --- a/src/data/variable.h +++ b/src/data/variable.h @@ -87,8 +87,8 @@ struct variable /* Variable names. */ bool var_is_valid_name (const char *, bool issue_error); bool var_is_plausible_name (const char *name, bool issue_error); -int compare_var_names (const void *, const void *, void *); -unsigned hash_var_name (const void *, void *); +int compare_var_names (const void *, const void *, const void *); +unsigned hash_var_name (const void *, const void *); /* Short names. */ void var_set_short_name (struct variable *, const char *); @@ -96,8 +96,8 @@ void var_set_short_name_suffix (struct variable *, const char *, int suffix); void var_clear_short_name (struct variable *); /* Pointers to `struct variable', by name. */ -int compare_var_ptr_names (const void *, const void *, void *); -unsigned hash_var_ptr_name (const void *, void *); +int compare_var_ptr_names (const void *, const void *, const void *); +unsigned hash_var_ptr_name (const void *, const void *); /* Variable auxiliary data. */ void *var_attach_aux (struct variable *, diff --git a/src/language/data-io/matrix-data.c b/src/language/data-io/matrix-data.c index 1a586795..a002e78d 100644 --- a/src/language/data-io/matrix-data.c +++ b/src/language/data-io/matrix-data.c @@ -1584,7 +1584,7 @@ wr_read_splits (struct wr_aux_data *wr, /* Compares doubles A and B, treating SYSMIS as greatest. */ static int -compare_doubles (const void *a_, const void *b_, void *aux UNUSED) +compare_doubles (const void *a_, const void *b_, const void *aux UNUSED) { const double *a = a_; const double *b = b_; @@ -1604,9 +1604,9 @@ compare_doubles (const void *a_, const void *b_, void *aux UNUSED) /* Return strcmp()-type comparison of the MX->n_factors factors at _A and _B. Sort missing values toward the end. */ static int -compare_factors (const void *a_, const void *b_, void *mx_) +compare_factors (const void *a_, const void *b_, const void *mx_) { - struct matrix_data_pgm *mx = mx_; + const struct matrix_data_pgm *mx = mx_; struct factor_data *const *pa = a_; struct factor_data *const *pb = b_; const double *a = (*pa)->factors; diff --git a/src/language/dictionary/modify-variables.c b/src/language/dictionary/modify-variables.c index b47d93ff..f46dca7d 100644 --- a/src/language/dictionary/modify-variables.c +++ b/src/language/dictionary/modify-variables.c @@ -54,7 +54,7 @@ struct ordering static struct ordering forward_positional_ordering = {1, 1}; static int compare_variables_given_ordering (const void *, const void *, - void *ordering); + const void *ordering); /* Explains how to modify the variables in a dictionary. */ struct var_modification @@ -343,7 +343,7 @@ done: ORDERING, returning a strcmp()-type result. */ static int compare_variables_given_ordering (const void *a_, const void *b_, - void *ordering_) + const void *ordering_) { struct variable *const *pa = a_; struct variable *const *pb = b_; @@ -372,7 +372,7 @@ struct var_renaming var_renaming structures A and B. */ static int compare_var_renaming_by_new_name (const void *a_, const void *b_, - void *foo UNUSED) + const void *aux UNUSED) { const struct var_renaming *a = a_; const struct var_renaming *b = b_; diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index db45d4ea..41ac1058 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -311,7 +311,7 @@ autorecode_trns_free (void *trns_) /* AUTORECODE procedure. */ static int -compare_alpha_value (const void *a_, const void *b_, void *v_) +compare_alpha_value (const void *a_, const void *b_, const void *v_) { const union arc_value *a = a_; const union arc_value *b = b_; @@ -321,7 +321,7 @@ compare_alpha_value (const void *a_, const void *b_, void *v_) } static unsigned -hash_alpha_value (const void *a_, void *v_) +hash_alpha_value (const void *a_, const void *v_) { const union arc_value *a = a_; const struct variable *v = v_; @@ -330,7 +330,7 @@ hash_alpha_value (const void *a_, void *v_) } static int -compare_numeric_value (const void *a_, const void *b_, void *foo UNUSED) +compare_numeric_value (const void *a_, const void *b_, const void *aux UNUSED) { const union arc_value *a = a_; const union arc_value *b = b_; @@ -339,7 +339,7 @@ compare_numeric_value (const void *a_, const void *b_, void *foo UNUSED) } static unsigned -hash_numeric_value (const void *a_, void *foo UNUSED) +hash_numeric_value (const void *a_, const void *aux UNUSED) { const union arc_value *a = a_; diff --git a/src/language/stats/crosstabs.q b/src/language/stats/crosstabs.q index 8f392d5a..becc2edb 100644 --- a/src/language/stats/crosstabs.q +++ b/src/language/stats/crosstabs.q @@ -483,8 +483,8 @@ crs_custom_variables (struct dataset *ds, struct cmd_crosstabs *cmd UNUSED, void /* Data file processing. */ -static int compare_table_entry (const void *, const void *, void *); -static unsigned hash_table_entry (const void *, void *); +static int compare_table_entry (const void *, const void *, const void *); +static unsigned hash_table_entry (const void *, const void *); /* Set up the crosstabulation tables for processing. */ static void @@ -697,7 +697,7 @@ calc_integer (const struct ccase *c, void *aux UNUSED, const struct dataset *ds) /* Compare the table_entry's at A and B and return a strcmp()-type result. */ static int -compare_table_entry (const void *a_, const void *b_, void *foo UNUSED) +compare_table_entry (const void *a_, const void *b_, const void *aux UNUSED) { const struct table_entry *a = a_; const struct table_entry *b = b_; @@ -737,7 +737,7 @@ compare_table_entry (const void *a_, const void *b_, void *foo UNUSED) /* Calculate a hash value from table_entry A. */ static unsigned -hash_table_entry (const void *a_, void *foo UNUSED) +hash_table_entry (const void *a_, const void *aux UNUSED) { const struct table_entry *a = a_; unsigned long hash; @@ -1610,7 +1610,7 @@ find_pivot_extent_integer (struct table_entry **tp, int *cnt, int pivot) result. WIDTH_ points to an int which is either 0 for a numeric value or a string width for a string value. */ static int -compare_value (const void *a_, const void *b_, void *width_) +compare_value (const void *a_, const void *b_, const void *width_) { const union value *a = a_; const union value *b = b_; diff --git a/src/language/stats/descriptives.c b/src/language/stats/descriptives.c index a68f17c3..f07baece 100644 --- a/src/language/stats/descriptives.c +++ b/src/language/stats/descriptives.c @@ -939,11 +939,11 @@ display (struct dsc_proc *dsc) /* Compares `struct dsc_var's A and B according to the ordering specified by CMD. */ static int -descriptives_compare_dsc_vars (const void *a_, const void *b_, void *dsc_) +descriptives_compare_dsc_vars (const void *a_, const void *b_, const void *dsc_) { const struct dsc_var *a = a_; const struct dsc_var *b = b_; - struct dsc_proc *dsc = dsc_; + const struct dsc_proc *dsc = dsc_; int result; diff --git a/src/language/stats/frequencies.q b/src/language/stats/frequencies.q index 158fd429..03e90490 100644 --- a/src/language/stats/frequencies.q +++ b/src/language/stats/frequencies.q @@ -267,7 +267,7 @@ struct var_freqs }; static inline struct var_freqs * -get_var_freqs (struct variable *v) +get_var_freqs (const struct variable *v) { assert (v != NULL); assert (v->aux != NULL); @@ -515,7 +515,7 @@ calc (const struct ccase *c, void *aux UNUSED, const struct dataset *ds) for (i = 0; i < n_variables; i++) { - struct variable *v = v_variables[i]; + const struct variable *v = v_variables[i]; const union value *val = case_data (c, v->fv); struct var_freqs *vf = get_var_freqs (v); struct freq_tab *ft = &vf->tab; @@ -997,7 +997,7 @@ add_percentile (double x) /* Hash of numeric values. */ static unsigned -hash_value_numeric (const void *value_, void *foo UNUSED) +hash_value_numeric (const void *value_, const void *aux UNUSED) { const struct freq *value = value_; return hsh_hash_double (value->v[0].f); @@ -1005,10 +1005,10 @@ hash_value_numeric (const void *value_, void *foo UNUSED) /* Hash of string values. */ static unsigned -hash_value_alpha (const void *value_, void *v_) +hash_value_alpha (const void *value_, const void *v_) { const struct freq *value = value_; - struct variable *v = v_; + const struct variable *v = v_; struct var_freqs *vf = get_var_freqs (v); return hsh_hash_bytes (value->v[0].s, vf->width); @@ -1016,7 +1016,7 @@ hash_value_alpha (const void *value_, void *v_) /* Ascending numeric compare of values. */ static int -compare_value_numeric_a (const void *a_, const void *b_, void *foo UNUSED) +compare_value_numeric_a (const void *a_, const void *b_, const void *aux UNUSED) { const struct freq *a = a_; const struct freq *b = b_; @@ -1031,11 +1031,11 @@ compare_value_numeric_a (const void *a_, const void *b_, void *foo UNUSED) /* Ascending string compare of values. */ static int -compare_value_alpha_a (const void *a_, const void *b_, void *v_) +compare_value_alpha_a (const void *a_, const void *b_, const void *v_) { const struct freq *a = a_; const struct freq *b = b_; - struct variable *v = v_; + const struct variable *v = v_; struct var_freqs *vf = get_var_freqs (v); return memcmp (a->v[0].s, b->v[0].s, vf->width); @@ -1043,14 +1043,14 @@ compare_value_alpha_a (const void *a_, const void *b_, void *v_) /* Descending numeric compare of values. */ static int -compare_value_numeric_d (const void *a, const void *b, void *foo UNUSED) +compare_value_numeric_d (const void *a, const void *b, const void *aux UNUSED) { - return -compare_value_numeric_a (a, b, foo); + return -compare_value_numeric_a (a, b, aux); } /* Descending string compare of values. */ static int -compare_value_alpha_d (const void *a, const void *b, void *v) +compare_value_alpha_d (const void *a, const void *b, const void *v) { return -compare_value_alpha_a (a, b, v); } @@ -1058,7 +1058,7 @@ compare_value_alpha_d (const void *a, const void *b, void *v) /* Ascending numeric compare of frequency; secondary key on ascending numeric value. */ static int -compare_freq_numeric_a (const void *a_, const void *b_, void *foo UNUSED) +compare_freq_numeric_a (const void *a_, const void *b_, const void *aux UNUSED) { const struct freq *a = a_; const struct freq *b = b_; @@ -1079,11 +1079,11 @@ compare_freq_numeric_a (const void *a_, const void *b_, void *foo UNUSED) /* Ascending numeric compare of frequency; secondary key on ascending string value. */ static int -compare_freq_alpha_a (const void *a_, const void *b_, void *v_) +compare_freq_alpha_a (const void *a_, const void *b_, const void *v_) { const struct freq *a = a_; const struct freq *b = b_; - struct variable *v = v_; + const struct variable *v = v_; struct var_freqs *vf = get_var_freqs (v); if (a->c > b->c) @@ -1097,7 +1097,7 @@ compare_freq_alpha_a (const void *a_, const void *b_, void *v_) /* Descending numeric compare of frequency; secondary key on ascending numeric value. */ static int -compare_freq_numeric_d (const void *a_, const void *b_, void *foo UNUSED) +compare_freq_numeric_d (const void *a_, const void *b_, const void *aux UNUSED) { const struct freq *a = a_; const struct freq *b = b_; @@ -1118,11 +1118,11 @@ compare_freq_numeric_d (const void *a_, const void *b_, void *foo UNUSED) /* Descending numeric compare of frequency; secondary key on ascending string value. */ static int -compare_freq_alpha_d (const void *a_, const void *b_, void *v_) +compare_freq_alpha_d (const void *a_, const void *b_, const void *v_) { const struct freq *a = a_; const struct freq *b = b_; - struct variable *v = v_; + const struct variable *v = v_; struct var_freqs *vf = get_var_freqs (v); if (a->c > b->c) diff --git a/src/libpspp/array.c b/src/libpspp/array.c index 1349f253..a0639cca 100644 --- a/src/libpspp/array.c +++ b/src/libpspp/array.c @@ -590,7 +590,7 @@ typedef struct void sort (void *array, size_t count, size_t size, - algo_compare_func *compare, void *aux) + algo_compare_func *compare, const void *aux) { char *const first = array; const size_t max_thresh = MAX_THRESH * size; @@ -755,7 +755,7 @@ sort (void *array, size_t count, size_t size, passed to COMPARE as auxiliary data. */ bool is_sorted (const void *array, size_t count, size_t size, - algo_compare_func *compare, void *aux) + algo_compare_func *compare, const void *aux) { const char *first = array; size_t idx; diff --git a/src/libpspp/array.h b/src/libpspp/array.h index a543e5a3..a06a7ca1 100644 --- a/src/libpspp/array.h +++ b/src/libpspp/array.h @@ -6,7 +6,8 @@ /* Compares A and B, given auxiliary data AUX, and returns a strcmp()-type result. */ -typedef int algo_compare_func (const void *a, const void *b, void *aux); + +typedef int algo_compare_func (const void *a, const void *b, const void *aux); /* Tests a predicate on DATA, given auxiliary data AUX */ typedef bool algo_predicate_func (const void *data, void *aux); @@ -46,13 +47,13 @@ size_t count_if (const void *array, size_t count, size_t size, using COMPARE for comparisons. AUX is passed to each comparison as auxiliary data. */ void sort (void *array, size_t count, size_t size, - algo_compare_func *compare, void *aux); + algo_compare_func *compare, const void *aux); /* Tests whether ARRAY, which contains COUNT elements of SIZE bytes each, is sorted in order according to COMPARE. AUX is passed to COMPARE as auxiliary data. */ bool is_sorted (const void *array, size_t count, size_t size, - algo_compare_func *compare, void *aux); + algo_compare_func *compare, const void *aux); /* Makes the elements in ARRAY unique, by moving up duplicates, and returns the new number of elements in the array. Sorted diff --git a/src/libpspp/hash.c b/src/libpspp/hash.c index a6d5f5d8..9a6c3cae 100644 --- a/src/libpspp/hash.c +++ b/src/libpspp/hash.c @@ -151,7 +151,7 @@ struct hsh_table size_t size; /* Number of entries (a power of 2). */ void **entries; /* Hash table proper. */ - void *aux; /* Auxiliary data for comparison functions. */ + const void *aux; /* Auxiliary data for comparison functions. */ hsh_compare_func *compare; hsh_hash_func *hash; hsh_free_func *free; @@ -365,11 +365,11 @@ hsh_data (struct hsh_table *h) /* Dereferences void ** pointers and passes them to the hash comparison function. */ static int -comparison_helper (const void *a_, const void *b_, void *h_) +comparison_helper (const void *a_, const void *b_, const void *h_) { void *const *a = a_; void *const *b = b_; - struct hsh_table *h = h_; + const struct hsh_table *h = h_; assert(a); assert(b); diff --git a/src/libpspp/hash.h b/src/libpspp/hash.h index aa4041c4..f5d2a5e4 100644 --- a/src/libpspp/hash.h +++ b/src/libpspp/hash.h @@ -23,9 +23,9 @@ #include #include -typedef int hsh_compare_func (const void *, const void *, void *aux); -typedef unsigned hsh_hash_func (const void *, void *aux); -typedef void hsh_free_func (void *, void *aux); +typedef int hsh_compare_func (const void *, const void *, const void *aux); +typedef unsigned hsh_hash_func (const void *, const void *aux); +typedef void hsh_free_func (void *, const void *aux); /* Hash table iterator (opaque). */ struct hsh_iterator diff --git a/src/math/sort.c b/src/math/sort.c index ee2bc6ea..0d32d5cc 100644 --- a/src/math/sort.c +++ b/src/math/sort.c @@ -139,7 +139,7 @@ struct indexed_case unsigned long idx; /* Index to allow for stable sorting. */ }; -static int compare_indexed_cases (const void *, const void *, void *); +static int compare_indexed_cases (const void *, const void *, const void *); /* If the data is in memory, do an internal sort and return a new casefile for the data. Otherwise, return a null pointer. */ @@ -200,9 +200,9 @@ do_internal_sort (struct casereader *reader, at A and B, with a "last resort" comparison for stability, and returns a strcmp()-type result. */ static int -compare_indexed_cases (const void *a_, const void *b_, void *criteria_) +compare_indexed_cases (const void *a_, const void *b_, const void *criteria_) { - struct sort_criteria *criteria = criteria_; + const struct sort_criteria *criteria = criteria_; const struct indexed_case *a = a_; const struct indexed_case *b = b_; int result = compare_record (&a->c, &b->c, criteria); @@ -309,16 +309,17 @@ struct initial_run_state }; static bool destroy_initial_run_state (struct initial_run_state *); -static void process_case (struct initial_run_state *, const struct ccase *, - size_t); +static void process_case (struct initial_run_state *, + const struct ccase *, size_t); static int allocate_cases (struct initial_run_state *); static void output_record (struct initial_run_state *); static void start_run (struct initial_run_state *); static void end_run (struct initial_run_state *); static int compare_record_run (const struct record_run *, const struct record_run *, - struct initial_run_state *); -static int compare_record_run_minheap (const void *, const void *, void *); + const struct initial_run_state *); +static int compare_record_run_minheap (const void *, const void *, + const void *); /* Reads cases from READER and composes initial runs in XSRT. */ static int @@ -361,7 +362,8 @@ write_runs (struct external_sort *xsrt, struct casereader *reader) /* Add a single case to an initial run. */ static void -process_case (struct initial_run_state *irs, const struct ccase *c, size_t idx) +process_case (struct initial_run_state *irs, const struct ccase *c, + size_t idx) { struct record_run *rr; @@ -480,7 +482,7 @@ compare_record (const struct ccase *a, const struct ccase *b, static int compare_record_run (const struct record_run *a, const struct record_run *b, - struct initial_run_state *irs) + const struct initial_run_state *irs) { int result = a->run < b->run ? -1 : a->run > b->run; if (result == 0) @@ -494,7 +496,7 @@ compare_record_run (const struct record_run *a, on the current record according to SCP, but in descending order. */ static int -compare_record_run_minheap (const void *a, const void *b, void *irs) +compare_record_run_minheap (const void *a, const void *b, const void *irs) { return -compare_record_run (a, b, irs); }