Mercurial > hg > octave-terminal
changeset 8455:fd11a08a9b31
disallow invalid {}-indexed assigments
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Sun, 11 Jan 2009 07:55:44 +0100 |
parents | aaf2b6d6813c |
children | c1709a45b45b |
files | scripts/ChangeLog scripts/general/sortrows.m scripts/miscellaneous/orderfields.m scripts/miscellaneous/what.m scripts/pkg/pkg.m scripts/plot/ndgrid.m scripts/strings/strcat.m src/ChangeLog src/oct-obj.cc src/oct-obj.h src/ov-cell.cc |
diffstat | 11 files changed, 40 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,3 +1,12 @@ +2009-01-11 Jaroslav Hajek <highegg@gmail.com> + + * general/sortrows.m: Fix invalid `{x:y} = z' assignment. + * miscellaneous/orderfields.m: Dtto. + * miscellaneous/what.m: Dtto. + * pkg/pkg.m: Dtto. + * plot/ndgrid.m: Dtto. + * strings/strcat.m: Dtto. + 2009-01-09 Kai Habel <kai.habel@gmx.de> * plot/surfl.m: New function
--- a/scripts/general/sortrows.m +++ b/scripts/general/sortrows.m @@ -34,7 +34,7 @@ other_mode = "descend"; if (nargin < 2) indices = [1:size(m,2)]'; - mode{1:size(m,2)} = default_mode; + mode(1:size(m,2)) = {default_mode}; else for ii = 1:length (c); if (c(ii) < 0)
--- a/scripts/miscellaneous/orderfields.m +++ b/scripts/miscellaneous/orderfields.m @@ -90,7 +90,7 @@ if (numel (s1) == 0) args = cell (1, 2 * numel (names)); args(1:2:end) = names; - args{2:2:end} = {}; + args(2:2:end) = {[]}; t = struct (args{:}); else for i = 1:numel (names)
--- a/scripts/miscellaneous/what.m +++ b/scripts/miscellaneous/what.m @@ -107,8 +107,7 @@ for i = 1 : nrows args = f(i:nrows:end); if (length (args) < ncols) - n = ncols - length (args); - args{end : end + n} = ""; + args(end : ncols) = {""}; endif printf (fmt, args{:}); endfor
--- a/scripts/pkg/pkg.m +++ b/scripts/pkg/pkg.m @@ -971,11 +971,11 @@ describe_all = false; if (any (strcmp ("all", pkgnames))) describe_all = true; - flag{1:num_packages} = "Not Loaded"; + flag(1:num_packages) = {"Not Loaded"}; num_pkgnames = num_packages; else num_pkgnames = length (pkgnames); - flag{1:num_pkgnames} = "Not installed"; + flag(1:num_pkgnames) = {"Not installed"}; endif for i = 1:num_packages
--- a/scripts/plot/ndgrid.m +++ b/scripts/plot/ndgrid.m @@ -37,7 +37,7 @@ if (nargin == 1) n = max ([nargout, 2]); ## If only one input argument is given, repeat it n-times - varargin{1:n} = varargin{1}; + varargin(1:n) = varargin(1); elseif (nargin >= nargout) n = max ([nargin, 2]); else
--- a/scripts/strings/strcat.m +++ b/scripts/strings/strcat.m @@ -86,7 +86,7 @@ for nv = find (numstrs == 1) str = varargin{nv}{1}; varargin{nv} = cell (dim); - varargin{nv}{:} = str; + varargin{nv}(:) = {str}; endfor ## Concatenate the strings
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,10 @@ +2009-01-11 Jaroslav Hajek <highegg@gmail.com> + + * oct-obj.cc (octave_value_list::all_scalars): New method. + * oct-obj.h: Declare it. + * ov-cell.cc (octave_cell::subsasgn): Disable assigning + to non-scalar {}-indexed cell, unless in a multi-assignment. + 2009-01-10 Jaroslav Hajek <highegg@gmail.com> * DLD-FUNCTIONS/sparse.cc (Ffull): Convert diagonal & permutation
--- a/src/oct-obj.cc +++ b/src/oct-obj.cc @@ -162,6 +162,16 @@ } bool +octave_value_list::all_scalars (void) const +{ + octave_idx_type n = length (), i; + + for (i = 0; i < n && elem (i).is_string (); i++) ; + + return i == n; +} + +bool octave_value_list::has_magic_colon (void) const { octave_idx_type n = length ();
--- a/src/oct-obj.h +++ b/src/oct-obj.h @@ -111,6 +111,8 @@ bool all_strings_p (void) const; + bool all_scalars (void) const; + bool has_magic_colon (void) const; string_vector make_argv (const std::string& = std::string()) const;
--- a/src/ov-cell.cc +++ b/src/ov-cell.cc @@ -268,9 +268,11 @@ octave_base_matrix<Cell>::assign (i, tmp_cell); } - else - // Regularize a null matrix if stored into a struct component. - octave_base_matrix<Cell>::assign (i, Cell (t_rhs.non_null_value ())); + else if (i.all_scalars () || do_index_op (i, true).dims ().numel () == 1) + // Regularize a null matrix if stored into a cell. + octave_base_matrix<Cell>::assign (i, Cell (t_rhs.non_null_value ())); + else if (! error_state) + error ("scalar indices required for {} in assignment."); if (! error_state) {