Work on getting rid of trns_chain_finalize(). pxd
authorBen Pfaff <blp@cs.stanford.edu>
Mon, 5 Aug 2013 02:20:14 +0000 (19:20 -0700)
committerBen Pfaff <blp@cs.stanford.edu>
Mon, 16 Feb 2015 19:25:56 +0000 (11:25 -0800)
src/data/dataset.c
src/data/transformations.c
src/data/transformations.h
src/language/data-io/inpt-pgm.c

index 5b3f0ba5fb3a1b65c241f8757af77d08bfca2de9..afab39dc0c5e63a4bdfa2a6ba4d49b6b37c65137 100644 (file)
@@ -30,6 +30,7 @@
 #include "data/casereader-provider.h"
 #include "data/casereader-shim.h"
 #include "data/casewriter.h"
+#include "data/control-stack.h"
 #include "data/dictionary.h"
 #include "data/file-handle-def.h"
 #include "data/session.h"
@@ -201,6 +202,7 @@ dataset_destroy (struct dataset *ds)
       dataset_clear (ds);
       dict_destroy (ds->dict);
       caseinit_destroy (ds->caseinit);
+      ctl_stack_clear ();
       trns_chain_destroy (ds->permanent_trns_chain);
       dataset_transformations_changed__ (ds, false);
       free (ds->name);
@@ -426,7 +428,7 @@ proc_open_filtering (struct dataset *ds, bool filter)
   add_case_limit_trns (ds);
   if (filter)
     add_filter_trns (ds);
-  trns_chain_finalize (ds->cur_trns_chain);
+  ctl_stack_clear ();
 
   /* Make permanent_dict refer to the dictionary right before
      data reaches the sink. */
@@ -725,7 +727,7 @@ proc_start_temporary_transformations (struct dataset *ds)
 
       ds->permanent_dict = dict_clone (ds->dict);
 
-      trns_chain_finalize (ds->permanent_trns_chain);
+      ctl_stack_clear ();
       ds->temporary_trns_chain = ds->cur_trns_chain = trns_chain_create ();
       dataset_transformations_changed__ (ds, true);
     }
