From: John Darrington Date: Sat, 22 Jun 2013 05:33:00 +0000 (+0200) Subject: dictionary.c: Added a oldvar parameter to the var_changed callback X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=960895696ee774cfe824b3d0f25b6325f7277fd8;p=pspp dictionary.c: Added a oldvar parameter to the var_changed callback The var_changed callback needs a copy of the old (unchanged) variable, so that implementations can compare and act accordingly. --- diff --git a/src/data/dictionary.c b/src/data/dictionary.c index e3622655c5..c8f9da5ef4 100644 --- a/src/data/dictionary.c +++ b/src/data/dictionary.c @@ -1591,10 +1591,12 @@ dict_has_attributes (const struct dictionary *d) return attrset_count (&d->attributes) > 0; } -/* Called from variable.c to notify the dictionary that some property of - the variable has changed */ +/* Called from variable.c to notify the dictionary that some property (indicated + by WHAT) of the variable has changed. OLDVAR is a copy of V as it existed + prior to the change. OLDVAR is destroyed by this function. +*/ void -dict_var_changed (const struct variable *v, unsigned int what UNUSED) +dict_var_changed (const struct variable *v, unsigned int what UNUSED, struct variable *oldvar) { if ( var_has_vardict (v)) { @@ -1608,6 +1610,7 @@ dict_var_changed (const struct variable *v, unsigned int what UNUSED) if ( d->callbacks && d->callbacks->var_changed ) d->callbacks->var_changed (d, var_get_dict_index (v), d->cb_data); } + var_destroy (oldvar); } diff --git a/src/data/vardict.h b/src/data/vardict.h index ad87c82cfa..76e1c05c8a 100644 --- a/src/data/vardict.h +++ b/src/data/vardict.h @@ -39,7 +39,7 @@ bool var_has_vardict (const struct variable *); void var_clear_vardict (struct variable *); /* Called by variable.c, defined in dictionary.c. */ -void dict_var_changed (const struct variable *v, unsigned int what); +void dict_var_changed (const struct variable *v, unsigned int what, struct variable *ov); void dict_var_resized (const struct variable *v, int old_width); void dict_var_display_width_changed (const struct variable *v); diff --git a/src/data/variable.c b/src/data/variable.c index 6c6f6cedc7..6affaec6e8 100644 --- a/src/data/variable.c +++ b/src/data/variable.c @@ -160,8 +160,9 @@ var_set_name_quiet (struct variable *v, const char *name) void var_set_name (struct variable *v, const char *name) { + struct variable *ov = var_clone (v); var_set_name_quiet (v, name); - dict_var_changed (v, VAR_TRAIT_NAME); + dict_var_changed (v, VAR_TRAIT_NAME, ov); } /* Returns VAR's dictionary class. */ @@ -246,11 +247,14 @@ var_get_width (const struct variable *v) void var_set_width (struct variable *v, int new_width) { + struct variable *ov; const int old_width = v->width; if (old_width == new_width) return; + ov = var_clone (v); + if (mv_is_resizable (&v->miss, new_width)) mv_resize (&v->miss, new_width); else @@ -275,7 +279,7 @@ var_set_width (struct variable *v, int new_width) v->width = new_width; dict_var_resized (v, old_width); - dict_var_changed (v, VAR_TRAIT_WIDTH); + dict_var_changed (v, VAR_TRAIT_WIDTH, ov); } /* Returns true if variable V is numeric, false otherwise. */ @@ -325,8 +329,9 @@ var_set_missing_values_quiet (struct variable *v, const struct missing_values *m void var_set_missing_values (struct variable *v, const struct missing_values *miss) { + struct variable *ov = var_clone (v); var_set_missing_values_quiet (v, miss); - dict_var_changed (v, VAR_TRAIT_MISSING_VALUES); + dict_var_changed (v, VAR_TRAIT_MISSING_VALUES, ov); } /* Sets variable V to have no user-missing values. */ @@ -413,8 +418,9 @@ var_set_value_labels_quiet (struct variable *v, const struct val_labs *vls) void var_set_value_labels (struct variable *v, const struct val_labs *vls) { + struct variable *ov = var_clone (v); var_set_value_labels_quiet (v, vls); - dict_var_changed (v, VAR_TRAIT_LABEL); + dict_var_changed (v, VAR_TRAIT_LABEL, ov); } @@ -548,8 +554,9 @@ var_set_print_format_quiet (struct variable *v, const struct fmt_spec *print) void var_set_print_format (struct variable *v, const struct fmt_spec *print) { + struct variable *ov = var_clone (v); var_set_print_format_quiet (v, print); - dict_var_changed (v, VAR_TRAIT_FORMAT); + dict_var_changed (v, VAR_TRAIT_FORMAT, ov); } /* Returns V's write format specification. */ @@ -580,8 +587,9 @@ var_set_write_format_quiet (struct variable *v, const struct fmt_spec *write) void var_set_write_format (struct variable *v, const struct fmt_spec *write) { + struct variable *ov = var_clone (v); var_set_write_format_quiet (v, write); - dict_var_changed (v, VAR_TRAIT_FORMAT); + dict_var_changed (v, VAR_TRAIT_FORMAT, ov); } @@ -592,9 +600,10 @@ var_set_write_format (struct variable *v, const struct fmt_spec *write) void var_set_both_formats (struct variable *v, const struct fmt_spec *format) { + struct variable *ov = var_clone (v); var_set_print_format_quiet (v, format); var_set_write_format_quiet (v, format); - dict_var_changed (v, VAR_TRAIT_FORMAT); + dict_var_changed (v, VAR_TRAIT_FORMAT, ov); } /* Returns the default print and write format for a variable of @@ -724,9 +733,10 @@ var_set_label_quiet (struct variable *v, const char *label, bool issue_warning) bool var_set_label (struct variable *v, const char *label, bool issue_warning) { + struct variable *ov = var_clone (v); bool truncated = var_set_label_quiet (v, label, issue_warning); - dict_var_changed (v, VAR_TRAIT_LABEL); + dict_var_changed (v, VAR_TRAIT_LABEL, ov); return truncated; } @@ -795,8 +805,9 @@ var_set_measure_quiet (struct variable *v, enum measure measure) void var_set_measure (struct variable *v, enum measure measure) { + struct variable *ov = var_clone (v); var_set_measure_quiet (v, measure); - dict_var_changed (v, VAR_TRAIT_MEASURE); + dict_var_changed (v, VAR_TRAIT_MEASURE, ov); } @@ -831,8 +842,9 @@ var_set_display_width_quiet (struct variable *v, int new_width) void var_set_display_width (struct variable *v, int new_width) { + struct variable *ov = var_clone (v); var_set_display_width_quiet (v, new_width); - dict_var_changed (v, VAR_TRAIT_DISPLAY_WIDTH); + dict_var_changed (v, VAR_TRAIT_DISPLAY_WIDTH, ov); } @@ -892,8 +904,9 @@ var_set_alignment_quiet (struct variable *v, enum alignment alignment) void var_set_alignment (struct variable *v, enum alignment alignment) { + struct variable *ov = var_clone (v); var_set_alignment_quiet (v, alignment); - dict_var_changed (v, VAR_TRAIT_ALIGNMENT); + dict_var_changed (v, VAR_TRAIT_ALIGNMENT, ov); } @@ -930,8 +943,9 @@ var_set_leave_quiet (struct variable *v, bool leave) void var_set_leave (struct variable *v, bool leave) { + struct variable *ov = var_clone (v); var_set_leave_quiet (v, leave); - dict_var_changed (v, VAR_TRAIT_LEAVE); + dict_var_changed (v, VAR_TRAIT_LEAVE, ov); } @@ -978,6 +992,8 @@ var_get_short_name (const struct variable *var, size_t idx) void var_set_short_name (struct variable *var, size_t idx, const char *short_name) { + struct variable *ov = var_clone (var); + assert (short_name == NULL || id_is_plausible (short_name, false)); /* Clear old short name numbered IDX, if any. */ @@ -1003,7 +1019,7 @@ var_set_short_name (struct variable *var, size_t idx, const char *short_name) var->short_names[idx] = utf8_to_upper (short_name); } - dict_var_changed (var, VAR_TRAIT_NAME); + dict_var_changed (var, VAR_TRAIT_NAME, ov); } /* Clears V's short names. */ @@ -1064,8 +1080,9 @@ var_set_attributes_quiet (struct variable *v, const struct attrset *attrs) void var_set_attributes (struct variable *v, const struct attrset *attrs) { + struct variable *ov = var_clone (v); var_set_attributes_quiet (v, attrs); - dict_var_changed (v, VAR_TRAIT_ATTRIBUTES); + dict_var_changed (v, VAR_TRAIT_ATTRIBUTES, ov); }