X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fcase.c;h=6e65af975a1d77150c7cbaaeb49d6d278457c433;hb=4dc2ebcfd1a113b25f6997ff3b66fa52ac41158b;hp=6fad874d0c71482086c0387c1cf390e4f75708d0;hpb=dcf9b154cbcaa35c3d8459a201b77eec8bcb30bd;p=pspp-builds.git diff --git a/src/data/case.c b/src/data/case.c index 6fad874d..6e65af97 100644 --- a/src/data/case.c +++ b/src/data/case.c @@ -22,11 +22,11 @@ #include #include #include "value.h" -#include "alloc.h" -#include "str.h" +#include +#include #include "variable.h" -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING #undef NDEBUG #else #ifndef NDEBUG @@ -66,7 +66,7 @@ case_size (size_t value_cnt) + value_cnt * sizeof (union value)); } -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Initializes C as a null case. */ void case_nullify (struct ccase *c) @@ -74,16 +74,16 @@ case_nullify (struct ccase *c) c->case_data = NULL; c->this = c; } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Returns true iff C is a null case. */ int case_is_null (const struct ccase *c) { return c->case_data == NULL; } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ /* Initializes C as a new case that can store VALUE_CNT values. The values have indeterminate contents until explicitly @@ -95,7 +95,7 @@ case_create (struct ccase *c, size_t value_cnt) xalloc_die (); } -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Initializes CLONE as a copy of ORIG. */ void case_clone (struct ccase *clone, const struct ccase *orig) @@ -113,9 +113,9 @@ case_clone (struct ccase *clone, const struct ccase *orig) } orig->case_data->ref_cnt++; } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Replaces DST by SRC and nullifies SRC. DST and SRC must be initialized cases at entry. */ void @@ -126,14 +126,17 @@ case_move (struct ccase *dst, struct ccase *src) assert (src->case_data != NULL); assert (src->case_data->ref_cnt > 0); assert (dst != NULL); - - *dst = *src; - dst->this = dst; - case_nullify (src); + + if (dst != src) + { + *dst = *src; + dst->this = dst; + case_nullify (src); + } } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Destroys case C. */ void case_destroy (struct ccase *c) @@ -151,7 +154,7 @@ case_destroy (struct ccase *c) free (cd); } } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ /* Resizes case C from OLD_CNT to NEW_CNT values. */ void @@ -180,23 +183,18 @@ case_swap (struct ccase *a, struct ccase *b) int case_try_create (struct ccase *c, size_t value_cnt) { +#ifdef DEBUGGING + c->this = c; +#endif c->case_data = malloc (case_size (value_cnt)); if (c->case_data != NULL) { -#ifdef GLOBAL_DEBUGGING - c->this = c; -#endif c->case_data->value_cnt = value_cnt; c->case_data->ref_cnt = 1; return 1; } else - { -#ifdef GLOBAL_DEBUGGING - c->this = c; -#endif - return 0; - } + return 0; } /* Tries to initialize CLONE as a copy of ORIG. @@ -209,7 +207,7 @@ case_try_clone (struct ccase *clone, const struct ccase *orig) return 1; } -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Copies VALUE_CNT values from SRC (starting at SRC_IDX) to DST (starting at DST_IDX). */ void @@ -229,16 +227,18 @@ case_copy (struct ccase *dst, size_t dst_idx, assert (src->case_data->ref_cnt > 0); assert (src_idx + value_cnt <= dst->case_data->value_cnt); - if (dst->case_data->ref_cnt > 1) - case_unshare (dst); if (dst->case_data != src->case_data || dst_idx != src_idx) - memmove (dst->case_data->values + dst_idx, - src->case_data->values + src_idx, - sizeof *dst->case_data->values * value_cnt); + { + if (dst->case_data->ref_cnt > 1) + case_unshare (dst); + memmove (dst->case_data->values + dst_idx, + src->case_data->values + src_idx, + sizeof *dst->case_data->values * value_cnt); + } } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Copies case C to OUTPUT. OUTPUT_SIZE is the number of `union values' in OUTPUT, which must match the number of `union values' in C. */ @@ -256,9 +256,9 @@ case_to_values (const struct ccase *c, union value *output, memcpy (output, c->case_data->values, c->case_data->value_cnt * sizeof *output); } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Copies INPUT into case C. INPUT_SIZE is the number of `union values' in INPUT, which must match the number of `union values' in C. */ @@ -278,9 +278,9 @@ case_from_values (struct ccase *c, const union value *input, memcpy (c->case_data->values, input, c->case_data->value_cnt * sizeof *input); } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Returns a pointer to the `union value' used for the element of C numbered IDX. The caller must not modify the returned data. */ @@ -295,9 +295,9 @@ case_data (const struct ccase *c, size_t idx) return &c->case_data->values[idx]; } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Returns the numeric value of the `union value' in C numbered IDX. */ double @@ -311,9 +311,9 @@ case_num (const struct ccase *c, size_t idx) return c->case_data->values[idx].f; } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Returns the string value of the `union value' in C numbered IDX. (Note that the value is not null-terminated.) @@ -329,9 +329,9 @@ case_str (const struct ccase *c, size_t idx) return c->case_data->values[idx].s; } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ -#ifdef GLOBAL_DEBUGGING +#ifdef DEBUGGING /* Returns a pointer to the `union value' used for the element of C numbered IDX. The caller is allowed to modify the returned data. */ @@ -348,7 +348,7 @@ case_data_rw (struct ccase *c, size_t idx) case_unshare (c); return &c->case_data->values[idx]; } -#endif /* GLOBAL_DEBUGGING */ +#endif /* DEBUGGING */ /* Compares the values of the VAR_CNT variables in VP in cases A and B and returns a strcmp()-type result. */