more work on datasets
[pspp] / src / data / dataset.c
index 9c3fe8cfecffc9003781836fe616bd3dc5858bf3..7972a5ddcc75889586a9cd44fe09a4a56388edca 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPP - a program for statistical analysis.
-   Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2013 Free Software Foundation, Inc.
+   Copyright (C) 1997-9, 2000, 2006, 2007, 2009, 2010, 2011, 2013, 2016 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
@@ -267,10 +267,12 @@ dataset_set_session (struct dataset *ds, struct session *session)
 {
   if (session != ds->session)
     {
+      dataset_ref (ds);
       if (ds->session != NULL)
         session_remove_dataset (ds->session, ds);
       if (session != NULL)
         session_add_dataset (session, ds);
+      dataset_unref (ds);
     }
 }
 
@@ -746,9 +748,13 @@ proc_start_temporary_transformations (struct dataset *ds)
     }
 }
 
-/* Converts all the temporary transformations, if any, to
-   permanent transformations.  Further transformations will be
-   permanent.
+/* Converts all the temporary transformations, if any, to permanent
+   transformations.  Further transformations will be permanent.
+
+   The FILTER command is implemented as a temporary transformation, so a
+   procedure that uses this function should usually use proc_open_filtering()
+   with FILTER false, instead of plain proc_open().
+
    Returns true if anything changed, false otherwise. */
 bool
 proc_make_temporary_transformations_permanent (struct dataset *ds)
@@ -759,6 +765,8 @@ proc_make_temporary_transformations_permanent (struct dataset *ds)
       trns_chain_splice (ds->permanent_trns_chain, ds->temporary_trns_chain);
       ds->temporary_trns_chain = NULL;
 
+      ds->cur_trns_chain = ds->permanent_trns_chain;
+
       dict_destroy (ds->permanent_dict);
       ds->permanent_dict = NULL;
 
@@ -968,5 +976,12 @@ dataset_transformations_changed__ (struct dataset *ds, bool non_empty)
 void
 dataset_set_session__ (struct dataset *ds, struct session *session)
 {
-  ds->session = session;
+  if (ds->session != session)
+    {
+      if (ds->session)
+        dataset_unref (ds->session);
+      ds->session = session;
+      if (session)
+        dataset_ref (session);
+    }
 }