gui: Fix crash in executor when inline data is missing.
[pspp-builds.git] / src / ui / gui / executor.c
index 3afa1ecd022359d2b0e72468c962451fe0477fb4..123000fedf9d7434f3e0d793508cd9164e62faee 100644 (file)
@@ -1,5 +1,5 @@
 /* PSPPIRE - a graphical user interface for PSPP.
-   Copyright (C) 2007, 2009, 2010  Free Software Foundation
+   Copyright (C) 2007, 2009, 2010, 2011  Free Software Foundation
 
    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
@@ -50,9 +50,9 @@ execute_syntax (struct lex_reader *lex_reader)
   unsigned long int lazy_serial;
 
   /* When the user executes a number of snippets of syntax in a
-     row, none of which read from the active file, the GUI becomes
+     row, none of which read from the active dataset, the GUI becomes
      progressively less responsive.  The reason is that each syntax
-     execution encapsulates the active file data in another
+     execution encapsulates the active dataset data in another
      datasheet layer.  The cumulative effect of having a number of
      layers of datasheets wastes time and space.
 
@@ -67,9 +67,9 @@ execute_syntax (struct lex_reader *lex_reader)
   reader = lazy_casereader_create (proto, case_cnt,
                                    create_casereader_from_data_store,
                                    the_data_store, &lazy_serial);
-  proc_set_active_file_data (the_dataset, reader);
+  dataset_set_source (the_dataset, reader);
 
-  g_return_val_if_fail (proc_has_active_file (the_dataset), FALSE);
+  g_return_val_if_fail (dataset_has_source (the_dataset), FALSE);
 
   lexer = lex_create ();
   psppire_set_lexer (lexer);
@@ -90,18 +90,22 @@ execute_syntax (struct lex_reader *lex_reader)
        break;
     }
 
-  lex_destroy (lexer);
-  psppire_set_lexer (NULL);
-
   proc_execute (the_dataset);
 
   psppire_dict_replace_dictionary (the_data_store->dict,
                                   dataset_dict (the_dataset));
 
-  reader = proc_extract_active_file_data (the_dataset);
+  reader = dataset_steal_source (the_dataset);
   if (!lazy_casereader_destroy (reader, lazy_serial))
     psppire_data_store_set_reader (the_data_store, reader);
 
+  /* Destroy the lexer only after obtaining the dataset, because the dataset
+     might depend on the lexer, if the casereader specifies inline data.  (In
+     such a case then we'll always get an error message--the inline data is
+     missing, otherwise it would have been parsed in the loop above.) */
+  lex_destroy (lexer);
+  psppire_set_lexer (NULL);
+
   output_flush ();
 
   return retval;