From: Ben Pfaff Date: Sat, 8 Dec 2007 06:09:03 +0000 (+0000) Subject: Patch #6302. X-Git-Tag: v0.6.0~166 X-Git-Url: https://pintos-os.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=c217e77f75f84c5e31ea0f698014069cd4e78e0c;p=pspp-builds.git Patch #6302. * casegrouper.c (casegrouper_get_next_group): Cause a casegrouper made from an empty casereader produce a casegrouper with no groups, instead of one with one group that has no cases. * casereader.c (casereader_is_empty): New function. --- diff --git a/src/data/ChangeLog b/src/data/ChangeLog index e25c3984..25d67925 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,13 @@ +2007-12-07 Ben Pfaff + + Patch #6302. + + * casegrouper.c (casegrouper_get_next_group): Cause a casegrouper + made from an empty casereader produce a casegrouper with no + groups, instead of one with one group that has no cases. + + * casereader.c (casereader_is_empty): New function. + 2007-12-06 Ben Pfaff Patch #6303. diff --git a/src/data/casegrouper.c b/src/data/casegrouper.c index 8a4f05b3..f5974a40 100644 --- a/src/data/casegrouper.c +++ b/src/data/casegrouper.c @@ -110,9 +110,18 @@ casegrouper_get_next_group (struct casegrouper *grouper, { if (grouper->reader != NULL) { - *reader = grouper->reader; - grouper->reader = NULL; - return true; + if (!casereader_is_empty (grouper->reader)) + { + *reader = grouper->reader; + grouper->reader = NULL; + return true; + } + else + { + casereader_destroy (grouper->reader); + grouper->reader = NULL; + return false; + } } else { diff --git a/src/data/casereader.c b/src/data/casereader.c index 8b786456..e6d859c9 100644 --- a/src/data/casereader.c +++ b/src/data/casereader.c @@ -183,6 +183,24 @@ casereader_peek (struct casereader *reader, casenumber idx, struct ccase *c) return false; } +/* Returns true if no cases remain to be read from READER, or if + an error has occurred on READER. (A return value of false + does *not* mean that the next call to casereader_peek or + casereader_read will return true, because an error can occur + in the meantime.) */ +bool +casereader_is_empty (struct casereader *reader) +{ + struct ccase c; + if (reader->case_cnt == 0 || !casereader_peek (reader, 0, &c)) + return true; + else + { + case_destroy (&c); + return false; + } +} + /* Returns true if an I/O error or another hard error has occurred on READER, a clone of READER, or on some object on which READER's data has a dependency, false otherwise. */ diff --git a/src/data/casereader.h b/src/data/casereader.h index d4a1cce5..6d719c61 100644 --- a/src/data/casereader.h +++ b/src/data/casereader.h @@ -70,6 +70,7 @@ void casereader_swap (struct casereader *, struct casereader *); bool casereader_peek (struct casereader *, casenumber, struct ccase *) WARN_UNUSED_RESULT; +bool casereader_is_empty (struct casereader *); bool casereader_error (const struct casereader *); void casereader_force_error (struct casereader *);