changeset 21953:c46e2532d421

Add directories through addpath in the correct order (bug #48247). * load-path.cc (Faddpath): Copy input args to function into local variable arglist. Reverse arglist if 'append' option is given.
author Rik <rik@octave.org>
date Sun, 19 Jun 2016 18:04:07 -0700
parents a5924b0cbf42
children 6da01de4dd8a
files libinterp/corefcn/load-path.cc
diffstat 1 files changed, 10 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/load-path.cc	Sun Jun 19 06:23:54 2016 -0700
+++ b/libinterp/corefcn/load-path.cc	Sun Jun 19 18:04:07 2016 -0700
@@ -2402,8 +2402,8 @@
 @seealso{path, rmpath, genpath, pathdef, savepath, pathsep}\n\
 @end deftypefn")
 {
-  // Originally written by Bill Denney and Etienne Grossman.  Heavily
-  // modified and translated to C++ by jwe.
+  // Originally written by Bill Denney and Etienne Grossman.
+  // Heavily modified and translated to C++ by jwe.
 
   int nargin = args.length ();
 
@@ -2448,20 +2448,22 @@
 
   bool need_to_update = false;
 
-  for (int i = 0; i < nargin; i++)
+  octave_value_list arglist (args.slice (0, nargin));
+  if (! append)
+    arglist.reverse ();
+
+  for (int i = 0; i < arglist.length (); i++)
     {
-      std::string arg = args(i).xstring_value ("addpath: all arguments must be strings");
+      std::string arg = arglist(i).xstring_value ("addpath: all arguments must be strings");
 
       std::list<std::string> dir_elts = split_path (arg);
 
       if (! append)
         std::reverse (dir_elts.begin (), dir_elts.end ());
 
-      for (std::list<std::string>::const_iterator p = dir_elts.begin ();
-           p != dir_elts.end ();
-           p++)
+      for (const auto& p : dir_elts)
         {
-          std::string dir = *p;
+          std::string dir = p;
 
           //dir = regexprep (dir_elts{j}, '//+', "/");
           //dir = regexprep (dir, '/$', "");