From cbda9ae91c77f34e9591d980d5202fd7d376ac12 Mon Sep 17 00:00:00 2001 From: Ben Pfaff Date: Mon, 13 May 2013 17:04:30 -0700 Subject: [PATCH] transformations: Remove finalize functions. --- src/data/dataset.c | 17 +---------------- src/data/dataset.h | 4 ---- src/data/transformations.c | 27 +++++++-------------------- src/data/transformations.h | 5 ++--- src/language/control/do-if.c | 17 ++--------------- src/language/control/loop.c | 17 ++--------------- 6 files changed, 14 insertions(+), 73 deletions(-) diff --git a/src/data/dataset.c b/src/data/dataset.c index 7a5a6a4a6a..5b3f0ba5fb 100644 --- a/src/data/dataset.c +++ b/src/data/dataset.c @@ -691,22 +691,7 @@ proc_capture_transformations (struct dataset *ds) void add_transformation (struct dataset *ds, trns_proc_func *proc, trns_free_func *free, void *aux) { - trns_chain_append (ds->cur_trns_chain, NULL, proc, free, aux); - dataset_transformations_changed__ (ds, true); -} - -/* Adds a transformation that processes a case with PROC and - frees itself with FREE to the current set of transformations. - When parsing of the block of transformations is complete, - FINALIZE will be called. - The functions are passed AUX as auxiliary data. */ -void -add_transformation_with_finalizer (struct dataset *ds, - trns_finalize_func *finalize, - trns_proc_func *proc, - trns_free_func *free, void *aux) -{ - trns_chain_append (ds->cur_trns_chain, finalize, proc, free, aux); + trns_chain_append (ds->cur_trns_chain, proc, free, aux); dataset_transformations_changed__ (ds, true); } diff --git a/src/data/dataset.h b/src/data/dataset.h index ce8b980d2e..3f0d2e689f 100644 --- a/src/data/dataset.h +++ b/src/data/dataset.h @@ -80,10 +80,6 @@ void dataset_set_display (struct dataset *, enum dataset_display); void add_transformation (struct dataset *ds, trns_proc_func *, trns_free_func *, void *); -void add_transformation_with_finalizer (struct dataset *ds, - trns_finalize_func *, - trns_proc_func *, - trns_free_func *, void *); size_t next_transformation (const struct dataset *ds); bool proc_cancel_all_transformations (struct dataset *ds); diff --git a/src/data/transformations.c b/src/data/transformations.c index 209d13f82b..884def6753 100644 --- a/src/data/transformations.c +++ b/src/data/transformations.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2013 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2013, 2015 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 @@ -22,6 +22,7 @@ #include #include "libpspp/str.h" +#include "language/control/control-stack.h" /* XXX layering violation */ #include "gl/xalloc.h" @@ -32,7 +33,6 @@ struct transformation transformation index. Normally 0 but set to the starting index of a spliced chain after splicing. */ int idx_ofs; - trns_finalize_func *finalize; /* Finalize proc. */ trns_proc_func *execute; /* Executes the transformation. */ trns_free_func *free; /* Garbage collector proc. */ void *aux; /* Auxiliary data. */ @@ -66,18 +66,8 @@ trns_chain_finalize (struct trns_chain *chain) { while (!chain->finalized) { - size_t i; - + ctl_stack_clear (); /* XXX layering violation */ chain->finalized = true; - for (i = 0; i < chain->trns_cnt; i++) - { - struct transformation *trns = &chain->trns[i]; - trns_finalize_func *finalize = trns->finalize; - - trns->finalize = NULL; - if (finalize != NULL) - finalize (trns->aux); - } } } @@ -116,13 +106,11 @@ trns_chain_is_empty (const struct trns_chain *chain) return chain->trns_cnt == 0; } -/* Adds a transformation to CHAIN with finalize function - FINALIZE, execute function EXECUTE, free function FREE, and - auxiliary data AUX. */ +/* Adds a transformation to CHAIN with execute function EXECUTE, free function + FREE, and auxiliary data AUX. */ void -trns_chain_append (struct trns_chain *chain, trns_finalize_func *finalize, - trns_proc_func *execute, trns_free_func *free, - void *aux) +trns_chain_append (struct trns_chain *chain, trns_proc_func *execute, + trns_free_func *free, void *aux) { struct transformation *trns; @@ -134,7 +122,6 @@ trns_chain_append (struct trns_chain *chain, trns_finalize_func *finalize, trns = &chain->trns[chain->trns_cnt++]; trns->idx_ofs = 0; - trns->finalize = finalize; trns->execute = execute; trns->free = free; trns->aux = aux; diff --git a/src/data/transformations.h b/src/data/transformations.h index 013bcaa731..5e1488323b 100644 --- a/src/data/transformations.h +++ b/src/data/transformations.h @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2006, 2009, 2011 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2006, 2009, 2011, 2013 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 @@ -32,7 +32,6 @@ enum trns_result }; struct ccase; -typedef void trns_finalize_func (void *); typedef int trns_proc_func (void *, struct ccase **, casenumber); typedef bool trns_free_func (void *); @@ -44,7 +43,7 @@ bool trns_chain_destroy (struct trns_chain *); bool trns_chain_is_empty (const struct trns_chain *); -void trns_chain_append (struct trns_chain *, trns_finalize_func *, +void trns_chain_append (struct trns_chain *, trns_proc_func *, trns_free_func *, void *); size_t trns_chain_next (struct trns_chain *); enum trns_result trns_chain_execute (const struct trns_chain *, diff --git a/src/language/control/do-if.c b/src/language/control/do-if.c index 6b6dc16d4d..bbb8fa92c5 100644 --- a/src/language/control/do-if.c +++ b/src/language/control/do-if.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009-2012 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009-2013 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 @@ -89,7 +89,6 @@ static bool has_else (struct do_if_trns *); static bool must_not_have_else (struct do_if_trns *); static void close_do_if (void *do_if); -static trns_finalize_func do_if_finalize_func; static trns_proc_func do_if_trns_proc, break_trns_proc; static trns_free_func do_if_trns_free; @@ -103,8 +102,7 @@ cmd_do_if (struct lexer *lexer, struct dataset *ds) do_if->ds = ds; ctl_stack_push (&do_if_class, do_if); - add_transformation_with_finalizer (ds, do_if_finalize_func, - do_if_trns_proc, do_if_trns_free, do_if); + add_transformation (ds, do_if_trns_proc, do_if_trns_free, do_if); return parse_clause (lexer, do_if, ds); } @@ -225,17 +223,6 @@ add_clause (struct do_if_trns *do_if, struct expression *condition) clause->target_index = next_transformation (do_if->ds); } -/* Finalizes DO IF by clearing the control stack, thus ensuring - that all open DO IFs are closed. */ -static void -do_if_finalize_func (void *do_if_ UNUSED) -{ - /* This will be called multiple times if multiple DO IFs were - executed, which is slightly unclean, but at least it's - idempotent. */ - ctl_stack_clear (); -} - /* DO IF transformation procedure. Checks each clause and jumps to the appropriate transformation. */ diff --git a/src/language/control/loop.c b/src/language/control/loop.c index cece7f68f6..4d2aaa33a4 100644 --- a/src/language/control/loop.c +++ b/src/language/control/loop.c @@ -1,5 +1,5 @@ /* PSPP - a program for statistical analysis. - Copyright (C) 1997-9, 2000, 2009-2011 Free Software Foundation, Inc. + Copyright (C) 1997-9, 2000, 2009-2011, 2013 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 @@ -81,7 +81,6 @@ struct loop_trns static const struct ctl_class loop_class; -static trns_finalize_func loop_trns_finalize; static trns_proc_func loop_trns_proc, end_loop_trns_proc, break_trns_proc; static trns_free_func loop_trns_free; @@ -282,8 +281,7 @@ create_loop_trns (struct dataset *ds) loop->loop_condition = loop->end_loop_condition = NULL; loop->ds = ds; - add_transformation_with_finalizer (ds, loop_trns_finalize, - loop_trns_proc, loop_trns_free, loop); + add_transformation (ds, loop_trns_proc, loop_trns_free, loop); loop->past_LOOP_index = next_transformation (ds); ctl_stack_push (&loop_class, loop); @@ -291,17 +289,6 @@ create_loop_trns (struct dataset *ds) return loop; } -/* Finalizes LOOP by clearing the control stack, thus ensuring - that all open LOOPs are closed. */ -static void -loop_trns_finalize (void *do_if_ UNUSED) -{ - /* This will be called multiple times if multiple LOOPs were - executed, which is slightly unclean, but at least it's - idempotent. */ - ctl_stack_clear (); -} - /* Sets up LOOP for the first pass. */ static int loop_trns_proc (void *loop_, struct ccase **c, casenumber case_num) -- 2.30.2