transformations: Remove finalize functions.
authorBen Pfaff <blp@cs.stanford.edu>
Tue, 14 May 2013 00:04:30 +0000 (17:04 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 16 Feb 2015 19:24:47 +0000 (11:24 -0800)
src/data/dataset.c
src/data/dataset.h
src/data/transformations.c
src/data/transformations.h
src/language/control/do-if.c
src/language/control/loop.c

index 7a5a6a4a6a08a22749baf5340b9e71d709d66c51..5b3f0ba5fb3a1b65c241f8757af77d08bfca2de9 100644 (file)
@@ -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);
 }
 
index ce8b980d2e69c1cbc6207bd7c3ce8dc3b77a3c23..3f0d2e689f1a05f3ff914b6f9609264c54074d1b 100644 (file)
@@ -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);
index 209d13f82bf816653cba78240060924cb206c2fe..884def67531de301129872b6298f96327b6d5d09 100644 (file)
@@ -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 <stdlib.h>
 
 #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;
index 013bcaa731e8e29adedaad8eb04d75b46e3e37e4..5e1488323b1936808f46496843fdfcd5c7ac3a45 100644 (file)
@@ -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 *);
 \f
@@ -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 *,
index 6b6dc16d4de600362035e9d39c35afa1f0e5e456..bbb8fa92c5ee1343b7a620f586b578f1757e18a9 100644 (file)
@@ -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. */
index cece7f68f647cf91e1fd925759c9b7c7a0c80f06..4d2aaa33a44636e615618fc3de27a3846206a023 100644 (file)
@@ -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)