# HG changeset patch # User jwe # Date 1057962078 0 # Node ID af308ca1a354e3b95d283947471a61ecf90d8bf6 # Parent cef48c4b902db231f2fcdd8386fe10f3c0bcf306 [project @ 2003-07-11 22:21:17 by jwe] diff --git a/ChangeLog b/ChangeLog --- a/ChangeLog +++ b/ChangeLog @@ -1,8 +1,10 @@ 2003-07-11 John W. Eaton - * emacs/octave-mod.el (octave-variables): Add - warn_empty_list_elements to the list. - Delete empty_list_elements_ok from the list. + * emacs/octave-mod.el (octave-variables): + Add warn_empty_list_elements and warn_resize_on_range_error to the + list. + Delete empty_list_elements_ok and resize_on_range_error from the + list. 2003-07-10 John W. Eaton diff --git a/doc/interpreter/expr.txi b/doc/interpreter/expr.txi --- a/doc/interpreter/expr.txi +++ b/doc/interpreter/expr.txi @@ -167,7 +167,7 @@ size whose elements are all one, and then to scale it to produce the desired result. @xref{Special Utility Matrices}. -@DOCSTRING(resize_on_range_error) +@DOCSTRING(warn_resize_on_range_error) Note that it is quite inefficient to create a vector using a loop like the one shown in the example above. In this particular case, it would diff --git a/doc/interpreter/var.txi b/doc/interpreter/var.txi --- a/doc/interpreter/var.txi +++ b/doc/interpreter/var.txi @@ -321,11 +321,6 @@ Default value: 1. -@item resize_on_range_error -@xref{Index Expressions}. - -Default value: 1. - @item return_last_computed_value @xref{Returning From a Function}. @@ -431,6 +426,11 @@ Default value: 1. +@item warn_resize_on_range_error +@xref{Index Expressions}. + +Default value: 0. + @item warn_single_quote_string) @xref{String Conversions}. diff --git a/emacs/octave-mod.el b/emacs/octave-mod.el --- a/emacs/octave-mod.el +++ b/emacs/octave-mod.el @@ -148,17 +148,19 @@ "page_output_immediately" "page_screen_output" "pi" "print_answer_id_name" "print_empty_dimensions" "program_invocation_name" "program_name" "propagate_empty_matrices" - "realmax" "realmin" "resize_on_range_error" - "return_last_computed_value" "save_precision" "saving_history" - "sighup_dumps_octave_core" "sigterm_dumps_octave_core" + "realmax" "realmin" "return_last_computed_value" "save_precision" + "saving_history" "sighup_dumps_octave_core" "sigterm_dumps_octave_core" "silent_functions" "split_long_rows" "stderr" "stdin" "stdout" "string_fill_char" "struct_levels_to_print" "suppress_verbose_help_message" "warn_assign_as_truth_value" - "warn_comma_in_global_decl" "warn_divide_by_zero" - "warn_empty_list_elements" "warn_fortran_indexing" - "warn_function_name_clash" "warn_imag_to_real" - "warn_missing_semicolon" "warn_neg_dim_as_zero" - "warn_num_to_str" "warn_str_to_num" "whitespace_in_literal_matrix") + "warn_divide_by_zero" "warn_empty_list_elements" + "warn_fortran_indexing" "warn_function_name_clash" + "warn_future_time_stamp" "warn_imag_to_real" + "warn_matlab_incompatible" "warn_missing_semicolon" + "warn_neg_dim_as_zero" "warn_num_to_str" "warn_precedence_change" + "warn_reload_forces_clear" "warn_separator_insert" + "warn_single_quote_string" "warn_str_to_num" + "warn_variable_switch_label") "Builtin variables in Octave.") (defvar octave-function-header-regexp diff --git a/liboctave/Array-flags.cc b/liboctave/Array-flags.cc --- a/liboctave/Array-flags.cc +++ b/liboctave/Array-flags.cc @@ -30,8 +30,8 @@ #if defined (HEAVYWEIGHT_INDEXING) -int liboctave_wfi_flag = 0; -int liboctave_rre_flag = 0; +bool liboctave_wfi_flag = false; +bool liboctave_wrore_flag = false; #endif diff --git a/liboctave/Array-flags.h b/liboctave/Array-flags.h --- a/liboctave/Array-flags.h +++ b/liboctave/Array-flags.h @@ -22,7 +22,7 @@ #if defined (OCTAVE_SOURCE) extern int liboctave_wfi_flag; -extern int liboctave_rre_flag; +extern int liboctave_wrore_flag; #endif /* diff --git a/liboctave/Array-idx.h b/liboctave/Array-idx.h --- a/liboctave/Array-idx.h +++ b/liboctave/Array-idx.h @@ -69,8 +69,7 @@ template Array -Array::index (idx_vector& idx_arg, int resize_ok, - const T& resize_fill_value) const +Array::index (idx_vector& idx_arg, int resize_ok, const T& rfv) const { Array retval; @@ -102,7 +101,7 @@ { int ii = idx_arg.elem (i); if (ii >= len) - retval.elem (i) = resize_fill_value; + retval.elem (i) = rfv; else retval.elem (i) = elem (ii); } @@ -181,7 +180,7 @@ template int -assign (Array& lhs, const Array& rhs, const LT& resize_fill_value) +assign (Array& lhs, const Array& rhs, const LT& rfv) { int retval = 1; @@ -192,15 +191,15 @@ int lhs_len = lhs.length (); int rhs_len = rhs.length (); - int n = lhs_idx.freeze (lhs_len, "vector", liboctave_rre_flag); + int n = lhs_idx.freeze (lhs_len, "vector", true, liboctave_wrore_flag); if (n != 0) { - if (liboctave_rre_flag && (rhs_len == n || rhs_len == 1)) + if (rhs_len == n || rhs_len == 1) { int max_idx = lhs_idx.max () + 1; if (max_idx > lhs_len) - lhs.resize (max_idx, resize_fill_value); + lhs.resize (max_idx, rfv); } if (rhs_len == n) diff --git a/liboctave/Array.h b/liboctave/Array.h --- a/liboctave/Array.h +++ b/liboctave/Array.h @@ -271,7 +271,7 @@ template int -assign (Array& lhs, const Array& rhs, const LT& resize_fill_value); +assign (Array& lhs, const Array& rhs, const LT& rfv); template diff --git a/liboctave/Array2-idx.h b/liboctave/Array2-idx.h --- a/liboctave/Array2-idx.h +++ b/liboctave/Array2-idx.h @@ -488,16 +488,13 @@ #define MAYBE_RESIZE_LHS \ do \ { \ - if (liboctave_rre_flag) \ - { \ - int max_row_idx = idx_i_is_colon ? rhs_nr : idx_i.max () + 1; \ - int max_col_idx = idx_j_is_colon ? rhs_nc : idx_j.max () + 1; \ + int max_row_idx = idx_i_is_colon ? rhs_nr : idx_i.max () + 1; \ + int max_col_idx = idx_j_is_colon ? rhs_nc : idx_j.max () + 1; \ \ - int new_nr = max_row_idx > lhs_nr ? max_row_idx : lhs_nr; \ - int new_nc = max_col_idx > lhs_nc ? max_col_idx : lhs_nc; \ + int new_nr = max_row_idx > lhs_nr ? max_row_idx : lhs_nr; \ + int new_nc = max_col_idx > lhs_nc ? max_col_idx : lhs_nc; \ \ - lhs.resize (new_nr, new_nc, rfv); \ - } \ + lhs.resize (new_nr, new_nc, rfv); \ } \ while (0) @@ -528,9 +525,9 @@ if (n_idx == 2) { - int n = idx_i.freeze (lhs_nr, "row", liboctave_rre_flag); + int n = idx_i.freeze (lhs_nr, "row", true, liboctave_wrore_flag); - int m = idx_j.freeze (lhs_nc, "column", liboctave_rre_flag); + int m = idx_j.freeze (lhs_nc, "column", true, liboctave_wrore_flag); int idx_i_is_colon = idx_i.is_colon (); int idx_j_is_colon = idx_j.is_colon (); @@ -616,7 +613,7 @@ { int lhs_len = lhs.length (); - int n = idx_i.freeze (lhs_len, 0, liboctave_rre_flag); + int n = idx_i.freeze (lhs_len, 0, true, liboctave_wrore_flag); if (idx_i) { @@ -674,7 +671,7 @@ } else if (lhs_nr == 1) { - idx_i.freeze (lhs_nc, "vector", liboctave_rre_flag); + idx_i.freeze (lhs_nc, "vector", true, liboctave_wrore_flag); if (idx_i) { @@ -692,7 +689,7 @@ } else if (lhs_nc == 1) { - idx_i.freeze (lhs_nr, "vector", liboctave_rre_flag); + idx_i.freeze (lhs_nr, "vector", true, liboctave_wrore_flag); if (idx_i) { diff --git a/liboctave/Array2.h b/liboctave/Array2.h --- a/liboctave/Array2.h +++ b/liboctave/Array2.h @@ -194,7 +194,7 @@ template int -assign (Array2& lhs, const Array2& rhs, const LT& resize_fill_value); +assign (Array2& lhs, const Array2& rhs, const LT& rfv); template int diff --git a/liboctave/Array3.h b/liboctave/Array3.h --- a/liboctave/Array3.h +++ b/liboctave/Array3.h @@ -158,7 +158,7 @@ template int -assign (Array3& lhs, const Array3& rhs, const LT& resize_fill_value); +assign (Array3& lhs, const Array3& rhs, const LT& rfv); template int diff --git a/liboctave/ArrayN-idx.h b/liboctave/ArrayN-idx.h --- a/liboctave/ArrayN-idx.h +++ b/liboctave/ArrayN-idx.h @@ -70,8 +70,7 @@ template ArrayN -ArrayN::index (idx_vector& ra_idx, int resize_ok, - const T& resize_fill_value) const +ArrayN::index (idx_vector& ra_idx, int resize_ok, const T& rfv) const { ArrayN retval; assert (0); @@ -200,8 +199,7 @@ template ArrayN -ArrayN::index (Array& ra_idx, int resize_ok, - const T& resize_fill_value) const +ArrayN::index (Array& ra_idx, int resize_ok, const T& rfv) const { ArrayN retval; @@ -242,7 +240,7 @@ Array elt_idx = get_elt_idx (result_idx); if (elt_idx > orig_len) - retval.elem (result_idx) = resize_fill_value; + retval.elem (result_idx) = rfv; else retval.elem (result_idx) = elem (elt_idx); diff --git a/liboctave/ArrayN.h b/liboctave/ArrayN.h --- a/liboctave/ArrayN.h +++ b/liboctave/ArrayN.h @@ -191,7 +191,7 @@ template int -assign (ArrayN& lhs, const ArrayN& rhs, const LT& resize_fill_value); +assign (ArrayN& lhs, const ArrayN& rhs, const LT& rfv); template int diff --git a/liboctave/ChangeLog b/liboctave/ChangeLog --- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,20 @@ +2003-07-11 John W. Eaton + + * Array2-idx.h (assign (Array2&, const Array2&, const LT&)): + Pass true for resize_ok arg to freeze. + * Array-idx.h (assign (Array&, const Array&, const LT&)): + Likewise. + + * idx-vector.cc (IDX_VEC_REP::freeze): New arg, warn_resize; + resize_ok arg is now bool. + * idx-vector.h (idx_vector::freeze): Likewise. + + * Array-flags.cc, Array-flags.h (liboctave_wrore_flag): + Rename from liboctave_rre_flag. Now bool. + (liboctave_wfi_flag): Now bool. + + * Array2-idx.h (MAYBE_RESIZE_LHS): Don't check liboctave_rre_flag. + 2003-07-11 Russell Standish * Array.h (resize_fill_value): Now a top-level template function. diff --git a/liboctave/idx-vector.cc b/liboctave/idx-vector.cc --- a/liboctave/idx-vector.cc +++ b/liboctave/idx-vector.cc @@ -612,7 +612,8 @@ } int -IDX_VEC_REP::freeze (int z_len, const char *tag, int resize_ok) +IDX_VEC_REP::freeze (int z_len, const char *tag, bool resize_ok, + bool warn_resize) { if (frozen) return frozen_len; @@ -655,7 +656,21 @@ initialized = 0; } else - frozen_len = length (z_len); + { + if (warn_resize && max_val >= z_len) + { + if (tag) + (*current_liboctave_error_handler) + ("resizing object with %s index = %d out of bounds", + tag, max_val+1); + else + (*current_liboctave_error_handler) + ("resizing object with index = %d out of bounds", + max_val+1); + } + + frozen_len = length (z_len); + } } } diff --git a/liboctave/idx-vector.h b/liboctave/idx-vector.h --- a/liboctave/idx-vector.h +++ b/liboctave/idx-vector.h @@ -111,7 +111,7 @@ void shorten (int n); // Unsafe. Avoid at all cost. - int freeze (int z_len, const char *tag, int resize_ok); + int freeze (int z_len, const char *tag, bool resize_ok, bool warn_resize); // i/o @@ -257,8 +257,9 @@ // i/o - int freeze (int z_len, const char *tag, int resize_ok = 0) - { return rep->freeze (z_len, tag, resize_ok); } + int freeze (int z_len, const char *tag, bool resize_ok = false, + bool warn_resize = false) + { return rep->freeze (z_len, tag, resize_ok, warn_resize); } std::ostream& print (std::ostream& os) const { return rep->print (os); } diff --git a/scripts/ChangeLog b/scripts/ChangeLog --- a/scripts/ChangeLog +++ b/scripts/ChangeLog @@ -1,5 +1,9 @@ 2003-07-11 John W. Eaton + * miscellaneous/dump_prefs.m: Add warn_resize_on_reange_error to + the list. + Delete resize_on_range_error from the list. + * control/base/pzmap.m, control/base/place.m, control/base/__freqresp__.m, control/system/sysappend.m, control/system/syscont.m, control/system/sysdisc.m, diff --git a/scripts/miscellaneous/dump_prefs.m b/scripts/miscellaneous/dump_prefs.m --- a/scripts/miscellaneous/dump_prefs.m +++ b/scripts/miscellaneous/dump_prefs.m @@ -82,7 +82,6 @@ "print_empty_dimensions"; "print_rhs_assign_val"; "propagate_empty_matrices"; - "resize_on_range_error"; "return_last_computed_value"; "save_precision"; "saving_history"; @@ -103,6 +102,7 @@ "warn_missing_semicolon"; "warn_neg_dim_as_zero"; "warn_num_to_str"; + "warn_resize_on_range_error"; "warn_str_to_num"; "warn_variable_switch_label"; "whitespace_in_literal_matrix"]; diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,10 +1,21 @@ 2003-07-11 John W. Eaton + * ov-list.cc (octave_list::assign): Check + Vwarn_resize_on_range_error, not Vresize_on_range_error. + + * ov.cc (Vwarn_resize_on_range_error): New variable. + (warn_resize_on_range_error): New function. + (symbols_of_ov): Add DEFVAR for warn_resize_on_range_error. + + * ov.cc (Vresize_on_range_error): Delete. + (resize_on_range_error): Delete. + (symbols_of_ov): Delete DEFVAR for resize_on_range_error. + * pt-mat.cc (Vwarn_empty_list_elements): New variable. (warn_empty_list_elements): New function. (symbols_of_pt_mat): Add DEFVAR for warn_empty_list_elements. - (): Check Vwarn_empty_list_elements, not - Vempty_list_elements_ok. + (tm_row_const::tm_row_const_rep::init, tm_const::init): + Check Vwarn_empty_list_elements, not Vempty_list_elements_ok. * pt-mat.cc (Vempty_list_elements_ok): Delete. (empty_list_elements_ok): Delete. diff --git a/src/ov-cs-list.cc b/src/ov-cs-list.cc --- a/src/ov-cs-list.cc +++ b/src/ov-cs-list.cc @@ -203,8 +203,13 @@ { int n = lst.length (); - if (i > 0 && (Vresize_on_range_error || i <= n)) - lst(i-1) = rhs; + if (i > 0) + { + if (Vwarn_resize_on_range_error && i > n) + warning ("list index = %d out of range", i); + + lst(i-1) = rhs; + } else error ("list index = %d out of range", i); } diff --git a/src/ov-list.cc b/src/ov-list.cc --- a/src/ov-list.cc +++ b/src/ov-list.cc @@ -201,8 +201,13 @@ { int n = lst.length (); - if (i > 0 && (Vresize_on_range_error || i <= n)) - lst(i-1) = rhs; + if (i > 0) + { + if (Vwarn_resize_on_range_error && i > n) + warning ("list index = %d out of range", i); + + lst(i-1) = rhs; + } else error ("list index = %d out of range", i); } diff --git a/src/ov.cc b/src/ov.cc --- a/src/ov.cc +++ b/src/ov.cc @@ -111,9 +111,9 @@ // Allow divide by zero errors to be suppressed. bool Vwarn_divide_by_zero; -// If TRUE, resize matrices when performing and indexed assignment and -// the indices are outside the current bounds. -bool Vresize_on_range_error; +// If TRUE, print a warning when a matrix is resized by an indexed +// assignment with indices outside the current bounds. +bool Vwarn_resize_on_range_error; // XXX FIXME XXX @@ -1804,11 +1804,12 @@ } static int -resize_on_range_error (void) +warn_resize_on_range_error (void) { - Vresize_on_range_error = check_preference ("resize_on_range_error"); + Vwarn_resize_on_range_error + = check_preference ("warn_resize_on_range_error"); - liboctave_rre_flag = Vresize_on_range_error; + liboctave_wrore_flag = Vwarn_resize_on_range_error; return 0; } @@ -1866,26 +1867,6 @@ if they are given one as an argument. The default value is 1.\n\ @end defvr"); - DEFVAR (resize_on_range_error, true, resize_on_range_error, - "-*- texinfo -*-\n\ -@defvr {Built-in Variable} resize_on_range_error\n\ -If the value of @code{resize_on_range_error} is nonzero, expressions\n\ -like\n\ -\n\ -@example\n\ -for i = 1:10\n\ - a (i) = sqrt (i);\n\ -endfor\n\ -@end example\n\ -\n\ -@noindent\n\ -(for @code{a} previously undefined) result in the variable @code{a}\n\ -being resized to be just large enough to hold the new value. New\n\ -elements that have not been given a value are set to zero. If the value\n\ -of @code{resize_on_range_error} is 0, an error message is printed and\n\ -control is returned to the top level. The default value is 1.\n\ -@end defvr"); - DEFVAR (silent_functions, false, silent_functions, "-*- texinfo -*-\n\ @defvr {Built-in Variable} silent_functions\n\ @@ -1956,6 +1937,14 @@ value is 1.\n\ @end defvr"); + DEFVAR (warn_resize_on_range_error, false, warn_resize_on_range_error, + "-*- texinfo -*-\n\ +@defvr {Built-in Variable} warn_resize_on_range_error\n\ +If the value of @code{warn_resize_on_range_error} is nonzero, print a\n\ +warning when a matrix is resized by an indexed assignment with\n\ +indices outside the current bounds. The default value is 0.\n\ +@end defvr"); + DEFVAR (warn_str_to_num, false, warn_str_to_num, "-*- texinfo -*-\n\ @defvr {Built-in Variable} warn_str_to_num\n\ diff --git a/src/ov.h b/src/ov.h --- a/src/ov.h +++ b/src/ov.h @@ -756,9 +756,9 @@ // Allow divide by zero errors to be suppressed. extern bool Vwarn_divide_by_zero; -// If TRUE, resize matrices when performing and indexed assignment and -// the indices are outside the current bounds. -extern bool Vresize_on_range_error; +// If TRUE, print a warning when a matrix is resized by an indexed +// assignment with indices outside the current bounds. +extern bool Vwarn_resize_on_range_error; // Indentation level for structures. extern int struct_indent; diff --git a/test/octave.test/prefer/prefer-17.m b/test/octave.test/prefer/prefer-17.m --- a/test/octave.test/prefer/prefer-17.m +++ b/test/octave.test/prefer/prefer-17.m @@ -1,2 +1,2 @@ -resize_on_range_error = 1; +warn_resize_on_range_error = 0; clear a; a(2) = 1; a(3) = 2; all (a == [0,1,2])