X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdatasheet.c;h=1175e20403eeb0fed73cf95a972beddb860766f8;hb=8f885c554e37cd066898e18b9c0752ac0e57b3dd;hp=4abc526f0cb2a720cb8e3023eb7d732effdb5da4;hpb=d0b91eae59319ab2756d0d43b9cb15eb9cd3c234;p=pspp diff --git a/src/data/datasheet.c b/src/data/datasheet.c index 4abc526f0c..1175e20403 100644 --- a/src/data/datasheet.c +++ b/src/data/datasheet.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 2007, 2009 Free Software Foundation, Inc. + Copyright (C) 2007, 2009, 2010, 2011, 2012 Free Software Foundation, Inc. This program is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License as published by @@ -16,28 +16,28 @@ #include -#include +#include "data/datasheet.h" #include #include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "minmax.h" -#include "md4.h" -#include "xalloc.h" +#include "data/casereader-provider.h" +#include "data/casereader.h" +#include "data/casewriter.h" +#include "data/lazy-casereader.h" +#include "data/settings.h" +#include "libpspp/array.h" +#include "libpspp/assertion.h" +#include "libpspp/misc.h" +#include "libpspp/range-map.h" +#include "libpspp/range-set.h" +#include "libpspp/sparse-xarray.h" +#include "libpspp/taint.h" +#include "libpspp/tower.h" + +#include "gl/minmax.h" +#include "gl/md4.h" +#include "gl/xalloc.h" struct column; @@ -360,6 +360,8 @@ datasheet_insert_column (struct datasheet *ds, { struct column *col; + assert (before <= ds->n_columns); + ds->columns = xnrealloc (ds->columns, ds->n_columns + 1, sizeof *ds->columns); insert_element (ds->columns, ds->n_columns, sizeof *ds->columns, before); @@ -382,6 +384,8 @@ datasheet_insert_column (struct datasheet *ds, void datasheet_delete_columns (struct datasheet *ds, size_t start, size_t n) { + assert (start + n <= ds->n_columns); + if (n > 0) { size_t i; @@ -411,6 +415,9 @@ datasheet_move_columns (struct datasheet *ds, size_t old_start, size_t new_start, size_t n) { + assert (old_start + n <= ds->n_columns); + assert (new_start + n <= ds->n_columns); + move_range (ds->columns, ds->n_columns, sizeof *ds->columns, old_start, new_start, n); @@ -502,15 +509,19 @@ datasheet_resize_column (struct datasheet *ds, size_t column, int new_width, if (!source_read (&old_col, prow, &src)) { /* FIXME: back out col changes. */ - return false; + break; } resize_cb (&src, &dst, resize_cb_aux); if (!source_write (col, prow, &dst)) { /* FIXME: back out col changes. */ - return false; + break; } } + value_destroy (&src, old_width); + value_destroy (&dst, new_width); + if (lrow < n_rows) + return false; release_source (ds, old_col.source); } @@ -919,8 +930,7 @@ axis_hash (const struct axis *axis, struct md4_ctx *ctx) md4_process_bytes (&size, sizeof size, ctx); } - for (rsn = range_set_first (axis->available); rsn != NULL; - rsn = range_set_next (axis->available, rsn)) + RANGE_SET_FOR_EACH (rsn, axis->available) { unsigned long int start = range_set_node_get_start (rsn); unsigned long int end = range_set_node_get_end (rsn); @@ -971,7 +981,7 @@ static void axis_make_available (struct axis *axis, unsigned long int start, unsigned long int width) { - range_set_insert (axis->available, start, width); + range_set_set1 (axis->available, start, width); } /* Extends the total physical length of AXIS by WIDTH and returns @@ -1221,7 +1231,7 @@ source_create_empty (size_t n_bytes) size_t row_size = n_bytes + 4 * sizeof (void *); size_t max_memory_rows = settings_get_workspace () / row_size; source->avail = range_set_create (); - range_set_insert (source->avail, 0, n_bytes); + range_set_set1 (source->avail, 0, n_bytes); source->data = sparse_xarray_create (n_bytes, MAX (max_memory_rows, 4)); source->backing = NULL; source->backing_rows = 0; @@ -1240,7 +1250,7 @@ source_create_casereader (struct casereader *reader) size_t n_columns; size_t i; - range_set_delete (source->avail, 0, n_bytes); + range_set_set0 (source->avail, 0, n_bytes); source->backing = reader; source->backing_rows = casereader_count_cases (reader); @@ -1294,7 +1304,7 @@ static void source_release_column (struct source *source, int ofs, int width) { assert (width >= 0); - range_set_insert (source->avail, ofs, width_to_n_bytes (width)); + range_set_set1 (source->avail, ofs, width_to_n_bytes (width)); if (source->backing != NULL) source->n_used--; }