changeset 21415:74a676d5ce09

use safe_source_file for PKG_ADD and PKG_DEL files (bug #47346) * oct-parse.in.yy (safe_source_file, gripe_safe_source_exception): Move here from octave.cc. * parse.h (safe_source_file): Provide decl. * load-path.cc (execute_pkg_add_or_del): Call safe_source_file instead of source_file.
author John W. Eaton <jwe@octave.org>
date Tue, 08 Mar 2016 06:19:57 -0500
parents 1562e7e27f6d
children fdeb0d731512
files libinterp/corefcn/load-path.cc libinterp/octave.cc libinterp/parse-tree/oct-parse.in.yy libinterp/parse-tree/parse.h
diffstat 4 files changed, 47 insertions(+), 40 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/load-path.cc	Mon Mar 07 20:01:37 2016 -0500
+++ b/libinterp/corefcn/load-path.cc	Tue Mar 08 06:19:57 2016 -0500
@@ -2216,7 +2216,7 @@
   file_stat fs (file);
 
   if (fs.exists ())
-    source_file (file, "base");
+    safe_source_file (file, "base");
 }
 
 void
--- a/libinterp/octave.cc	Mon Mar 07 20:01:37 2016 -0500
+++ b/libinterp/octave.cc	Tue Mar 08 06:19:57 2016 -0500
@@ -257,45 +257,6 @@
   F__version_info__ (args, 0);
 }
 
-static void
-gripe_safe_source_exception (const std::string& file, const std::string& msg)
-{
-  std::cerr << "error: " << msg << "\n"
-            << "error: execution of " << file << " failed\n"
-            << "error: trying to make my way to a command prompt"
-            << std::endl;
-}
-
-// Execute commands from a file and catch potential exceptions in a consistent
-// way.  This function should be called anywhere we might parse and execute
-// commands from a file before before we have entered the main loop in
-// toplev.cc.
-
-static void
-safe_source_file (const std::string& file_name,
-                  const std::string& context = "",
-                  bool verbose = false, bool require_file = true,
-                  const std::string& warn_for = "")
-{
-  try
-    {
-      source_file (file_name, context, verbose, require_file, warn_for);
-    }
-  catch (const octave_interrupt_exception&)
-    {
-      recover_from_exception ();
-
-      if (quitting_gracefully)
-        clean_up_and_exit (exit_status);
-    }
-  catch (const octave_execution_exception&)
-    {
-      recover_from_exception ();
-
-      gripe_safe_source_exception (file_name, "unhandled execution exception");
-    }
-}
-
 // Initialize by reading startup files.
 
 static void
@@ -782,6 +743,9 @@
 
   install_classdef ();
 
+  // Setting the command line path just stores the directory names, it
+  // does not execute PKG_ADD scripts as we are not ready to do that yet.  
+
   for (std::list<std::string>::const_iterator it = command_line_path.begin ();
        it != command_line_path.end (); it++)
     load_path::set_command_line_path (*it);
--- a/libinterp/parse-tree/oct-parse.in.yy	Mon Mar 07 20:01:37 2016 -0500
+++ b/libinterp/parse-tree/oct-parse.in.yy	Tue Mar 08 06:19:57 2016 -0500
@@ -4622,6 +4622,43 @@
     }
 }
 
+static void
+gripe_safe_source_exception (const std::string& file, const std::string& msg)
+{
+  std::cerr << "error: " << msg << "\n"
+            << "error: execution of " << file << " failed\n"
+            << "error: trying to make my way to a command prompt"
+            << std::endl;
+}
+
+// Execute commands from a file and catch potential exceptions in a consistent
+// way.  This function should be called anywhere we might parse and execute
+// commands from a file before before we have entered the main loop in
+// toplev.cc.
+
+void
+safe_source_file (const std::string& file_name, const std::string& context,
+                  bool verbose, bool require_file, const std::string& warn_for)
+{
+  try
+    {
+      source_file (file_name, context, verbose, require_file, warn_for);
+    }
+  catch (const octave_interrupt_exception&)
+    {
+      recover_from_exception ();
+
+      if (quitting_gracefully)
+        clean_up_and_exit (exit_status);
+    }
+  catch (const octave_execution_exception&)
+    {
+      recover_from_exception ();
+
+      gripe_safe_source_exception (file_name, "unhandled execution exception");
+    }
+}
+
 DEFUN (mfilename, args, ,
   "-*- texinfo -*-\n\
 @deftypefn  {} {} mfilename ()\n\
--- a/libinterp/parse-tree/parse.h	Mon Mar 07 20:01:37 2016 -0500
+++ b/libinterp/parse-tree/parse.h	Tue Mar 08 06:19:57 2016 -0500
@@ -117,6 +117,12 @@
              bool verbose = false, bool require_file = true,
              const std::string& warn_for = "");
 
+extern OCTINTERP_API void
+safe_source_file (const std::string& file_name,
+                  const std::string& context = "",
+                  bool verbose = false, bool require_file = true,
+                  const std::string& warn_for = "");
+
 extern OCTINTERP_API octave_value_list
 feval (const std::string& name,
        const octave_value_list& args = octave_value_list (),