From 0553d00dca10c2d2beeffd88fd12120e43a01025 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Wed, 12 Sep 2007 13:43:49 +0000 Subject: [PATCH] * casereader-translator.c (struct casereader_translator): Change input case parameter of translate member function from const struct ccase * to struct ccase *. (casereader_create_translator): Ditto, for translate parameter. * casewriter-translator.c (struct casewriter_translator): Ditto. (casewriter_create_translator): Ditto. * get.c (get_translate_case): Change input case parameter from const struct ccase * to struct ccase *, to match change in casereader and casewriter translators. Destroy input case, to fix memory leak. --- src/data/ChangeLog | 15 ++++++++++++++- src/data/casereader-translator.c | 5 ++--- src/data/casereader.h | 2 +- src/data/casewriter-translator.c | 17 ++++++++++++++--- src/data/casewriter.h | 2 +- src/language/data-io/ChangeLog | 7 +++++++ src/language/data-io/get.c | 6 +++--- 7 files changed, 42 insertions(+), 12 deletions(-) diff --git a/src/data/ChangeLog b/src/data/ChangeLog index 73cf8a1c..bc89aef7 100644 --- a/src/data/ChangeLog +++ b/src/data/ChangeLog @@ -1,3 +1,16 @@ +2007-09-12 Ben Pfaff + + Make it clear that translator casereader and casewriter translate + functions are supposed to destroy their input case. + + * casereader-translator.c (struct casereader_translator): Change + input case parameter of translate member function from const + struct ccase * to struct ccase *. + (casereader_create_translator): Ditto, for translate parameter. + + * casewriter-translator.c (struct casewriter_translator): Ditto. + (casewriter_create_translator): Ditto. + 2007-08-27 John Darrinton * sys-file-reader.c (read_display_parameters): Force display width @@ -32,7 +45,7 @@ dict_make_compactor. (scratch_writer_casewriter_write): Use case_map_execute instead of dict_compactor_compact. -o + 2007-08-12 Ben Pfaff * automake.mk: Add case-map.c, case-map.h. diff --git a/src/data/casereader-translator.c b/src/data/casereader-translator.c index 523afe3f..5a717da8 100644 --- a/src/data/casereader-translator.c +++ b/src/data/casereader-translator.c @@ -33,8 +33,7 @@ struct casereader_translator { struct casereader *subreader; /* Source of input cases. */ - void (*translate) (const struct ccase *input, struct ccase *output, - void *aux); + void (*translate) (struct ccase *input, struct ccase *output, void *aux); bool (*destroy) (void *aux); void *aux; }; @@ -56,7 +55,7 @@ static struct casereader_class casereader_translator_class; struct casereader * casereader_create_translator (struct casereader *subreader, size_t output_value_cnt, - void (*translate) (const struct ccase *input, + void (*translate) (struct ccase *input, struct ccase *output, void *aux), bool (*destroy) (void *aux), diff --git a/src/data/casereader.h b/src/data/casereader.h index 31e448fb..d4a1cce5 100644 --- a/src/data/casereader.h +++ b/src/data/casereader.h @@ -105,7 +105,7 @@ casereader_create_counter (struct casereader *, casenumber *counter, struct casereader * casereader_create_translator (struct casereader *, size_t output_value_cnt, - void (*translate) (const struct ccase *input, + void (*translate) (struct ccase *input, struct ccase *output, void *aux), bool (*destroy) (void *aux), diff --git a/src/data/casewriter-translator.c b/src/data/casewriter-translator.c index 526bba34..79694a46 100644 --- a/src/data/casewriter-translator.c +++ b/src/data/casewriter-translator.c @@ -29,18 +29,29 @@ struct casewriter_translator { struct casewriter *subwriter; - void (*translate) (const struct ccase *input, struct ccase *output, - void *aux); + void (*translate) (struct ccase *input, struct ccase *output, void *aux); bool (*destroy) (void *aux); void *aux; }; static struct casewriter_class casewriter_translator_class; +/* Creates and returns a new casewriter whose cases are passed + through TRANSLATE, which must create case OUTPUT, with + OUTPUT_VALUE_CNT values, and populate it based on INPUT and + auxiliary data AUX. The translated cases are then written to + SUBWRITER. TRANSLATE must also destroy INPUT. + + When the translating casewriter is destroyed, DESTROY will be + called to allow any state maintained by TRANSLATE to be freed. + + After this function is called, SUBWRITER must not ever again + be referenced directly. It will be destroyed automatically + when the translating casewriter is destroyed. */ struct casewriter * casewriter_create_translator (struct casewriter *subwriter, size_t translated_value_cnt, - void (*translate) (const struct ccase *input, + void (*translate) (struct ccase *input, struct ccase *output, void *aux), bool (*destroy) (void *aux), diff --git a/src/data/casewriter.h b/src/data/casewriter.h index 87bf6f6a..a92c4176 100644 --- a/src/data/casewriter.h +++ b/src/data/casewriter.h @@ -43,7 +43,7 @@ struct casewriter *autopaging_writer_create (size_t value_cnt); struct casewriter * casewriter_create_translator (struct casewriter *, size_t translated_value_cnt, - void (*translate) (const struct ccase *input, + void (*translate) (struct ccase *input, struct ccase *output, void *aux), bool (*destroy) (void *aux), diff --git a/src/language/data-io/ChangeLog b/src/language/data-io/ChangeLog index 8eece80b..572aacd5 100644 --- a/src/language/data-io/ChangeLog +++ b/src/language/data-io/ChangeLog @@ -1,3 +1,10 @@ +2007-09-12 Ben Pfaff + + * get.c (get_translate_case): Change input case parameter from + const struct ccase * to struct ccase *, to match change in + casereader and casewriter translators. Destroy input case, to fix + memory leak. + 2007-08-12 Ben Pfaff * get.c (parse_read_command): Compact the values in the target diff --git a/src/language/data-io/get.c b/src/language/data-io/get.c index 22ae6feb..abfc6247 100644 --- a/src/language/data-io/get.c +++ b/src/language/data-io/get.c @@ -60,8 +60,7 @@ enum reader_command IMPORT_CMD }; -static void get_translate_case (const struct ccase *, struct ccase *, - void *map_); +static void get_translate_case (struct ccase *, struct ccase *, void *map_); static bool get_destroy_case_map (void *map_); /* Parses a GET or IMPORT command. */ @@ -143,11 +142,12 @@ parse_read_command (struct lexer *lexer, struct dataset *ds, enum reader_command } static void -get_translate_case (const struct ccase *input, struct ccase *output, +get_translate_case (struct ccase *input, struct ccase *output, void *map_) { struct case_map *map = map_; case_map_execute (map, input, output); + case_destroy (input); } static bool -- 2.30.2