dictionary: Fix misuse of DC_* treewide.
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 20 Feb 2023 17:48:50 +0000 (09:48 -0800)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 20 Feb 2023 18:11:21 +0000 (10:11 -0800)
The DC_* constants are bit values, but some code was using them as shift
offsets.  This fixes the problem.

perl-module/PSPP.xs
src/data/case-map.c
src/data/dataset.c
src/data/dictionary.c
src/language/lexer/variable-parser.c

index 1f05be2a65cf81ae626f9dc208ee182dec623508..573dfab42afaf8603406392a4fd1fce65387ad64 100644 (file)
@@ -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))
   {
index ed32db0d3fc940cf9d14cd74de02889b9a6721a0..87174f1fb3a4e37eb90064b5ab3f78f81aa9d894 100644 (file)
@@ -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++);
     }
 
index 450383fb875df81a71807ae7326de0768214330b..aa196f2850d84b5df9bf776302a0db62221bc837 100644 (file)
@@ -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);
         }
index 1dffcb542f36faa457438a15e0ce1ab2094ab735..a2a622c93765cef2cbfef731d7961d6f05d650e7 100644 (file)
@@ -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;
index 8b577578e721eb600b8c196f99185ecc3e954304..57f7042eca11cae9702a7f71a80aeea1774dffe4 100644 (file)
@@ -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;