From f821734badec2dcca4bdcd2069d22d60dc074c94 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Fri, 24 Feb 2023 18:46:48 -0800 Subject: [PATCH] dictionary: Make dict_get_weight_format() return by value, not pointer. This seems like a better interface. --- src/data/dictionary.c | 4 ++-- src/data/dictionary.h | 2 +- src/language/commands/crosstabs.c | 12 ++++++------ src/language/commands/jonckheere-terpstra.c | 4 ++-- src/language/commands/ks-one-sample.c | 6 +++--- src/language/commands/npar-summary.c | 2 +- src/language/commands/npar-summary.h | 2 +- src/language/commands/oneway.c | 2 +- src/output/pivot-table.c | 12 +++++------- src/output/pivot-table.h | 2 +- 10 files changed, 23 insertions(+), 25 deletions(-) diff --git a/src/data/dictionary.c b/src/data/dictionary.c index a2a622c937..800bad9463 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1315,10 +1315,10 @@ dict_get_rounded_case_weight (const struct dictionary *d, } /* Returns the format to use for weights. */ -const struct fmt_spec * +struct fmt_spec dict_get_weight_format (const struct dictionary *d) { - return d->weight ? var_get_print_format (d->weight) : &F_8_0; + return d->weight ? *var_get_print_format (d->weight) : F_8_0; } /* Sets the weighting variable of D to V, or turning off diff --git a/src/data/dictionary.h b/src/data/dictionary.h index f709f11dd9..e1d67ee704 100644 --- a/src/data/dictionary.h +++ b/src/data/dictionary.h @@ -102,7 +102,7 @@ double dict_get_rounded_case_weight (const struct dictionary *, const struct ccase *, bool *); struct variable *dict_get_weight (const struct dictionary *); void dict_set_weight (struct dictionary *, struct variable *); -const struct fmt_spec *dict_get_weight_format (const struct dictionary *); +struct fmt_spec dict_get_weight_format (const struct dictionary *); /* Filter variable. */ struct variable *dict_get_filter (const struct dictionary *); diff --git a/src/language/commands/crosstabs.c b/src/language/commands/crosstabs.c index 72579b0b97..0ed8452dc5 100644 --- a/src/language/commands/crosstabs.c +++ b/src/language/commands/crosstabs.c @@ -288,7 +288,7 @@ cmd_crosstabs (struct lexer *lexer, struct dataset *ds) .exclude = MV_ANY, .barchart = false, .bad_warn = true, - .weight_format = *dict_get_weight_format (dataset_dict (ds)), + .weight_format = dict_get_weight_format (dataset_dict (ds)), .variables = NULL, .n_variables = 0, @@ -1385,7 +1385,7 @@ create_crosstab_table (struct crosstabs_proc *proc, struct crosstabulation *xt, struct pivot_table *table = pivot_table_create__ ( pivot_value_new_user_text_nocopy (ds_steal_cstr (&title)), "Crosstabulation"); - pivot_table_set_weight_format (table, &proc->weight_format); + pivot_table_set_weight_format (table, proc->weight_format); struct pivot_dimension *statistics = pivot_dimension_create ( table, PIVOT_AXIS_ROW, N_("Statistics")); @@ -1419,7 +1419,7 @@ static struct pivot_table * create_chisq_table (struct crosstabulation *xt) { struct pivot_table *chisq = pivot_table_create (N_("Chi-Square Tests")); - pivot_table_set_weight_format (chisq, &xt->weight_format); + pivot_table_set_weight_format (chisq, xt->weight_format); pivot_dimension_create ( chisq, PIVOT_AXIS_ROW, N_("Statistics"), @@ -1449,7 +1449,7 @@ static struct pivot_table * create_sym_table (struct crosstabulation *xt) { struct pivot_table *sym = pivot_table_create (N_("Symmetric Measures")); - pivot_table_set_weight_format (sym, &xt->weight_format); + pivot_table_set_weight_format (sym, xt->weight_format); pivot_dimension_create ( sym, PIVOT_AXIS_COLUMN, N_("Values"), @@ -1488,7 +1488,7 @@ create_risk_table (struct crosstabulation *xt, struct pivot_dimension **risk_statistics) { struct pivot_table *risk = pivot_table_create (N_("Risk Estimate")); - pivot_table_set_weight_format (risk, &xt->weight_format); + pivot_table_set_weight_format (risk, xt->weight_format); struct pivot_dimension *values = pivot_dimension_create ( risk, PIVOT_AXIS_COLUMN, N_("Values"), @@ -1534,7 +1534,7 @@ static struct pivot_table * create_direct_table (struct crosstabulation *xt) { struct pivot_table *direct = pivot_table_create (N_("Directional Measures")); - pivot_table_set_weight_format (direct, &xt->weight_format); + pivot_table_set_weight_format (direct, xt->weight_format); pivot_dimension_create ( direct, PIVOT_AXIS_COLUMN, N_("Values"), diff --git a/src/language/commands/jonckheere-terpstra.c b/src/language/commands/jonckheere-terpstra.c index 7d654bbecb..b0385fa577 100644 --- a/src/language/commands/jonckheere-terpstra.c +++ b/src/language/commands/jonckheere-terpstra.c @@ -222,7 +222,7 @@ struct jt }; static void show_jt (const struct n_sample_test *, const struct jt *, - const struct fmt_spec *wfmt); + const struct fmt_spec wfmt); void @@ -350,7 +350,7 @@ jonckheere_terpstra_execute (const struct dataset *ds, static void show_jt (const struct n_sample_test *nst, const struct jt *jt, - const struct fmt_spec *wfmt) + const struct fmt_spec wfmt) { struct pivot_table *table = pivot_table_create ( N_("Jonckheere-Terpstra Test")); diff --git a/src/language/commands/ks-one-sample.c b/src/language/commands/ks-one-sample.c index f02b9309c3..b3e250aea8 100644 --- a/src/language/commands/ks-one-sample.c +++ b/src/language/commands/ks-one-sample.c @@ -126,7 +126,7 @@ ks_asymp_sig (double z) } } -static void show_results (const struct ks *, const struct ks_one_sample_test *, const struct fmt_spec *); +static void show_results (const struct ks *, const struct ks_one_sample_test *, const struct fmt_spec); void @@ -140,7 +140,7 @@ ks_one_sample_execute (const struct dataset *ds, const struct ks_one_sample_test *kst = UP_CAST (test, const struct ks_one_sample_test, parent.parent); const struct one_sample_test *ost = &kst->parent; struct ccase *c; - const struct fmt_spec *wfmt = dict_get_weight_format (dict); + const struct fmt_spec wfmt = dict_get_weight_format (dict); bool warn = true; int v; struct casereader *r = casereader_clone (input); @@ -268,7 +268,7 @@ ks_one_sample_execute (const struct dataset *ds, static void show_results (const struct ks *ks, const struct ks_one_sample_test *kst, - const struct fmt_spec *wfmt) + const struct fmt_spec wfmt) { struct pivot_table *table = pivot_table_create ( N_("One-Sample Kolmogorov-Smirnov Test")); diff --git a/src/language/commands/npar-summary.c b/src/language/commands/npar-summary.c index fddf30639e..08a678df83 100644 --- a/src/language/commands/npar-summary.c +++ b/src/language/commands/npar-summary.c @@ -93,7 +93,7 @@ void do_summary_box (const struct descriptives *desc, const struct variable *const *vv, int n_vars, - const struct fmt_spec *wfmt) + const struct fmt_spec wfmt) { if (!desc) return; diff --git a/src/language/commands/npar-summary.h b/src/language/commands/npar-summary.h index 3955bd6411..003cf89e9f 100644 --- a/src/language/commands/npar-summary.h +++ b/src/language/commands/npar-summary.h @@ -37,7 +37,7 @@ void do_summary_box (const struct descriptives *desc, const struct variable *const *vv, int n_vars, - const struct fmt_spec *wfmt); + const struct fmt_spec wfmt); void npar_summary_calc_descriptives (struct descriptives *desc, struct casereader *input, diff --git a/src/language/commands/oneway.c b/src/language/commands/oneway.c index 49b06c73d2..ba4e1c1395 100644 --- a/src/language/commands/oneway.c +++ b/src/language/commands/oneway.c @@ -139,7 +139,7 @@ struct oneway_spec /* The weight variable */ const struct variable *wv; - const struct fmt_spec *wfmt; + const struct fmt_spec wfmt; /* The confidence level for multiple comparisons */ double alpha; diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index bec8638bd0..c6197beb04 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -1368,19 +1368,17 @@ pivot_table_set_weight_var (struct pivot_table *table, const struct variable *wv) { if (wv) - pivot_table_set_weight_format (table, var_get_print_format (wv)); + pivot_table_set_weight_format (table, *var_get_print_format (wv)); } /* Sets the format used for PIVOT_RC_COUNT cells to WFMT, which should be the - format for the dictionary whose data or statistics are being put into TABLE. - - This has no effect if WFMT is NULL. */ + format for the dictionary whose data or statistics are being put into + TABLE. */ void pivot_table_set_weight_format (struct pivot_table *table, - const struct fmt_spec *wfmt) + const struct fmt_spec wfmt) { - if (wfmt) - table->weight_format = *wfmt; + table->weight_format = wfmt; } /* Returns true if TABLE has no cells, false otherwise. */ diff --git a/src/output/pivot-table.h b/src/output/pivot-table.h index 145e356cf3..c52c7654b1 100644 --- a/src/output/pivot-table.h +++ b/src/output/pivot-table.h @@ -577,7 +577,7 @@ void pivot_table_set_look (struct pivot_table *, void pivot_table_set_weight_var (struct pivot_table *, const struct variable *); void pivot_table_set_weight_format (struct pivot_table *, - const struct fmt_spec *); + const struct fmt_spec); /* Query. */ bool pivot_table_is_empty (const struct pivot_table *); -- 2.30.2