X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=blobdiff_plain;f=src%2Fdata%2Fdatasheet.c;h=970a7bbac2b4a362a62327cf536abfd9eeee1c76;hb=95cde62bdf5210c1c60dad5598a888b864f93161;hp=74da1116a579e539178461917c5561259b557544;hpb=339f1956cc727eda788638644ef93ab7852b31cd;p=pspp diff --git a/src/data/datasheet.c b/src/data/datasheet.c index 74da1116a5..970a7bbac2 100644 --- a/src/data/datasheet.c +++ b/src/data/datasheet.c @@ -61,13 +61,13 @@ static unsigned long axis_get_size (const struct axis *); static void axis_insert (struct axis *, unsigned long int log_start, unsigned long int phy_start, - unsigned long int cnt); + unsigned long int n); static void axis_remove (struct axis *, - unsigned long int start, unsigned long int cnt); + unsigned long int start, unsigned long int n); static void axis_move (struct axis *, unsigned long int old_start, unsigned long int new_start, - unsigned long int cnt); + unsigned long int n); static struct source *source_create_empty (size_t n_bytes); static struct source *source_create_casereader (struct casereader *); @@ -190,6 +190,7 @@ caseproto_to_n_bytes (const struct caseproto *proto) for (i = 0; i < caseproto_get_n_widths (proto); i++) { int width = caseproto_get_width (proto, i); + assert (width >= 0); if (width >= 0) n_bytes += width_to_n_bytes (width); } @@ -236,6 +237,7 @@ datasheet_create (struct casereader *reader) int width = caseproto_get_width (ds->proto, i); column->source = ds->sources[0]; column->width = width; + assert (width >= 0); if (width >= 0) { column->value_ofs = i; @@ -473,6 +475,8 @@ datasheet_resize_column (struct datasheet *ds, size_t column, int new_width, col = &ds->columns[column]; old_col = *col; old_width = old_col.width; + assert (old_width >= 0); + assert (new_width >= 0); if (new_width == -1) { @@ -610,7 +614,7 @@ datasheet_put_value (struct datasheet *ds, casenumber row, return rw_case (ds, OP_WRITE, row, column, 1, (union value *) value); } -/* Inserts the CNT cases at C into datasheet DS just before row +/* Inserts the N cases at C into datasheet DS just before row BEFORE. Returns true if successful, false on I/O error. On failure, datasheet DS is not modified. @@ -619,10 +623,10 @@ datasheet_put_value (struct datasheet *ds, casenumber row, bool datasheet_insert_rows (struct datasheet *ds, casenumber before, struct ccase *c[], - casenumber cnt) + casenumber n) { casenumber added = 0; - while (cnt > 0) + while (n > 0) { unsigned long first_phy; unsigned long n_phys; @@ -630,12 +634,12 @@ datasheet_insert_rows (struct datasheet *ds, /* Allocate physical rows from the pool of available rows. */ - if (!axis_allocate (ds->rows, cnt, &first_phy, &n_phys)) + if (!axis_allocate (ds->rows, n, &first_phy, &n_phys)) { /* No rows were available. Extend the row axis to make some new ones available. */ - n_phys = cnt; - first_phy = axis_extend (ds->rows, cnt); + n_phys = n; + first_phy = axis_extend (ds->rows, n); } /* Insert the new rows into the row mapping. */ @@ -645,7 +649,7 @@ datasheet_insert_rows (struct datasheet *ds, for (i = 0; i < n_phys; i++) if (!datasheet_put_row (ds, before + i, c[i])) { - while (++i < cnt) + while (++i < n) case_unref (c[i]); datasheet_delete_rows (ds, before - added, n_phys + added); return false; @@ -653,39 +657,39 @@ datasheet_insert_rows (struct datasheet *ds, /* Advance. */ c += n_phys; - cnt -= n_phys; + n -= n_phys; before += n_phys; added += n_phys; } return true; } -/* Deletes the CNT rows in DS starting from row FIRST. */ +/* Deletes the N rows in DS starting from row FIRST. */ void datasheet_delete_rows (struct datasheet *ds, - casenumber first, casenumber cnt) + casenumber first, casenumber n) { size_t lrow; /* Free up rows for reuse. FIXME: optimize. */ - for (lrow = first; lrow < first + cnt; lrow++) + for (lrow = first; lrow < first + n; lrow++) axis_make_available (ds->rows, axis_map (ds->rows, lrow), 1); /* Remove rows from logical-to-physical mapping. */ - axis_remove (ds->rows, first, cnt); + axis_remove (ds->rows, first, n); } -/* Moves the CNT rows in DS starting at position OLD_START so +/* Moves the N rows in DS starting at position OLD_START so that they then start at position NEW_START. Equivalent to deleting the given rows, then inserting them at what becomes position NEW_START after the deletion. */ void datasheet_move_rows (struct datasheet *ds, size_t old_start, size_t new_start, - size_t cnt) + size_t n) { - axis_move (ds->rows, old_start, new_start, cnt); + axis_move (ds->rows, old_start, new_start, n); } static const struct casereader_random_class datasheet_reader_class; @@ -756,6 +760,7 @@ allocate_column (struct datasheet *ds, int width, struct column *column) column->value_ofs = -1; column->width = width; + assert (width >= 0); if (width >= 0) { int n_bytes; @@ -1028,30 +1033,30 @@ axis_get_size (const struct axis *axis) return tower_height (&axis->log_to_phy); } -/* Inserts the CNT contiguous physical ordinates starting at +/* Inserts the N contiguous physical ordinates starting at PHY_START into AXIS's logical-to-physical mapping, starting at logical position LOG_START. */ static void axis_insert (struct axis *axis, unsigned long int log_start, unsigned long int phy_start, - unsigned long int cnt) + unsigned long int n) { struct tower_node *before = split_axis (axis, log_start); struct tower_node *new = make_axis_group (phy_start); - tower_insert (&axis->log_to_phy, cnt, new, before); + tower_insert (&axis->log_to_phy, n, new, before); merge_axis_nodes (axis, new, NULL); check_axis_merged (axis); } -/* Removes CNT ordinates from AXIS's logical-to-physical mapping +/* Removes N ordinates from AXIS's logical-to-physical mapping starting at logical position START. */ static void axis_remove (struct axis *axis, - unsigned long int start, unsigned long int cnt) + unsigned long int start, unsigned long int n) { - if (cnt > 0) + if (n > 0) { - struct tower_node *last = split_axis (axis, start + cnt); + struct tower_node *last = split_axis (axis, start + n); struct tower_node *cur, *next; for (cur = split_axis (axis, start); cur != last; cur = next) { @@ -1063,24 +1068,24 @@ axis_remove (struct axis *axis, } } -/* Moves the CNT ordinates in AXIS's logical-to-mapping starting +/* Moves the N ordinates in AXIS's logical-to-mapping starting at logical position OLD_START so that they then start at position NEW_START. */ static void axis_move (struct axis *axis, unsigned long int old_start, unsigned long int new_start, - unsigned long int cnt) + unsigned long int n) { - if (cnt > 0 && old_start != new_start) + if (n > 0 && old_start != new_start) { struct tower_node *old_first, *old_last, *new_first; struct tower_node *merge1, *merge2; struct tower tmp_array; - /* Move ordinates OLD_START...(OLD_START + CNT) into new, + /* Move ordinates OLD_START...(OLD_START + N) into new, separate TMP_ARRAY. */ old_first = split_axis (axis, old_start); - old_last = split_axis (axis, old_start + cnt); + old_last = split_axis (axis, old_start + n); tower_init (&tmp_array); tower_splice (&tmp_array, NULL, &axis->log_to_phy, old_first, old_last); @@ -1402,6 +1407,7 @@ copy_case_into_source (struct source *source, struct ccase *c, casenumber row) for (i = 0; i < n_widths; i++) { int width = caseproto_get_width (proto, i); + assert (width >= 0); if (width >= 0) { int n_bytes = width_to_n_bytes (width); @@ -1454,16 +1460,6 @@ source_write (const struct column columns[], casenumber row, return true; } -/* Within SOURCE, which must not have a backing casereader, - writes the VALUE_CNT values in VALUES_CNT to the VALUE_CNT - columns starting from START_COLUMN, in every row, even in rows - not yet otherwise initialized. Returns true if successful, - false if an I/O error occurs. - - We don't support backing != NULL because (1) it's harder and - (2) this function is only called by - datasheet_insert_column, which doesn't reuse columns from - sources that are backed by casereaders. */ static bool source_write_column (struct column *column, const union value *value) {