+2007-08-12 Ben Pfaff <blp@gnu.org>
+
+ Make casewriters keep track of the number of `union value's in
+ each case. This is useful for two reasons: casewriter_write can
+ then check that the case being written is large enough, and later
+ recipients of the casewriter can determine the size of the case.
+
+ * casewriter-translator.c (casewriter_create_translator): Add
+ value_cnt parameter.
+
+ * casewriter.c (struct casewriter): Add value_cnt member.
+ (casewriter_write): Check that the case passed in is big enough.
+ (casewriter_get_value_cnt): New function.
+ (casewriter_create): Add value_cnt parameter.
+
+
2007-08-09 Ben Pfaff <blp@gnu.org>
Fix bug reported by Jason Stover.
struct casereader *(*convert_to_reader) (struct casewriter *, void *aux);
};
-struct casewriter *casewriter_create (const struct casewriter_class *, void *);
+struct casewriter *casewriter_create (size_t value_cnt,
+ const struct casewriter_class *, void *);
#endif /* data/casewriter-provider.h */
struct casewriter *
casewriter_create_translator (struct casewriter *subwriter,
+ size_t translated_value_cnt,
void (*translate) (const struct ccase *input,
struct ccase *output,
void *aux),
ct->translate = translate;
ct->destroy = destroy;
ct->aux = aux;
- writer = casewriter_create (&casewriter_translator_class, ct);
+ writer = casewriter_create (translated_value_cnt,
+ &casewriter_translator_class, ct);
taint_propagate (casewriter_get_taint (ct->subwriter),
casewriter_get_taint (writer));
return writer;
struct casewriter
{
struct taint *taint;
+ size_t value_cnt;
casenumber case_cnt;
const struct casewriter_class *class;
void *aux;
void
casewriter_write (struct casewriter *writer, struct ccase *c)
{
+ assert (case_get_value_cnt (c) >= writer->value_cnt);
writer->class->write (writer, writer->aux, c);
}
return ok;
}
+/* Returns the number of `union value's in each case written to
+ WRITER. */
+size_t
+casewriter_get_value_cnt (const struct casewriter *writer)
+{
+ return writer->value_cnt;
+}
+
/* Destroys WRITER and in its place returns a casereader that can
be used to read back the data written to WRITER. WRITER must
not be used again after calling this function, even as an
}
/* Creates and returns a new casewriter with the given CLASS and
- auxiliary data AUX. */
+ auxiliary data AUX. The casewriter accepts cases with
+ VALUE_CNT `union value's. */
struct casewriter *
-casewriter_create (const struct casewriter_class *class, void *aux)
+casewriter_create (size_t value_cnt,
+ const struct casewriter_class *class, void *aux)
{
struct casewriter *writer = xmalloc (sizeof *writer);
writer->taint = taint_create ();
+ writer->value_cnt = value_cnt;
writer->case_cnt = 0;
writer->class = class;
writer->aux = aux;
create_casewriter_window (size_t value_cnt, casenumber max_in_core_cases)
{
struct casewindow *window = casewindow_create (value_cnt, max_in_core_cases);
- struct casewriter *writer = casewriter_create (&casewriter_window_class,
+ struct casewriter *writer = casewriter_create (value_cnt,
+ &casewriter_window_class,
window);
taint_propagate (casewindow_get_taint (window),
casewriter_get_taint (writer));
void casewriter_write (struct casewriter *, struct ccase *);
bool casewriter_destroy (struct casewriter *);
+size_t casewriter_get_value_cnt (const struct casewriter *);
+
struct casereader *casewriter_make_reader (struct casewriter *);
struct casewriter *casewriter_rename (struct casewriter *);
struct casewriter *autopaging_writer_create (size_t value_cnt);
\f
struct casewriter *
-casewriter_create_translator (struct casewriter *,
+casewriter_create_translator (struct casewriter *, size_t translated_value_cnt,
void (*translate) (const struct ccase *input,
struct ccase *output,
void *aux),
buf_write (w, "F", 1);
if (ferror (w->file))
goto error;
- return casewriter_create (&por_file_casewriter_class, w);
+ return casewriter_create (dict_get_next_value_idx (dict),
+ &por_file_casewriter_class, w);
error:
close_writer (w);
struct dictionary *scratch_dict;
struct dict_compactor *compactor;
struct casewriter *casewriter;
+ size_t dict_value_cnt;
if (!fh_open (fh, FH_REF_SCRATCH, "scratch file", "we"))
return NULL;
}
else
compactor = NULL;
+ dict_value_cnt = dict_get_next_value_idx (scratch_dict);
/* Create new contents. */
sh = xmalloc (sizeof *sh);
writer->handle = sh;
writer->fh = fh;
writer->compactor = compactor;
- writer->subwriter = autopaging_writer_create (dict_get_next_value_idx (
- scratch_dict));
+ writer->subwriter = autopaging_writer_create (dict_value_cnt);
fh_set_scratch_handle (fh, sh);
- casewriter = casewriter_create (&scratch_writer_casewriter_class, writer);
+ casewriter = casewriter_create (dict_value_cnt,
+ &scratch_writer_casewriter_class, writer);
taint_propagate (casewriter_get_taint (writer->subwriter),
casewriter_get_taint (casewriter));
return casewriter;
if (write_error (w))
goto error;
- return casewriter_create (&sys_file_casewriter_class, w);
+ return casewriter_create (dict_get_next_value_idx (d),
+ &sys_file_casewriter_class, w);
error:
close_writer (w);
+2007-08-12 Ben Pfaff <blp@gnu.org>
+
+ * get.c (case_map_get_value_cnt): New function.
+
2007-07-25 Ben Pfaff <blp@gnu.org>
Fix bug #17100.
static void map_case (const struct case_map *,
const struct ccase *, struct ccase *);
static void destroy_case_map (struct case_map *);
+static size_t case_map_get_value_cnt (const struct case_map *);
static bool parse_dict_trim (struct lexer *, struct dictionary *);
\f
map = finish_case_map (dict);
if (map != NULL)
writer = casewriter_create_translator (writer,
+ case_map_get_value_cnt (map),
get_translate_case,
get_destroy_case_map,
map);
free (map);
}
}
+
+/* Returns the number of `union value's in cases created by
+ MAP. */
+static size_t
+case_map_get_value_cnt (const struct case_map *map)
+{
+ return map->value_cnt;
+}
struct casewriter *
sort_create_writer (struct case_ordering *ordering)
{
+ size_t value_cnt = case_ordering_get_value_cnt (ordering);
struct sort_writer *sort;
sort = xmalloc (sizeof *sort);
case_ordering_destroy (ordering);
- return casewriter_create (&sort_casewriter_class, sort);
+ return casewriter_create (value_cnt, &sort_casewriter_class, sort);
}
static void