From a49b940e58f148bf111c647d9b4822025636ff80 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Sun, 21 Jul 2019 17:16:36 -0700 Subject: [PATCH] value: Get rid of value_str(), value_str_rw(), value_num(). These can now all be replaced now by plain ->s or ->f, which is shorter and clearer anyway. --- doc/dev/concepts.texi | 21 ---------- perl-module/PSPP.xs | 4 +- src/data/case-tmpfile.c | 2 +- src/data/case.c | 9 ++--- src/data/data-in.c | 6 +-- src/data/data-out.c | 6 +-- src/data/datasheet.c | 2 +- src/data/mdd-writer.c | 2 +- src/data/missing-values.c | 21 +++++----- src/data/pc+-file-reader.c | 6 +-- src/data/por-file-writer.c | 2 +- src/data/psql-reader.c | 3 +- src/data/sys-file-reader.c | 14 +++---- src/data/sys-file-writer.c | 10 ++--- src/data/value.c | 24 +++++------- src/data/value.h | 39 ------------------- src/language/data-io/matrix-data.c | 13 +++---- src/language/data-io/matrix-reader.c | 13 ++++--- src/language/dictionary/mrsets.c | 2 +- src/language/stats/aggregate.c | 34 +++++++--------- src/language/stats/autorecode.c | 8 ++-- src/language/xforms/recode.c | 8 ++-- src/output/pivot-table.c | 3 +- .../gui/psppire-dialog-action-indep-samps.c | 6 +-- src/ui/gui/spreadsheet-test.c | 2 +- src/ui/syntax-gen.c | 6 +-- tests/data/datasheet-test.c | 14 +++---- 27 files changed, 96 insertions(+), 184 deletions(-) diff --git a/doc/dev/concepts.texi b/doc/dev/concepts.texi index 8d1e8ac066..e3dcf16730 100644 --- a/doc/dev/concepts.texi +++ b/doc/dev/concepts.texi @@ -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}) diff --git a/perl-module/PSPP.xs b/perl-module/PSPP.xs index c563b40f63..ba43fa58a8 100644 --- a/perl-module/PSPP.xs +++ b/perl-module/PSPP.xs @@ -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); } } diff --git a/src/data/case-tmpfile.c b/src/data/case-tmpfile.c index 2b124341b6..0290f51126 100644 --- a/src/data/case-tmpfile.c +++ b/src/data/case-tmpfile.c @@ -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 diff --git a/src/data/case.c b/src/data/case.c index 60704185a6..e879f6ac25 100644 --- a/src/data/case.c +++ b/src/data/case.c @@ -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 diff --git a/src/data/data-in.c b/src/data/data-in.c index bf7e44e918..33eeb11138 100644 --- a/src/data/data-in.c +++ b/src/data/data-in.c @@ -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 (); } diff --git a/src/data/data-out.c b/src/data/data-out.c index cb21600a72..cbd114b8e5 100644 --- a/src/data/data-out.c +++ b/src/data/data-out.c @@ -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); } /* Decimal and scientific formatting. */ diff --git a/src/data/datasheet.c b/src/data/datasheet.c index e9d2b2f352..ef2024873b 100644 --- a/src/data/datasheet.c +++ b/src/data/datasheet.c @@ -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 diff --git a/src/data/mdd-writer.c b/src/data/mdd-writer.c index 495be8cafe..3db5f2bd3f 100644 --- a/src/data/mdd-writer.c +++ b/src/data/mdd-writer.c @@ -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); } diff --git a/src/data/missing-values.c b/src/data/missing-values.c index 742ddd2acf..0126651638 100644 --- a/src/data/missing-values.c +++ b/src/data/missing-values.c @@ -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); diff --git a/src/data/pc+-file-reader.c b/src/data/pc+-file-reader.c index d9904ef430..c7c9e3b7f8 100644 --- a/src/data/pc+-file-reader.c +++ b/src/data/pc+-file-reader.c @@ -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) { diff --git a/src/data/por-file-writer.c b/src/data/por-file-writer.c index f5507522b7..5795b817dc 100644 --- a/src/data/por-file-writer.c +++ b/src/data/por-file-writer.c @@ -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); } } diff --git a/src/data/psql-reader.c b/src/data/psql-reader.c index 4a49ba0cf9..c6f03250dd 100644 --- a/src/data/psql-reader.c +++ b/src/data/psql-reader.c @@ -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: diff --git a/src/data/sys-file-reader.c b/src/data/sys-file-reader.c index af8f1b4576..e0b43b9205 100644 --- a/src/data/sys-file-reader.c +++ b/src/data/sys-file-reader.c @@ -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)); diff --git a/src/data/sys-file-writer.c b/src/data/sys-file-writer.c index b655f44073..eb9f8e93b6 100644 --- a/src/data/sys-file-writer.c +++ b/src/data/sys-file-writer.c @@ -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); } } diff --git a/src/data/value.c b/src/data/value.c index 1d27083552..bbe96b1980 100644 --- a/src/data/value.c +++ b/src/data/value.c @@ -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); } } diff --git a/src/data/value.h b/src/data/value.h index 4d51774608..8e624a8464 100644 --- a/src/data/value.h +++ b/src/data/value.h @@ -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 diff --git a/src/language/data-io/matrix-data.c b/src/language/data-io/matrix-data.c index cd962e1f25..7676bb1de0 100644 --- a/src/language/data-io/matrix-data.c +++ b/src/language/data-io/matrix-data.c @@ -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) || diff --git a/src/language/data-io/matrix-reader.c b/src/language/data-io/matrix-reader.c index 3a7e6ef056..963f4a24f1 100644 --- a/src/language/data-io/matrix-reader.c +++ b/src/language/data-io/matrix-reader.c @@ -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); } diff --git a/src/language/dictionary/mrsets.c b/src/language/dictionary/mrsets.c index 97ab2c1fb4..4a01ddd49f 100644 --- a/src/language/dictionary/mrsets.c +++ b/src/language/dictionary/mrsets.c @@ -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); diff --git a/src/language/stats/aggregate.c b/src/language/stats/aggregate.c index 5a4b41e1ab..c0d1438ecb 100644 --- a/src/language/stats/aggregate.c +++ b/src/language/stats/aggregate.c @@ -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; diff --git a/src/language/stats/autorecode.c b/src/language/stats/autorecode.c index aabef142e1..e7d06a818d 100644 --- a/src/language/stats/autorecode.c +++ b/src/language/stats/autorecode.c @@ -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 diff --git a/src/language/xforms/recode.c b/src/language/xforms/recode.c index 361b5a64f8..4f8acf6bbb 100644 --- a/src/language/xforms/recode.c +++ b/src/language/xforms/recode.c @@ -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); diff --git a/src/output/pivot-table.c b/src/output/pivot-table.c index 092ebfc53a..dc15285b48 100644 --- a/src/output/pivot-table.c +++ b/src/output/pivot-table.c @@ -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] == ' ') diff --git a/src/ui/gui/psppire-dialog-action-indep-samps.c b/src/ui/gui/psppire-dialog-action-indep-samps.c index 7a2511ad6e..32db97ea13 100644 --- a/src/ui/gui/psppire-dialog-action-indep-samps.c +++ b/src/ui/gui/psppire-dialog-action-indep-samps.c @@ -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'; } } diff --git a/src/ui/gui/spreadsheet-test.c b/src/ui/gui/spreadsheet-test.c index da63c0ff4a..b8ce870d46 100644 --- a/src/ui/gui/spreadsheet-test.c +++ b/src/ui/gui/spreadsheet-test.c @@ -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); diff --git a/src/ui/syntax-gen.c b/src/ui/syntax-gen.c index 93d52c79c0..27e61e4253 100644 --- a/src/ui/syntax-gen.c +++ b/src/ui/syntax-gen.c @@ -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 THRU to OUTPUT. If LOW is LOWEST, then diff --git a/tests/data/datasheet-test.c b/tests/data/datasheet-test.c index e3dad3b32c..5f903c4dd9 100644 --- a/tests/data/datasheet-test.c +++ b/tests/data/datasheet-test.c @@ -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]; } } -- 2.30.2