value: Get rid of value_str(), value_str_rw(), value_num().
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 22 Jul 2019 00:16:36 +0000 (17:16 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 22 Jul 2019 00:27:03 +0000 (17:27 -0700)
These can now all be replaced now by plain ->s or ->f, which is
shorter and clearer anyway.

27 files changed:
doc/dev/concepts.texi
perl-module/PSPP.xs
src/data/case-tmpfile.c
src/data/case.c
src/data/data-in.c
src/data/data-out.c
src/data/datasheet.c
src/data/mdd-writer.c
src/data/missing-values.c
src/data/pc+-file-reader.c
src/data/por-file-writer.c
src/data/psql-reader.c
src/data/sys-file-reader.c
src/data/sys-file-writer.c
src/data/value.c
src/data/value.h
src/language/data-io/matrix-data.c
src/language/data-io/matrix-reader.c
src/language/dictionary/mrsets.c
src/language/stats/aggregate.c
src/language/stats/autorecode.c
src/language/xforms/recode.c
src/output/pivot-table.c
src/ui/gui/psppire-dialog-action-indep-samps.c
src/ui/gui/spreadsheet-test.c
src/ui/syntax-gen.c
tests/data/datasheet-test.c

index 8d1e8ac0663604ba526332fa7c9bcf8653955f8e..e3dcf1673028b1df6a632421b74d3c58f077b606 100644 (file)
@@ -156,27 +156,6 @@ This function returns false if @func{value_init} and
 @func{value_destroy} are actually required for the given @var{width}.
 @end deftypefun
 
-@deftypefun double value_num (const union value *@var{value})
-Returns the numeric value in @var{value}, which must have been
-initialized as a numeric value.  Equivalent to @code{@var{value}->f}.
-@end deftypefun
-
-@deftypefun {const char *} value_str (const union value *@var{value}, int @var{width})
-@deftypefunx {char *} value_str_rw (union value *@var{value}, int @var{width})
-Returns the string value in @var{value}, which must have been
-initialized with positive width @var{width}.  The string returned is
-not null-terminated.  Only @var{width} bytes of returned data may be
-accessed.
-
-The two different functions exist only for @code{const}-correctness.
-Otherwise they are identical.
-
-It is important that @var{width} be the correct value that was passed
-to @func{value_init}.  Passing a smaller or larger value (e.g.@:
-because that number of bytes will be accessed) will not always work
-and should be avoided.
-@end deftypefun
-
 @deftypefun void value_copy (union value *@var{dst}, @
                              const union value *@var{src}, @
                              int @var{width})
index c563b40f6330785c48f42d1efa30749b8d4345a1..ba43fa58a8b33f22e1e1c356a8cb42ccced5f65a 100644 (file)
@@ -141,7 +141,7 @@ scalar_to_value (union value *val, SV *scalar, const struct variable *var)
        const char *p = SvPV (scalar, len);
        int width = var_get_width (var);
        value_set_missing (val, width);
-       memcpy (value_str_rw (val, width), p, len);
+       memcpy (val->s, p, len);
     }
 }
 
@@ -159,7 +159,7 @@ value_to_scalar (const union value *val, const struct variable *var)
   else
     {
       int width = var_get_width (var);
-      return newSVpvn (value_str (val, width), width);
+      return newSVpvn (val->s, width);
     }
 }
 
index 2b124341b67820f8be89c6f3224c1a48a4fcae52..0290f51126380366a233e8a3e5dc1f6eb8c22a68 100644 (file)
@@ -56,7 +56,7 @@ value_to_data (const union value *value_, int width)
   if (width == 0)
     return &value->f;
   else
-    return value_str_rw (value, width);
+    return value->s;
 }
 
 /* Creates and returns a new case_tmpfile that will store cases
index 60704185a6a105b5a5730447c9a018919fc5bac1..e879f6ac2559fbf84559652796d6acbae69e6705 100644 (file)
@@ -333,8 +333,7 @@ const uint8_t *
 case_str (const struct ccase *c, const struct variable *v)
 {
   assert_variable_matches_case (c, v);
-  size_t idx = var_get_case_index (v);
-  return value_str (&c->values[idx], caseproto_get_width (c->proto, idx));
+  return c->values[var_get_case_index (v)].s;
 }
 
 /* Returns the string value of the `union value' in C numbered
@@ -346,7 +345,7 @@ const uint8_t *
 case_str_idx (const struct ccase *c, size_t idx)
 {
   assert (idx < c->proto->n_widths);
-  return value_str (&c->values[idx], caseproto_get_width (c->proto, idx));
+  return c->values[idx].s;
 }
 
 /* Returns the string value of the `union value' in C for
@@ -363,7 +362,7 @@ case_str_rw (struct ccase *c, const struct variable *v)
   assert_variable_matches_case (c, v);
   size_t idx = var_get_case_index (v);
   assert (!case_is_shared (c));
-  return value_str_rw (&c->values[idx], caseproto_get_width (c->proto, idx));
+  return c->values[idx].s;
 }
 
 /* Returns the string value of the `union value' in C numbered
@@ -378,7 +377,7 @@ case_str_rw_idx (struct ccase *c, size_t idx)
 {
   assert (idx < c->proto->n_widths);
   assert (!case_is_shared (c));
-  return value_str_rw (&c->values[idx], caseproto_get_width (c->proto, idx));
+  return c->values[idx].s;
 }
 
 /* Compares the values of the N_VARS variables in VP
index bf7e44e91879d943ca432f177fbf0917a8435467..33eeb111384971179087e368c3bff10005ce8b54 100644 (file)
@@ -699,7 +699,7 @@ parse_A (struct data_in *i)
 {
   /* This is equivalent to buf_copy_rpad, except that we posibly
      do a character set recoding in the middle. */
