X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fmath%2Finteraction.c;h=133d7d7c6aa695ab6ffd7383db6b821ec19af171;hb=04c88b897db0d2281faa2829ed57b0f344395b8a;hp=33da8423bd7c7545a69e4c51a1d0a9a5abd4318d;hpb=d75247c28e0dce9c21070e4ee14fdc6a2338fb77;p=pspp-builds.git diff --git a/src/math/interaction.c b/src/math/interaction.c index 33da8423..133d7d7c 100644 --- a/src/math/interaction.c +++ b/src/math/interaction.c @@ -50,10 +50,10 @@ struct interaction_variable struct interaction_value { const struct interaction_variable *intr; - union value *val; /* Concatenation of the string values in this - interaction's value, or the product of a bunch - of numeric values for a purely numeric - interaction. + union value val; /* Concatenation of the string values in this + interaction's value, or the product of a bunch + of numeric values for a purely numeric + interaction. */ double f; /* Product of the numerical values in this interaction's value. */ }; @@ -73,7 +73,6 @@ interaction_variable_create (const struct variable **vars, int n_vars) result = xmalloc (sizeof (*result)); result->n_alpha = 0; result->members = xnmalloc (n_vars, sizeof (*result->members)); - result->intr = var_create_internal (0); result->n_vars = n_vars; for (i = 0; i < n_vars; i++) { @@ -84,10 +83,7 @@ interaction_variable_create (const struct variable **vars, int n_vars) } } } - /* - VAR_SET_WIDTH sets the type of the variable. - */ - var_set_width (result->intr, MAX_SHORT_STRING * result->n_alpha + 1); + result->intr = var_create_internal (0, 0); return result; } @@ -150,10 +146,16 @@ interaction_value_create (const struct interaction_variable *var, const union va if (var != NULL) { + int val_width; + char *val; + result = xmalloc (sizeof (*result)); result->intr = var; n_vars = interaction_get_n_vars (var); - result->val = value_create (n_vars * MAX_SHORT_STRING + 1); + val_width = n_vars * MAX_SHORT_STRING + 1; + value_init (&result->val, val_width); + val = value_str_rw (&result->val, val_width); + val[0] = '\0'; result->f = 1.0; for (i = 0; i < n_vars; i++) { @@ -161,7 +163,7 @@ interaction_value_create (const struct interaction_variable *var, const union va if (var_is_value_missing (member, vals[i], MV_ANY)) { - value_set_missing (result->val, MAX_SHORT_STRING); + value_set_missing (&result->val, MAX_SHORT_STRING); result->f = SYSMIS; break; } @@ -169,7 +171,8 @@ interaction_value_create (const struct interaction_variable *var, const union va { if (var_is_alpha (var->members[i])) { - strncat (result->val->s, vals[i]->s, MAX_SHORT_STRING); + int w = var_get_width (var->members[i]); + strncat (val, value_str (vals[i], w), MAX_SHORT_STRING); } else if (var_is_numeric (var->members[i])) { @@ -192,17 +195,17 @@ interaction_value_create (const struct interaction_variable *var, const union va avoid the error, we set result->f to 1.0 for numeric interactions. */ - result->val->f = result->f; + result->val.f = result->f; result->f = 1.0; } } return result; } -union value * +const union value * interaction_value_get (const struct interaction_value *val) { - return val->val; + return &val->val; } /* @@ -224,7 +227,10 @@ interaction_value_destroy (struct interaction_value *val) { if (val != NULL) { - free (val->val); + size_t n_vars = interaction_get_n_vars (val->intr); + int val_width = n_vars * MAX_SHORT_STRING + 1; + + value_destroy (&val->val, val_width); free (val); } } @@ -238,7 +244,7 @@ interaction_case_data (const struct ccase *ccase, const struct variable *var, { size_t i; size_t n_vars; - const struct interaction_variable *iv; + const struct interaction_variable *iv = NULL; const struct variable *intr; const struct variable *member; const union value **vals = NULL;