From 37c8a21f16b972b259535527f38161c611b17e2a Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 20 Feb 2023 09:48:50 -0800 Subject: [PATCH] dictionary: Fix misuse of DC_* treewide. The DC_* constants are bit values, but some code was using them as shift offsets. This fixes the problem. --- perl-module/PSPP.xs | 3 +-- src/data/case-map.c | 8 ++++---- src/data/dataset.c | 6 +++--- src/data/dictionary.c | 17 ++++++----------- src/language/lexer/variable-parser.c | 3 +-- 5 files changed, 15 insertions(+), 22 deletions(-) diff --git a/perl-module/PSPP.xs b/perl-module/PSPP.xs index 1f05be2a65..573dfab42a 100644 --- a/perl-module/PSPP.xs +++ b/perl-module/PSPP.xs @@ -694,8 +694,7 @@ CODE: c = case_create (dict_get_proto (swi->dict->dict)); - dict_get_vars (swi->dict->dict, &vv, &nv, - 1u << DC_ORDINARY | 1u << DC_SYSTEM); + dict_get_vars (swi->dict->dict, &vv, &nv, 0); for (SV *sv = av_shift (av_case); SvOK (sv); sv = av_shift (av_case)) { diff --git a/src/data/case-map.c b/src/data/case-map.c index ed32db0d3f..87174f1fb3 100644 --- a/src/data/case-map.c +++ b/src/data/case-map.c @@ -182,9 +182,9 @@ destroy_case_map (void *map_) the last value. (Holes are created by deleting variables.) All variables are compacted if EXCLUDE_CLASSES is 0, or it may - contain one or more of (1u << DC_ORDINARY), (1u << DC_SYSTEM), - or (1u << DC_SCRATCH) to cause the corresponding type of - variable to be deleted during compaction. */ + contain one or more of DC_ORDINARY, DC_SYSTEM, or DC_SCRATCH + to cause the corresponding type of variable to be deleted + during compaction. */ struct case_map * case_map_to_compact_dict (const struct dictionary *d, unsigned int exclude_classes) @@ -205,7 +205,7 @@ case_map_to_compact_dict (const struct dictionary *d, for (i = 0; i < n_vars; i++) { struct variable *v = dict_get_var (d, i); - if (!(exclude_classes & (1u << var_get_dict_class (v)))) + if (!(exclude_classes & var_get_dict_class (v))) insert_mapping (map, var_get_case_index (v), n_values++); } diff --git a/src/data/dataset.c b/src/data/dataset.c index 450383fb87..aa196f2850 100644 --- a/src/data/dataset.c +++ b/src/data/dataset.c @@ -450,12 +450,12 @@ proc_open_filtering (struct dataset *ds, bool filter) if (!ds->discard_output) { struct dictionary *pd = ds->permanent_dict; - size_t compacted_n_values = dict_count_values (pd, 1u << DC_SCRATCH); + size_t compacted_n_values = dict_count_values (pd, DC_SCRATCH); if (compacted_n_values < dict_get_next_value_idx (pd)) { struct caseproto *compacted_proto; - compacted_proto = dict_get_compacted_proto (pd, 1u << DC_SCRATCH); - ds->compactor = case_map_to_compact_dict (pd, 1u << DC_SCRATCH); + compacted_proto = dict_get_compacted_proto (pd, DC_SCRATCH); + ds->compactor = case_map_to_compact_dict (pd, DC_SCRATCH); ds->sink = autopaging_writer_create (compacted_proto); caseproto_unref (compacted_proto); } diff --git a/src/data/dictionary.c b/src/data/dictionary.c index 1dffcb542f..a2a622c937 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1435,9 +1435,8 @@ dict_compact_values (struct dictionary *d) /* Returns the number of values occupied by the variables in dictionary D. All variables are considered if EXCLUDE_CLASSES - is 0, or it may contain one or more of (1u << DC_ORDINARY), - (1u << DC_SYSTEM), or (1u << DC_SCRATCH) to exclude the - corresponding type of variable. + is 0, or it may contain one or more of DC_ORDINARY, DC_SYSTEM, + or DC_SCRATCH to exclude the corresponding type of variable. The return value may be less than the number of values in one of dictionary D's cases (as returned by @@ -1446,15 +1445,13 @@ dict_compact_values (struct dictionary *d) size_t dict_count_values (const struct dictionary *d, unsigned int exclude_classes) { - assert ((exclude_classes & ~((1u << DC_ORDINARY) - | (1u << DC_SYSTEM) - | (1u << DC_SCRATCH))) == 0); + assert (!(exclude_classes & ~DC_ALL)); size_t n = 0; for (size_t i = 0; i < d->n_vars; i++) { enum dict_class class = var_get_dict_class (d->vars[i].var); - if (!(exclude_classes & (1u << class))) + if (!(exclude_classes & class)) n++; } return n; @@ -1474,15 +1471,13 @@ dict_get_compacted_proto (const struct dictionary *d, struct caseproto *proto; size_t i; - assert ((exclude_classes & ~((1u << DC_ORDINARY) - | (1u << DC_SYSTEM) - | (1u << DC_SCRATCH))) == 0); + assert (!(exclude_classes & ~DC_ALL)); proto = caseproto_create (); for (i = 0; i < d->n_vars; i++) { struct variable *v = d->vars[i].var; - if (!(exclude_classes & (1u << var_get_dict_class (v)))) + if (!(exclude_classes & var_get_dict_class (v))) proto = caseproto_add_width (proto, var_get_width (v)); } return proto; diff --git a/src/language/lexer/variable-parser.c b/src/language/lexer/variable-parser.c index 8b577578e7..57f7042eca 100644 --- a/src/language/lexer/variable-parser.c +++ b/src/language/lexer/variable-parser.c @@ -179,8 +179,7 @@ parse_variables_pool (struct lexer *lexer, struct pool *pool, failure. */ static bool parse_var_idx_class (struct lexer *lexer, const struct var_set *vs, - size_t *idx, - enum dict_class *class) + size_t *idx, enum dict_class *class) { if (!parse_vs_variable_idx (lexer, vs, idx)) return false; -- 2.30.2