@@ -744,7 +746,7 @@ proc_make_temporary_transformations_permanent (struct dataset *ds)
 {
   if (proc_in_temporary_transformations (ds))
     {
-      trns_chain_finalize (ds->temporary_trns_chain);
+      ctl_stack_clear ();
       trns_chain_splice (ds->permanent_trns_chain, ds->temporary_trns_chain);
       ds->temporary_trns_chain = NULL;
 
@@ -771,6 +773,7 @@ proc_cancel_temporary_transformations (struct dataset *ds)
       ds->dict = ds->permanent_dict;
       ds->permanent_dict = NULL;
 
+      ctl_stack_clear ();
       trns_chain_destroy (ds->temporary_trns_chain);
       ds->temporary_trns_chain = NULL;
       dataset_transformations_changed__ (
@@ -788,6 +791,7 @@ proc_cancel_all_transformations (struct dataset *ds)
 {
   bool ok;
   assert (ds->proc_state == PROC_COMMITTED);
+  ctl_stack_clear ();
   ok = trns_chain_destroy (ds->permanent_trns_chain);
   ok = trns_chain_destroy (ds->temporary_trns_chain) && ok;
   ds->permanent_trns_chain = ds->cur_trns_chain = trns_chain_create ();
index 46241c8fc2bab393571233def90bb16fb1a261ba..8b246b7399d036826361412bc0b3657b702f4a93 100644 (file)
@@ -44,7 +44,6 @@ struct trns_chain
     struct transformation *trns;        /* Array of transformations. */
     size_t trns_cnt;                    /* Number of transformations. */
     size_t trns_cap;                    /* Allocated capacity. */
-    bool finalized;                     /* Finalize functions called? */
   };
 
 /* Allocates and returns a new transformation chain. */
@@ -55,24 +54,10 @@ trns_chain_create (void)
   chain->trns = NULL;
   chain->trns_cnt = 0;
   chain->trns_cap = 0;
-  chain->finalized = false;
   return chain;
 }
 
-/* Finalizes all the un-finalized transformations in CHAIN.
-   Any given transformation is only finalized once. */
-void
-trns_chain_finalize (struct trns_chain *chain)
-{
-  while (!chain->finalized)
-    {
-      ctl_stack_clear ();       /* XXX layering violation */
-      chain->finalized = true;
-    }
-}
-
-/* Destroys CHAIN, finalizing it in the process if it has not
-   already been finalized. */
+/* Destroys CHAIN. */
 bool
 trns_chain_destroy (struct trns_chain *chain)
 {
@@ -82,9 +67,6 @@ trns_chain_destroy (struct trns_chain *chain)
     {
       size_t i;
 
-      /* Needed to ensure that the control stack gets cleared. */
-      trns_chain_finalize (chain);
-
       for (i = 0; i < chain->trns_cnt; i++)
         {
           struct transformation *trns = &chain->trns[i];
@@ -114,8 +96,6 @@ trns_chain_append (struct trns_chain *chain, trns_proc_func *execute,
 {
   struct transformation *trns;
 
-  chain->finalized = false;
-
   if (chain->trns_cnt == chain->trns_cap)
     chain->trns = x2nrealloc (chain->trns, &chain->trns_cap,
                               sizeof *chain->trns);
@@ -127,17 +107,12 @@ trns_chain_append (struct trns_chain *chain, trns_proc_func *execute,
   trns->aux = aux;
 }
 
-/* Appends the transformations in SRC to those in DST,
-   and destroys SRC.
-   Both DST and SRC must already be finalized. */
+/* Appends the transformations in SRC to those in DST, and destroys SRC. */
 void
 trns_chain_splice (struct trns_chain *dst, struct trns_chain *src)
 {
   size_t i;
 
-  assert (dst->finalized);
-  assert (src->finalized);
-
   if (dst->trns_cnt + src->trns_cnt > dst->trns_cap)
     {
       dst->trns_cap = dst->trns_cnt + src->trns_cnt;
@@ -177,7 +152,6 @@ trns_chain_execute (const struct trns_chain *chain, enum trns_result start,
 {
   int i;
 
-  assert (chain->finalized);
   for (i = start < 0 ? 0 : start; i < chain->trns_cnt; )
     {
       struct transformation *trns = &chain->trns[i];
index 66ddb4e0fb63a4688f05b7f70e78d5000b0a5040..1d422376a628ec854fd71ba67c99c1f6b5df04ed 100644 (file)
@@ -49,7 +49,6 @@ struct trns_class
 /* Transformation chains. */
 
 struct trns_chain *trns_chain_create (void);
-void trns_chain_finalize (struct trns_chain *);
 bool trns_chain_destroy (struct trns_chain *);
 
 bool trns_chain_is_empty (const struct trns_chain *);
index b9488f17f47604bcfd92ac9c80c4a79dda9a132c..607196169b1dc1ca3c7ec7f7d9e922dc1e7b4392 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012, 2013 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2009, 2010, 2011, 2012, 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 "data/case.h"
 #include "data/caseinit.h"
 #include "data/casereader-provider.h"
+#include "data/control-stack.h"
 #include "data/dataset.h"
 #include "data/dictionary.h"
 #include "data/session.h"
@@ -154,8 +155,8 @@ cmd_input_program (struct lexer *lexer, struct dataset *ds)
       return CMD_FAILURE;
     }
 
-  inp->trns_chain = proc_capture_transformations (inp->ds);
-  trns_chain_finalize (inp->trns_chain);
+  ctl_stack_clear ();
+  inp->trns_chain = proc_capture_transformations (ds);
 
   inp->restart = TRNS_CONTINUE;
 
@@ -230,6 +231,7 @@ destroy_input_program (struct input_program_pgm *pgm)
   if (pgm != NULL)
     {
       session_destroy (pgm->session);
+      ctl_stack_clear ();
       trns_chain_destroy (pgm->trns_chain);
       caseinit_destroy (pgm->init);
       caseproto_unref (pgm->proto);