# HG changeset patch # User John W. Eaton # Date 1420478151 18000 # Node ID ffbd2cc7ca917d795f1c016b09047a1177258ea8 # Parent 827cc33ae05cdf5b1cd8be19f47e27d367ab928a savepath: avoid possible error in struct concatenation * savepath.m: Use cellfun to simplify extraction and concatenation of struct elements. Tag warning with ID and disable warning in test. diff -r 827cc33ae05c -r ffbd2cc7ca91 scripts/path/savepath.m --- a/scripts/path/savepath.m Mon Jan 05 11:36:33 2015 -0500 +++ b/scripts/path/savepath.m Mon Jan 05 12:15:51 2015 -0500 @@ -107,18 +107,11 @@ ## Determine the path to Octave's user and system wide packages. [pkg_user, pkg_system] = pkg ("list"); - ## Conversion from cell array of structs to cellstr of archprefixes - if (isempty (pkg_user)) - pkg_user_path = {}; - else - pkg_user_path = {[pkg_user{:}].archprefix}; - endif - if (isempty (pkg_system)) - pkg_system_path = {}; - else - pkg_system_path = {[pkg_system{:}].archprefix}; - endif - pkg_path = union (pkg_user_path, pkg_system_path); + + ## Conversion from cell array of structs to cellstr of archprefixes. + pkg_path = unique (cellfun (@(elt) elt.archprefix, + [pkg_user, pkg_system], + "uniformoutput", false)); ## Rely on Octave's initialization to include the pkg path elements. if (! isempty (pkg_path)) @@ -177,7 +170,8 @@ error ("savepath: could not close savefile after writing, %s", file); elseif (nargin == 0) warning ("off", "backtrace", "local"); - warning ("savepath: current path saved to %s", file); + warning ("Octave:savepath-local", + "savepath: current path saved to %s", file); endif end_unwind_protect @@ -192,7 +186,6 @@ path_elements = strcat (ostrsplit (p, pathsep), pathsep); endfunction - %!test %! fname = tempname (); %! status = savepath (fname); @@ -208,6 +201,7 @@ %! assert (fid >= 0); %! fclose (fid); %! ## Save path into local .octaverc file +%! warning ("off", "Octave:savepath-local"); %! status = savepath (); %! assert (status == 0); %! ## Compare old and new versions