-  uint8_t *dst = value_str_rw (i->output, i->width);
+  uint8_t *dst = i->output->s;
   size_t dst_size = i->width;
   const char *src = ss_data (i->input);
   size_t src_size = ss_length (i->input);
@@ -716,7 +716,7 @@ parse_A (struct data_in *i)
 static char *
 parse_AHEX (struct data_in *i)
 {
-  uint8_t *s = value_str_rw (i->output, i->width);
+  uint8_t *s = i->output->s;
   size_t j;
 
   for (j = 0; ; j++)
@@ -1246,7 +1246,7 @@ static void
 default_result (struct data_in *i)
 {
   if (fmt_is_string (i->format))
-    memset (value_str_rw (i->output, i->width), ' ', i->width);
+    memset (i->output->s, ' ', i->width);
   else
     i->output->f = settings_get_blanks ();
 }
index cb21600a72962bdddcb47eda87dd494db913e7da..cbd114b8e58cf8399caba921df0c12168cca4b90 100644 (file)
@@ -113,7 +113,7 @@ data_out_recode (const union value *input, const char *input_encoding,
   assert (fmt_check_output (format));
   if (format->type == FMT_A)
     {
-      char *in = CHAR_CAST (char *, value_str (input, format->w));
+      char *in = CHAR_CAST (char *, input->s);
       char *out = recode_string (output_encoding, input_encoding,
                                  in, format->w);
       ds_put_cstr (output, out);
@@ -170,7 +170,7 @@ data_out_pool (const union value *input, const char *input_encoding,
   assert (fmt_check_output (format));
   if (format->type == FMT_A)
     {
-      char *in = CHAR_CAST (char *, value_str (input, format->w));
+      char *in = CHAR_CAST (char *, input->s);
       return recode_string_pool (UTF8, input_encoding, in, format->w, pool);
     }
   else if (fmt_get_category (format->type) == FMT_CAT_BINARY)
@@ -621,7 +621,7 @@ static void
 output_AHEX (const union value *input, const struct fmt_spec *format,
              char *output)
 {
-  output_hex (value_str (input, format->w / 2), format->w / 2, output);
+  output_hex (input->s, format->w / 2, output);
 }
 \f
 /* Decimal and scientific formatting. */
index e9d2b2f3528f8aef209809df6677b4e76e0dc047..ef2024873b72eb432f35a9164009e6b41ea7d36b 100644 (file)
@@ -175,7 +175,7 @@ value_to_data (const union value *value_, int width)
   if (width == 0)
     return &value->f;
   else
-    return value_str_rw (value, width);
+    return value->s;
 }
 
 /* Returns the number of bytes needed to store all the values in
index 495be8cafea8c1127eab718bec0209eee6110936..3db5f2bd3f22eb3168e4f6e1d7af7b570f7ed01c 100644 (file)
@@ -288,7 +288,7 @@ write_value_label_value (xmlTextWriter *writer, const struct val_lab *vl,
   const union value *value = val_lab_get_value (vl);
   if (width)
     {
-      char *s = xmemdup0 (value_str (value, width), width);
+      char *s = xmemdup0 (value->s, width);
       xmlTextWriterWriteAttribute (writer, _xml ("value"), _xml (s));
       free (s);
     }
index 742ddd2acfe7891682ec5da39f79db867e36bd82..0126651638d613bec4b20de3cb2b12b455ff3312 100644 (file)
@@ -115,7 +115,7 @@ mv_is_acceptable (const union value *value, int width)
   int i;
 
   for (i = MV_MAX_STRING; i < width; i++)
-    if (value_str (value, width)[i] != ' ')
+    if (value->s[i] != ' ')
       return false;
   return true;
 }
@@ -177,7 +177,7 @@ mv_add_str (struct missing_values *mv, const uint8_t s[], size_t len)
       return false;
 
   value_init (&v, mv->width);
-  buf_copy_rpad (CHAR_CAST (char *, value_str_rw (&v, mv->width)), mv->width,
+  buf_copy_rpad (CHAR_CAST (char *, v.s), mv->width,
                  CHAR_CAST (char *, s), len, ' ');
   ok = mv_add_value (mv, &v);
   value_destroy (&v, mv->width);
@@ -424,14 +424,14 @@ is_str_user_missing (const struct missing_values *mv, const uint8_t s[])
     case MVT_NONE:
       return false;
     case MVT_1:
-      return !memcmp (value_str (&v[0], mv->width), s, mv->width);
+      return !memcmp (v[0].s, s, mv->width);
     case MVT_2:
-      return (!memcmp (value_str (&v[0], mv->width), s, mv->width)
-              || !memcmp (value_str (&v[1], mv->width), s, mv->width));
+      return (!memcmp (v[0].s, s, mv->width)
+              || !memcmp (v[1].s, s, mv->width));
     case MVT_3:
-      return (!memcmp (value_str (&v[0], mv->width), s, mv->width)
-              || !memcmp (value_str (&v[1], mv->width), s, mv->width)
-              || !memcmp (value_str (&v[2], mv->width), s, mv->width));
+      return (!memcmp (v[0].s, s, mv->width)
+              || !memcmp (v[1].s, s, mv->width)
+              || !memcmp (v[2].s, s, mv->width));
     case MVT_RANGE:
     case MVT_RANGE_1:
       NOT_REACHED ();
@@ -447,7 +447,7 @@ mv_is_value_missing (const struct missing_values *mv, const union value *v,
 {
   return (mv->width == 0
           ? mv_is_num_missing (mv, v->f, class)
-          : mv_is_str_missing (mv, value_str (v, mv->width), class));
+          : mv_is_str_missing (mv, v->s, class));
 }
 
 /* Returns true if D is a missing value in the given CLASS in MV,
@@ -501,8 +501,7 @@ mv_to_string (const struct missing_values *mv, const char *encoding)
       else
         {
           char *mvs = recode_string (
-            "UTF-8", encoding,
-            CHAR_CAST (char *, value_str (value, mv->width)),
+            "UTF-8", encoding, CHAR_CAST (char *, value->s),
             MIN (mv->width, MV_MAX_STRING));
           ds_put_format (&s, "\"%s\"", mvs);
           free (mvs);
index d9904ef430ea289c798b7d05fc6a31fb9e0ba486..c7c9e3b7f8b062b75d3e57c0ed5be2a262e34fe5 100644 (file)
@@ -900,8 +900,7 @@ parse_variable_records (struct pcp_reader *r, struct dictionary *dict,
           if (var_is_numeric (var))
             value.f = parse_float (rec->val_labs[i].value);
           else
-            memcpy (value_str_rw (&value, rec->width),
-                    rec->val_labs[i].value, rec->width);
+            memcpy (value.s, rec->val_labs[i].value, rec->width);
 
           utf8_label = recode_string ("UTF-8", dict_encoding,
                                       rec->val_labs[i].label, -1);
@@ -967,8 +966,7 @@ pcp_file_casereader_read (struct casereader *reader, void *r_)
       if (var->width == 0)
         retval = read_case_number (r, &v->f);
       else
-        retval = read_case_string (r, value_str_rw (v, var->width),
-                                   var->width);
+        retval = read_case_string (r, v->s, var->width);
 
       if (retval != 1)
         {
index f5507522b7a81adf0684c13b0f242f58be0e37f0..5795b817dcf2b9cefafb42d342fe715ac96f1117 100644 (file)
@@ -316,7 +316,7 @@ write_value (struct pfm_writer *w, const union value *v, int width)
     {
       width = MIN (width, MAX_POR_WIDTH);
       write_int (w, width);
-      buf_write (w, value_str (v, width), width);
+      buf_write (w, v->s, width);
     }
 }
 
index 4a49ba0cf92c413c551811b1ce1a87dd9e64c062..c6f03250ddced18199b64af59351e0da9f5e6814 100644 (file)
@@ -840,8 +840,7 @@ set_value (struct psql_reader *r)
            case VARCHAROID:
            case BPCHAROID:
            case BYTEAOID:
-             memcpy (value_str_rw (val, var_width), vptr,
-                      MIN (length, var_width));
+             memcpy (val->s, vptr, MIN (length, var_width));
              break;
 
            case NUMERICOID:
index af8f1b457678e60c5a927969e737d39cc169c4f9..e0b43b9205c59db8b777baacc7c65b1125f1b616 100644 (file)
@@ -2213,7 +2213,7 @@ parse_value_labels (struct sfm_reader *r, struct dictionary *dict,
           if (width == 0)
             value.f = parse_float (r, label->value, 0);
           else
-            memcpy (value_str_rw (&value, width), label->value, width);
+            memcpy (value.s, label->value, width);
 
           if (!var_add_value_label (var, &value, utf8_labels[j]))
             {
@@ -2232,8 +2232,7 @@ parse_value_labels (struct sfm_reader *r, struct dictionary *dict,
               else
                 sys_warn (r, record->pos,
                           _("Duplicate value label for `%.*s' on %s."),
-                          width, value_str (&value, width),
-                          var_get_name (var));
+                          width, value.s, var_get_name (var));
             }
 
           value_destroy (&value, width);
@@ -2520,8 +2519,7 @@ parse_long_string_value_labels (struct sfm_reader *r,
           if (!skip)
             {
               if (value_length == width)
-                memcpy (value_str_rw (&value, width),
-                        (const uint8_t *) record->data + ofs, width);
+                memcpy (value.s, (const uint8_t *) record->data + ofs, width);
               else
                 {
                   sys_warn (r, record->pos + ofs,
@@ -2553,8 +2551,7 @@ parse_long_string_value_labels (struct sfm_reader *r,
               if (!var_add_value_label (var, &value, label))
                 sys_warn (r, record->pos + ofs,
                           _("Duplicate value label for `%.*s' on %s."),
-                          width, value_str (&value, width),
-                          var_get_name (var));
+                          width, value.s, var_get_name (var));
               pool_free (r->pool, label);
             }
           ofs += label_length;
@@ -2688,8 +2685,7 @@ sys_file_casereader_read (struct casereader *reader, void *r_)
         retval = read_case_number (r, &v->f);
       else
         {
-          uint8_t *s = value_str_rw (v, sv->var_width);
-          retval = read_case_string (r, s + sv->offset, sv->segment_width);
+          retval = read_case_string (r, v->s + sv->offset, sv->segment_width);
           if (retval == 1)
             {
               retval = skip_whole_strings (r, ROUND_DOWN (sv->padding, 8));
index b655f44073a353737d526a32f0b7159bea2e28c5..eb9f8e93b611a54aab26980d0f8070c91a0f9b87 100644 (file)
@@ -854,8 +854,7 @@ write_mrsets (struct sfm_writer *w, const struct dictionary *dict,
           if (mrset->width == 0)
             counted = xasprintf ("%.0f", mrset->counted.f);
           else
-            counted = xmemdup0 (value_str (&mrset->counted, mrset->width),
-                                mrset->width);
+            counted = xmemdup0 (mrset->counted.s, mrset->width);
           ds_put_format (&s, "%zu %s", strlen (counted), counted);
           free (counted);
         }
@@ -1010,8 +1009,7 @@ write_long_string_value_labels (struct sfm_writer *w,
           size_t len;
 
           write_int (w, width);
-          write_bytes (w, value_str (val_lab_get_value (val_lab), width),
-                       width);
+          write_bytes (w, val_lab_get_value (val_lab)->s, width);
 
           label = recode_string (var_get_encoding (var), "UTF-8",
                                  val_lab_get_escaped_label (val_lab), -1);
@@ -1080,7 +1078,7 @@ write_long_string_missing_values (struct sfm_writer *w,
           const union value *value = mv_get_value (mv, j);
 
           write_int (w, 8);
-          write_bytes (w, value_str (value, width), 8);
+          write_bytes (w, value->s, 8);
         }
     }
 }
@@ -1593,7 +1591,7 @@ write_value (struct sfm_writer *w, const union value *value, int width)
     write_float (w, value->f);
   else
     {
-      write_bytes (w, value_str (value, width), width);
+      write_bytes (w, value->s, width);
       write_zeros (w, 8 - width);
     }
 }
index 1d27083552696e978f7d5e1980d8ec9fb4391970..bbe96b19805a7060945e26bc6eb1ec4d60810583 100644 (file)
@@ -46,9 +46,7 @@ value_copy_rpad (union value *dst, int dst_width,
                  const union value *src, int src_width,
                  char pad)
 {
-  u8_buf_copy_rpad (value_str_rw (dst, dst_width), dst_width,
-                 value_str (src, src_width), src_width,
-                 pad);
+  u8_buf_copy_rpad (dst->s, dst_width, src->s, src_width, pad);
 }
 
 /* Copies the contents of null-terminated string SRC to string
@@ -85,7 +83,7 @@ void
 value_copy_buf_rpad (union value *dst, int dst_width,
                      const uint8_t *src, size_t src_len, char pad)
 {
-  u8_buf_copy_rpad (value_str_rw (dst, dst_width), dst_width, src, src_len, pad);
+  u8_buf_copy_rpad (dst->s, dst_width, src, src_len, pad);
 }
 
 /* Sets V to the system-missing value for data of the given
@@ -98,7 +96,7 @@ value_set_missing (union value *v, int width)
       if (width == 0)
         v->f = SYSMIS;
       else
-        memset (value_str_rw (v, width), ' ', width);
+        memset (v->s, ' ', width);
     }
 }
 
@@ -109,7 +107,7 @@ value_compare_3way (const union value *a, const union value *b, int width)
 {
   return (width == -1 ? 0
           : width == 0 ? (a->f < b->f ? -1 : a->f > b->f)
-          : memcmp (value_str (a, width), value_str (b, width), width));
+          : memcmp (a->s, b->s, width));
 }
 
 /* Returns true if A and B, which must both have the given WIDTH,
@@ -119,7 +117,7 @@ value_equal (const union value *a, const union value *b, int width)
 {
   return (width == -1 ? true
           : width == 0 ? a->f == b->f
-          : !memcmp (value_str (a, width), value_str (b, width), width));
+          : !memcmp (a->s, b->s, width));
 }
 
 /* Returns a hash of the data in VALUE, which must have the given
@@ -129,7 +127,7 @@ value_hash (const union value *value, int width, unsigned int basis)
 {
   return (width == -1 ? basis
           : width == 0 ? hash_double (value->f, basis)
-          : hash_bytes (value_str (value, width), width, basis));
+          : hash_bytes (value->s, width, basis));
 }
 
 /* Tests whether VALUE may be resized from OLD_WIDTH to
@@ -147,7 +145,7 @@ value_is_resizable (const union value *value, int old_width, int new_width)
     return false;
   else
     {
-      const uint8_t *str = value_str (value, old_width);
+      const uint8_t *str = value->s;
       int i;
 
       for (i = new_width; i < old_width; i++)
@@ -178,11 +176,10 @@ value_resize (union value *value, int old_width, int new_width)
 bool
 value_is_spaces (const union value *value, int width)
 {
-  const uint8_t *s = value_str (value, width);
   int i;
 
   for (i = 0; i < width; i++)
-    if (s[i] != ' ')
+    if (value->s[i] != ' ')
       return false;
 
   return true;
@@ -248,10 +245,9 @@ value_resize_pool (struct pool *pool, union value *value,
   if (new_width > old_width)
     {
       uint8_t *new_string = pool_alloc_unaligned (pool, new_width);
-      memcpy (new_string, value_str (value, old_width), old_width);
+      memcpy (new_string, value->s, old_width);
       value->s = new_string;
 
-      memset (value_str_rw (value, new_width) + old_width, ' ',
-              new_width - old_width);
+      memset (value->s + old_width, ' ', new_width - old_width);
     }
 }
index 4d5177460858926006ac7b5dd1d47ebb4bb0e676..8e624a8464b73163e9638c88c26dff5fa6a444cd 100644 (file)
@@ -39,10 +39,6 @@ static inline bool value_needs_init (int width);
 static inline bool value_try_init (union value *, int width);
 static inline void value_destroy (union value *, int width);
 
-static inline double value_num (const union value *);
-static inline const uint8_t *value_str (const union value *, int width);
-static inline uint8_t *value_str_rw (union value *, int width);
-
 static inline void value_copy (union value *, const union value *, int width);
 void value_copy_rpad (union value *, int dst_width,
                       const union value *, int src_width,
@@ -133,41 +129,6 @@ value_destroy (union value *v, int width)
     free (v->s);
 }
 
-/* Returns the numeric value in V, which must have width 0. */
-static inline double
-value_num (const union value *v)
-{
-  return v->f;
-}
-
-/* Returns the string value in V, which must have width WIDTH.
-
-   The returned value is not null-terminated.
-
-   It is important that WIDTH be the actual value that was passed
-   to value_init.  Passing, e.g., a smaller value because only
-   that number of bytes will be accessed will not always work. */
-static inline const uint8_t *
-value_str (const union value *v, int width)
-{
-  assert (width > 0);
-  return v->s;
-}
-
-/* Returns the string value in V, which must have width WIDTH.
-
-   The returned value is not null-terminated.
-
-   It is important that WIDTH be the actual value that was passed
-   to value_init.  Passing, e.g., a smaller value because only
-   that number of bytes will be accessed will not always work. */
-static inline uint8_t *
-value_str_rw (union value *v, int width)
-{
-  assert (width > 0);
-  return v->s;
-}
-
 /* Copies SRC to DST, given that they both contain data of the
    given WIDTH. */
 static inline void
index cd962e1f25e182add5bd032819e0983b7b374c7d..7676bb1de0157d45c0c74ead6f2a18c387378cc6 100644 (file)
@@ -106,16 +106,16 @@ set_varname_column (struct ccase *outcase, const struct variable *vname,
      const char *str)
 {
   int len = var_get_width (vname);
-  uint8_t *s = value_str_rw (case_data_rw (outcase, vname), len);
+  uint8_t *s = case_str_rw (outcase, vname);
 
-  strncpy ((char *) s, str, len);
+  strncpy (CHAR_CAST (char *, s), str, len);
 }
 
 static void
 blank_varname_column (struct ccase *outcase, const struct variable *vname)
 {
   int len = var_get_width (vname);
-  uint8_t *s = value_str_rw (case_data_rw (outcase, vname), len);
+  uint8_t *s = case_str_rw (outcase, vname);
 
   memset (s, ' ', len);
 }
@@ -181,7 +181,7 @@ preprocess (struct casereader *casereader0, const struct dictionary *dict, void
       if (mformat->triangle == UPPER && mformat->diagonal == NO_DIAGONAL)
        c_offset++;
       const union value *v = case_data (c, mformat->rowtype);
-      const char *val = (const char *) value_str (v, ROWTYPE_WIDTH);
+      const char *val = CHAR_CAST (const char *, v->s);
       if (0 == strncasecmp (val, "corr    ", ROWTYPE_WIDTH) ||
          0 == strncasecmp (val, "cov     ", ROWTYPE_WIDTH))
        {
@@ -230,8 +230,7 @@ preprocess (struct casereader *casereader0, const struct dictionary *dict, void
       int col;
       struct ccase *outcase = case_create (proto);
       union value *v = case_data_rw (outcase, mformat->rowtype);
-      uint8_t *n = value_str_rw (v, ROWTYPE_WIDTH);
-      memcpy (n, "N       ", ROWTYPE_WIDTH);
+      memcpy (v->s, "N       ", ROWTYPE_WIDTH);
       blank_varname_column (outcase, mformat->varname);
       for (col = 0; col < mformat->n_continuous_vars; ++col)
        {
@@ -280,7 +279,7 @@ preprocess (struct casereader *casereader0, const struct dictionary *dict, void
 
       case_unref (prev_case);
       const union value *v = case_data (c, mformat->rowtype);
-      const char *val = (const char *) value_str (v, ROWTYPE_WIDTH);
+      const char *val = CHAR_CAST (const char *, v->s);
       if (mformat->n >= 0)
        {
          if (0 == strncasecmp (val, "n       ", ROWTYPE_WIDTH) ||
index 3a7e6ef056f16afd6ca5e5abaafc0d93da88a4df..963f4a24f152a1227955a5a58159bf196c730775 100644 (file)
@@ -222,19 +222,20 @@ next_matrix_from_reader (struct matrix_material *mm,
   struct ccase *c;
   for ( ; (c = casereader_read (group) ); case_unref (c))
     {
-      const union value *uv  = case_data (c, mr->rowtype);
+      const union value *uv = case_data (c, mr->rowtype);
+      const char *row_type = CHAR_CAST (const char *, uv->s);
       int col, row;
       for (col = 0; col < n_vars; ++col)
        {
          const struct variable *cv = vars[col];
          double x = case_data (c, cv)->f;
-         if (0 == strncasecmp ((char *)value_str (uv, 8), "N       ", 8))
+         if (0 == strncasecmp (row_type, "N       ", 8))
            for (row = 0; row < n_vars; ++row)
              gsl_matrix_set (mr->n_vectors, row, col, x);
-         else if (0 == strncasecmp ((char *) value_str (uv, 8), "MEAN    ", 8))
+         else if (0 == strncasecmp (row_type, "MEAN    ", 8))
            for (row = 0; row < n_vars; ++row)
              gsl_matrix_set (mr->mean_vectors, row, col, x);
-         else if (0 == strncasecmp ((char *) value_str (uv, 8), "STDDEV  ", 8))
+         else if (0 == strncasecmp (row_type, "STDDEV  ", 8))
            for (row = 0; row < n_vars; ++row)
              gsl_matrix_set (mr->var_vectors, row, col, x * x);
        }
@@ -263,11 +264,11 @@ next_matrix_from_reader (struct matrix_material *mm,
       if (mrow == -1)
        continue;
 
-      if (0 == strncasecmp ((char *) value_str (uv, 8), "CORR    ", 8))
+      if (0 == strncasecmp (row_type, "CORR    ", 8))
        {
          matrix_fill_row (&mm->corr, c, mrow, vars, n_vars);
        }
-      else if (0 == strncasecmp ((char *) value_str (uv, 8), "COV     ", 8))
+      else if (0 == strncasecmp (row_type, "COV     ", 8))
        {
          matrix_fill_row (&mm->cov, c, mrow, vars, n_vars);
        }
index 97ab2c1fb4ffdded42110f9812ef73d3454a777b..4a01ddd49f165c84ed1906bc93e037e14193a4be 100644 (file)
@@ -170,7 +170,7 @@ parse_group (struct lexer *lexer, struct dictionary *dict,
 
               value_destroy (&mrset->counted, mrset->width);
               value_init (&mrset->counted, width);
-              memcpy (value_str_rw (&mrset->counted, width), s, width);
+              memcpy (mrset->counted.s, s, width);
               mrset->width = width;
 
               free (s);
index 5a4b41e1abbec582fa474ed9909aa0ae133afd4a..c0d1438ecb4849609b00c1a8a5c68516de41dd5a 100644 (file)
@@ -810,8 +810,8 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input)
            break;
          case MAX | FSTRING:
             /* Need to do some kind of Unicode collation thingy here */
-           if (memcmp (iter->string, value_str (v, src_width), src_width) < 0)
-             memcpy (iter->string, value_str (v, src_width), src_width);
+           if (memcmp (iter->string, v->s, src_width) < 0)
+             memcpy (iter->string, v->s, src_width);
            iter->int1 = 1;
            break;
          case MIN:
@@ -819,8 +819,8 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input)
            iter->int1 = 1;
            break;
          case MIN | FSTRING:
-           if (memcmp (iter->string, value_str (v, src_width), src_width) > 0)
-             memcpy (iter->string, value_str (v, src_width), src_width);
+           if (memcmp (iter->string, v->s, src_width) > 0)
+             memcpy (iter->string, v->s, src_width);
            iter->int1 = 1;
            break;
          case FGT:
@@ -831,8 +831,7 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input)
             break;
          case FGT | FSTRING:
          case PGT | FSTRING:
-            if (memcmp (iter->arg[0].c,
-                        value_str (v, src_width), src_width) < 0)
+            if (memcmp (iter->arg[0].c, v->s, src_width) < 0)
               iter->dbl[0] += weight;
             iter->dbl[1] += weight;
             break;
@@ -844,8 +843,7 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input)
             break;
          case FLT | FSTRING:
          case PLT | FSTRING:
-            if (memcmp (iter->arg[0].c,
-                        value_str (v, src_width), src_width) > 0)
+            if (memcmp (iter->arg[0].c, v->s, src_width) > 0)
               iter->dbl[0] += weight;
             iter->dbl[1] += weight;
             break;
@@ -857,10 +855,8 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input)
             break;
          case FIN | FSTRING:
          case PIN | FSTRING:
-            if (memcmp (iter->arg[0].c,
-                        value_str (v, src_width), src_width) <= 0
-                && memcmp (iter->arg[1].c,
-                           value_str (v, src_width), src_width) >= 0)
+            if (memcmp (iter->arg[0].c, v->s, src_width) <= 0
+                && memcmp (iter->arg[1].c, v->s, src_width) >= 0)
               iter->dbl[0] += weight;
             iter->dbl[1] += weight;
             break;
@@ -872,10 +868,8 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input)
             break;
          case FOUT | FSTRING:
          case POUT | FSTRING:
-            if (memcmp (iter->arg[0].c,
-                        value_str (v, src_width), src_width) > 0
-                || memcmp (iter->arg[1].c,
-                           value_str (v, src_width), src_width) < 0)
+            if (memcmp (iter->arg[0].c, v->s, src_width) > 0
+                || memcmp (iter->arg[1].c, v->s, src_width) < 0)
               iter->dbl[0] += weight;
             iter->dbl[1] += weight;
             break;
@@ -897,7 +891,7 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input)
          case FIRST | FSTRING:
            if (iter->int1 == 0)
              {
-               memcpy (iter->string, value_str (v, src_width), src_width);
+               memcpy (iter->string, v->s, src_width);
                iter->int1 = 1;
              }
            break;
@@ -906,7 +900,7 @@ accumulate_aggregate_info (struct agr_proc *agr, const struct ccase *input)
            iter->int1 = 1;
            break;
          case LAST | FSTRING:
-           memcpy (iter->string, value_str (v, src_width), src_width);
+           memcpy (iter->string, v->s, src_width);
            iter->int1 = 1;
            break;
           case NMISS:
@@ -1024,7 +1018,7 @@ dump_aggregate_info (const struct agr_proc *agr, struct casewriter *output, cons
          case MAX | FSTRING:
          case MIN | FSTRING:
            if (i->int1)
-             memcpy (value_str_rw (v, width), i->string, width);
+             memcpy (v->s, i->string, width);
            else
               value_set_missing (v, width);
            break;
@@ -1063,7 +1057,7 @@ dump_aggregate_info (const struct agr_proc *agr, struct casewriter *output, cons
          case FIRST | FSTRING:
          case LAST | FSTRING:
            if (i->int1)
-             memcpy (value_str_rw (v, width), i->string, width);
+             memcpy (v->s, i->string, width);
            else
               value_set_missing (v, width);
            break;
index aabef142e10731a4b299b5917872485e661a7014..e7d06a818ddfa7c8d860943d82d492696d0d9111 100644 (file)
@@ -105,7 +105,7 @@ static bool
 value_is_blank (const union value *val, int width, const struct dictionary *dict)
 {
   mbi_iterator_t iter;
-  const char *str = CHAR_CAST_BUG (const char*, value_str (val, width));
+  const char *str = CHAR_CAST_BUG (const char *, val->s);
   char *text = recode_string (UTF8, dict_get_encoding (dict), str, width);
 
   for (mbi_init (iter, text, width); mbi_avail (iter); mbi_advance (iter))
@@ -324,7 +324,7 @@ cmd_autorecode (struct lexer *lexer, struct dataset *ds)
             the source value from whence the new value comes. */
          if (src_width > 0)
            {
-             const char *str = CHAR_CAST_BUG (const char*, value_str (from, src_width));
+             const char *str = CHAR_CAST_BUG (const char *, from->s);
 
              recoded_value = recode_string (UTF8, dict_get_encoding (dict),
                                              str, src_width);
@@ -433,8 +433,8 @@ compare_arc_items (const void *a_, const void *b_, const void *aux UNUSED)
   if ( width_b == 0 && width_a != 0)
     return +1;
 
-  return buf_compare_rpad (CHAR_CAST_BUG (const char *, value_str (&(*a)->from, width_a)), width_a,
-                          CHAR_CAST_BUG (const char *, value_str (&(*b)->from, width_b)), width_b);
+  return buf_compare_rpad (CHAR_CAST_BUG (const char *, (*a)->from.s), width_a,
+                          CHAR_CAST_BUG (const char *, (*b)->from.s), width_b);
 }
 
 static int
index 361b5a64f867b27b20d4f69c1c7d968b3c79280d..4f8acf6bbb9d1f05db5cdf707eafd9787c3dd306 100644 (file)
@@ -452,7 +452,7 @@ set_map_out_str (struct map_out *out, struct pool *pool,
 
   out->copy_input = false;
   value_init_pool (pool, &out->value, length);
-  memcpy (value_str_rw (&out->value, length), string, length);
+  memcpy (out->value.s, string, length);
   out->width = length;
 }
 
@@ -656,8 +656,7 @@ find_src_string (struct recode_trns *trns, const uint8_t *value,
       switch (in->type)
         {
         case MAP_SINGLE:
-          match = !memcmp (value, value_str (&in->x, trns->max_src_width),
-                           width);
+          match = !memcmp (value, in->x.s, width);
           break;
         case MAP_ELSE:
           match = true;
@@ -722,8 +721,7 @@ recode_trns_proc (void *trns_, struct ccase **c, casenumber case_idx UNUSED)
           if (out != NULL)
             {
               if (!out->copy_input)
-                memcpy (dst, value_str (&out->value, trns->max_dst_width),
-                        var_get_width (dst_var));
+                memcpy (dst, out->value.s, var_get_width (dst_var));
               else if (trns->src_vars != trns->dst_vars)
                 {
                   union value *dst_data = case_data_rw (*c, dst_var);
index 092ebfc53a9564da3d9488a3972a87231ce8f527..dc15285b48b130d0eb94b9b5ca2e2d6c557cfb6b 100644 (file)
@@ -2024,8 +2024,7 @@ pivot_value_new_value (const union value *value, int width,
   struct pivot_value *pv = xzalloc (sizeof *pv);
   if (width > 0)
     {
-      char *s = recode_string (UTF8, encoding,
-                               CHAR_CAST (char *, value_str (value, width)),
+      char *s = recode_string (UTF8, encoding, CHAR_CAST (char *, value->s),
                                width);
       size_t n = strlen (s);
       while (n > 0 && s[n - 1] == ' ')
index 7a2511ad6ea7f91780c4245a8bf9c945e48049c8..32db97ea13c2c7344d2887d07abdf88f0852f963 100644 (file)
@@ -270,9 +270,9 @@ on_grp_var_change (GtkEntry *entry, PsppireDialogActionIndepSamps *act)
         }
       else
         {
-         value_str_rw (&act->cut_point, width)[0] = '\0';
-         value_str_rw (&act->grp_val[0], width)[0] = '\0';
-         value_str_rw (&act->grp_val[1], width)[0] = '\0';
+         act->cut_point.s[0] = '\0';
+         act->grp_val[0].s[0] = '\0';
+         act->grp_val[1].s[0] = '\0';
         }
     }
 
index da63c0ff4a1210aebdf95188cfdb9ac005731118..b8ce870d4635a07917d882d9f479294d81be46df 100644 (file)
@@ -83,7 +83,7 @@ on_clicked (GtkButton *button, struct xxx *stuff)
        else
          {
            char *ss = xzalloc (width + 1);
-            memcpy (ss, value_str (val, width), width);
+            memcpy (ss, val->s, width);
 
            printf ("%s ", ss);
            free (ss);
index 93d52c79c05b0fcbf26a940142654ddd1173eb94..27e61e4253b476607f37ef4f3ddecfb005db9e19 100644 (file)
@@ -196,10 +196,8 @@ syntax_gen_value (struct string *output, const union value *value, int width,
   if (width == 0)
     syntax_gen_number (output, value->f, format);
   else
-    {
-      char *s = CHAR_CAST_BUG (char *, value_str (value, width));
-      syntax_gen_string (output, ss_buffer (s, width));
-    }
+    syntax_gen_string (output,
+                       ss_buffer (CHAR_CAST (const char *, value->s), width));
 }
 
 /* Appends <low> THRU <high> to OUTPUT.  If LOW is LOWEST, then
index e3dad3b32c8a9b826656c38e32dc1a278cc91671..5f903c4dd943bc86769a8332fa0c039819f6c737 100644 (file)
@@ -163,7 +163,7 @@ check_datasheet_casereader (struct mc *mc, struct casereader *reader,
                               "'%.*s' != '%.*s'",
                               row, col, n_rows, n_columns,
                               width, case_str_idx (c, col),
-                              width, value_str (&array[row][col], width));
+                              width, array[row][col].s);
                 }
             }
 
@@ -225,8 +225,8 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
                   mc_error (mc, "element %zu,%zu (of %zu,%zu) differs: "
                             "'%.*s' != '%.*s'",
                             row, col, n_rows, n_columns,
-                            width, value_str (&v, width),
-                            width, value_str (av, width));
+                            width, v.s,
+                            width, v.s);
                 difference = true;
               }
             value_destroy (&v, width);
@@ -249,7 +249,7 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
                   if (width == 0)
                     ds_put_format (&s, " %g", v->f);
                   else
-                    ds_put_format (&s, " '%.*s'", width, value_str (v, width));
+                    ds_put_format (&s, " '%.*s'", width, v->s);
                 }
               mc_error (mc, "%s", ds_cstr (&s));
             }
@@ -270,8 +270,7 @@ check_datasheet (struct mc *mc, struct datasheet *ds,
                   if (width == 0)
                     ds_put_format (&s, " %g", v.f);
                   else
-                    ds_put_format (&s, " '%.*s'",
-                                   width, value_str (&v, width));
+                    ds_put_format (&s, " '%.*s'", width, v.s);
                 }
               mc_error (mc, "%s", ds_cstr (&s));
             }
@@ -407,12 +406,11 @@ value_from_param (union value *value, int width, unsigned int idx)
   else
     {
       unsigned int hash = hash_int (idx, 0);
-      uint8_t *string = value_str_rw (value, width);
       int offset;
 
       assert (width < 32);
       for (offset = 0; offset < width; offset++)
-        string[offset] = "ABCDEFGHIJ"[(hash >> offset) % 10];
+        value->s[offset] = "ABCDEFGHIJ"[(hash >> offset) % 10];
     }
 }