# HG changeset patch # User John W. Eaton # Date 1386822934 18000 # Node ID e473c4853afc1731fe49edf009e2f511ba6a229e # Parent 4a4897cd6da1d22a63ce3e50be11015abbbe5f69 enable non-integer ranges as indices by default and deprecate preference * octave.cc (maximum_braindamage): Don't call Fdo_brainded_shortcircuit_evaluation. * error.cc (initialize_default_warning_state): Don't set Octave:noninteger-range-as-index to "error". * octave.cc (maximum_braindamage): Don't call Fallow_noninteger_range_as_index. Don't set Octave:noninteger-range-as-index to "on". * ov-range.h, ov-range.cc (Vallow_noninteger_range_as_index): Now static. Set default value to true. * ov.h (octave_value::index_vector): New arg, require_integers. * ov-base.cc, ov-base.h (octave_value::index_vector): Likewise. * ov-base-diag.cc, ov-base-diag.h, ov-bool-mat.h, ov-bool-sparse.h, ov-bool.h, ov-ch-mat.cc, ov-ch-mat.h, ov-class.cc, ov-class.h, ov-colon.h, ov-complex.h, ov-float.h, ov-flt-re-mat.h, ov-intx.h, ov-lazy-idx.h, ov-perm.cc, ov-perm.h, ov-range.cc, ov-range.h, ov-re-mat.h, ov-re-sparse.cc, ov-re-sparse.h, ov-scalar.h: Make corresponding changes in all derived methods. * ov-range.cc (octave_range::index_vector): If new require_integers argument is true, also require integer arguments regardless of the setting of Vallow_noninteger_range_as_index. * utils.cc (Fisindex): Don't temporarily set Vallow_noninteger_range_as_index. Call index_vector with argument of true. * NEWS: Mention change in default value, warning state and deprecated function. diff -r 4a4897cd6da1 -r e473c4853afc NEWS --- a/NEWS Wed Dec 11 22:22:28 2013 -0500 +++ b/NEWS Wed Dec 11 23:35:34 2013 -0500 @@ -10,6 +10,17 @@ is now enabled by default. + ** The preference + + allow_noninteger_range_as_index + + is now enabled by default and the warning ID + + Octave:noninteger-range-as-index + + is now set to "on" by default instead of "error" by default and "on" + for --traditional. + ** Other new functions added in 4.0.0: validateattributes @@ -29,6 +40,7 @@ be removed from Octave 4.4 (or whatever version is the second major release after 4.0): + allow_noninteger_range_as_index do_braindead_shortcircuit_evaluation --------------------------------------------------------- diff -r 4a4897cd6da1 -r e473c4853afc libinterp/corefcn/error.cc --- a/libinterp/corefcn/error.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/corefcn/error.cc Wed Dec 11 23:35:34 2013 -0500 @@ -1642,9 +1642,6 @@ disable_warning ("Octave:str-to-num"); disable_warning ("Octave:mixed-string-concat"); disable_warning ("Octave:variable-switch-label"); - - // This should be an error unless we are in maximum braindamage mode. - set_warning_state ("Octave:noninteger-range-as-index", "error"); } DEFUN (lasterror, args, , diff -r 4a4897cd6da1 -r e473c4853afc libinterp/corefcn/utils.cc --- a/libinterp/corefcn/utils.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/corefcn/utils.cc Wed Dec 11 23:35:34 2013 -0500 @@ -1306,9 +1306,6 @@ { unwind_protect frame; - frame.protect_var (Vallow_noninteger_range_as_index); - Vallow_noninteger_range_as_index = false; - frame.protect_var (error_state); frame.protect_var (discard_error_messages); @@ -1316,7 +1313,8 @@ try { - idx_vector idx = args(0).index_vector (); + idx_vector idx = args(0).index_vector (true); + if (! error_state) { if (nargin == 2) diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-base-diag.cc --- a/libinterp/octave-value/ov-base-diag.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-base-diag.cc Wed Dec 11 23:35:34 2013 -0500 @@ -412,9 +412,9 @@ template idx_vector -octave_base_diag::index_vector (void) const +octave_base_diag::index_vector (bool require_integers) const { - return to_dense ().index_vector (); + return to_dense ().index_vector (require_integers); } template diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-base-diag.h --- a/libinterp/octave-value/ov-base-diag.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-base-diag.h Wed Dec 11 23:35:34 2013 -0500 @@ -133,7 +133,7 @@ double scalar_value (bool frc_str_conv = false) const { return double_value (frc_str_conv); } - idx_vector index_vector (void) const; + idx_vector index_vector (bool /* require_integers */ = false) const; Matrix matrix_value (bool = false) const; diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-base.cc --- a/libinterp/octave-value/ov-base.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-base.cc Wed Dec 11 23:35:34 2013 -0500 @@ -214,7 +214,7 @@ } idx_vector -octave_base_value::index_vector (void) const +octave_base_value::index_vector (bool /* require_integers */) const { std::string nm = type_name (); error ("%s type invalid as index value", nm.c_str ()); diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-base.h --- a/libinterp/octave-value/ov-base.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-base.h Wed Dec 11 23:35:34 2013 -0500 @@ -287,7 +287,7 @@ const std::list& idx, const octave_value& rhs); - virtual idx_vector index_vector (void) const; + virtual idx_vector index_vector (bool require_integers = false) const; virtual dim_vector dims (void) const { return dim_vector (); } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-bool-mat.h --- a/libinterp/octave-value/ov-bool-mat.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-bool-mat.h Wed Dec 11 23:35:34 2013 -0500 @@ -88,8 +88,10 @@ octave_base_value *try_narrowing_conversion (void); - idx_vector index_vector (void) const - { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); } + idx_vector index_vector (bool /* require_integers */ = false) const + { + return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); + } builtin_type_t builtin_type (void) const { return btyp_bool; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-bool-sparse.h --- a/libinterp/octave-value/ov-bool-sparse.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-bool-sparse.h Wed Dec 11 23:35:34 2013 -0500 @@ -86,8 +86,10 @@ octave_base_value *try_narrowing_conversion (void); // FIXME Adapt idx_vector to allow sparse logical indexing without overflow!! - idx_vector index_vector (void) const - { return idx_vector (matrix); } + idx_vector index_vector (bool /* require_integers */ = false) const + { + return idx_vector (matrix); + } builtin_type_t builtin_type (void) const { return btyp_bool; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-bool.h --- a/libinterp/octave-value/ov-bool.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-bool.h Wed Dec 11 23:35:34 2013 -0500 @@ -72,7 +72,7 @@ octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); - idx_vector index_vector (void) const { return idx_vector (scalar); } + idx_vector index_vector (bool /* require_integers */ = false) const { return idx_vector (scalar); } builtin_type_t builtin_type (void) const { return btyp_bool; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-ch-mat.cc --- a/libinterp/octave-value/ov-ch-mat.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-ch-mat.cc Wed Dec 11 23:35:34 2013 -0500 @@ -42,7 +42,7 @@ template class octave_base_matrix; idx_vector -octave_char_matrix::index_vector (void) const +octave_char_matrix::index_vector (bool /* require_integers */) const { const char *p = matrix.data (); if (numel () == 1 && *p == ':') diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-ch-mat.h --- a/libinterp/octave-value/ov-ch-mat.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-ch-mat.h Wed Dec 11 23:35:34 2013 -0500 @@ -87,7 +87,7 @@ octave_base_value *empty_clone (void) const { return new octave_char_matrix (); } - idx_vector index_vector (void) const; + idx_vector index_vector (bool require_integers = false) const; builtin_type_t builtin_type (void) const { return btyp_char; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-class.cc --- a/libinterp/octave-value/ov-class.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-class.cc Wed Dec 11 23:35:34 2013 -0500 @@ -991,7 +991,7 @@ } idx_vector -octave_class::index_vector (void) const +octave_class::index_vector (bool require_integers) const { idx_vector retval; @@ -1014,7 +1014,7 @@ // add one to the value returned as the index_vector method // expects it to be one based. retval = do_binary_op (octave_value::op_add, tmp (0), - octave_value (1.0)).index_vector (); + octave_value (1.0)).index_vector (require_integers); } } else diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-class.h --- a/libinterp/octave-value/ov-class.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-class.h Wed Dec 11 23:35:34 2013 -0500 @@ -115,7 +115,7 @@ const std::list& idx, const octave_value& rhs); - idx_vector index_vector (void) const; + idx_vector index_vector (bool require_integers = false) const; dim_vector dims (void) const { return map.dims (); } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-colon.h --- a/libinterp/octave-value/ov-colon.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-colon.h Wed Dec 11 23:35:34 2013 -0500 @@ -59,7 +59,7 @@ octave_base_value *empty_clone (void) const { return new octave_magic_colon (); } - idx_vector index_vector (void) const { return idx_vector (':'); } + idx_vector index_vector (bool /* require_integers */ = false) const { return idx_vector (':'); } bool is_defined (void) const { return true; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-complex.h --- a/libinterp/octave-value/ov-complex.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-complex.h Wed Dec 11 23:35:34 2013 -0500 @@ -80,7 +80,7 @@ bool resize_ok = false); // Use this to give a more specific error message - idx_vector index_vector (void) const + idx_vector index_vector (bool /* require_integers */ = false) const { error ("attempted to use a complex scalar as an index\n" " (forgot to initialize i or j?)"); diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-float.h --- a/libinterp/octave-value/ov-float.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-float.h Wed Dec 11 23:35:34 2013 -0500 @@ -77,7 +77,7 @@ octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); - idx_vector index_vector (void) const { return idx_vector (scalar); } + idx_vector index_vector (bool /* require_integers */ = false) const { return idx_vector (scalar); } octave_value any (int = 0) const { return (scalar != 0 && ! lo_ieee_isnan (scalar)); } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-flt-re-mat.h --- a/libinterp/octave-value/ov-flt-re-mat.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-flt-re-mat.h Wed Dec 11 23:35:34 2013 -0500 @@ -89,8 +89,10 @@ octave_base_value *try_narrowing_conversion (void); - idx_vector index_vector (void) const - { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); } + idx_vector index_vector (bool /* require_integers */ = false) const + { + return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); + } builtin_type_t builtin_type (void) const { return btyp_float; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-intx.h --- a/libinterp/octave-value/ov-intx.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-intx.h Wed Dec 11 23:35:34 2013 -0500 @@ -303,8 +303,10 @@ matrix_ref ().changesign (); } - idx_vector index_vector (void) const - { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); } + idx_vector index_vector (bool /* require_integers */ = false) const + { + return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); + } int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, int skip, @@ -606,7 +608,7 @@ scalar -= OCTAVE_INT_T (1); } - idx_vector index_vector (void) const { return idx_vector (scalar); } + idx_vector index_vector (bool /* require_integers */ = false) const { return idx_vector (scalar); } int write (octave_stream& os, int block_size, oct_data_conv::data_type output_type, octave_idx_type skip, diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-lazy-idx.h --- a/libinterp/octave-value/ov-lazy-idx.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-lazy-idx.h Wed Dec 11 23:35:34 2013 -0500 @@ -59,8 +59,7 @@ octave_value full_value (void) const { return make_value (); } - idx_vector index_vector (void) const - { return index; } + idx_vector index_vector (bool /* require_integers */ = false) const { return index; } builtin_type_t builtin_type (void) const { return btyp_double; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-perm.cc --- a/libinterp/octave-value/ov-perm.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-perm.cc Wed Dec 11 23:35:34 2013 -0500 @@ -245,9 +245,9 @@ FORWARD_MATRIX_VALUE (charNDArray, char_array) idx_vector -octave_perm_matrix::index_vector (void) const +octave_perm_matrix::index_vector (bool require_integers) const { - return to_dense ().index_vector (); + return to_dense ().index_vector (require_integers); } octave_value diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-perm.h --- a/libinterp/octave-value/ov-perm.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-perm.h Wed Dec 11 23:35:34 2013 -0500 @@ -131,7 +131,7 @@ double scalar_value (bool frc_str_conv = false) const { return double_value (frc_str_conv); } - idx_vector index_vector (void) const; + idx_vector index_vector (bool require_integers = false) const; PermMatrix perm_matrix_value (void) const { return matrix; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-range.cc --- a/libinterp/octave-value/ov-range.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-range.cc Wed Dec 11 23:35:34 2013 -0500 @@ -46,7 +46,7 @@ #include "ls-utils.h" // If TRUE, allow ranges with non-integer elements as array indices. -bool Vallow_noninteger_range_as_index = false; +static bool Vallow_noninteger_range_as_index = true; DEFINE_OCTAVE_ALLOCATOR (octave_range); @@ -148,13 +148,14 @@ } idx_vector -octave_range::index_vector (void) const +octave_range::index_vector (bool require_integers) const { if (idx_cache) return *idx_cache; else { - if (! Vallow_noninteger_range_as_index + if (require_integers + || ! Vallow_noninteger_range_as_index || range.all_elements_are_ints ()) return set_idx_cache (idx_vector (range)); else @@ -690,6 +691,14 @@ The original variable value is restored when exiting the function.\n\ @end deftypefn") { + static bool warned = false; + if (! warned) + { + warned = true; + warning_with_id ("Octave:deprecated-function", + "allow_noninteger_range_as_index is obsolete and will be removed from a future version of Octave"); + } + return SET_INTERNAL_VARIABLE (allow_noninteger_range_as_index); } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-range.h --- a/libinterp/octave-value/ov-range.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-range.h Wed Dec 11 23:35:34 2013 -0500 @@ -104,7 +104,7 @@ octave_value do_index_op (const octave_value_list& idx, bool resize_ok = false); - idx_vector index_vector (void) const; + idx_vector index_vector (bool require_integers = false) const; dim_vector dims (void) const { @@ -317,7 +317,4 @@ DECLARE_OV_TYPEID_FUNCTIONS_AND_DATA }; -// If TRUE, allow ranges with non-integer elements as array indices. -extern bool Vallow_noninteger_range_as_index; - #endif diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-re-mat.h --- a/libinterp/octave-value/ov-re-mat.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-re-mat.h Wed Dec 11 23:35:34 2013 -0500 @@ -104,7 +104,7 @@ octave_base_value *try_narrowing_conversion (void); - idx_vector index_vector (void) const + idx_vector index_vector (bool /* require_integers */ = false) const { return idx_cache ? *idx_cache : set_idx_cache (idx_vector (matrix)); } builtin_type_t builtin_type (void) const { return btyp_double; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-re-sparse.cc --- a/libinterp/octave-value/ov-re-sparse.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-re-sparse.cc Wed Dec 11 23:35:34 2013 -0500 @@ -55,7 +55,7 @@ "double"); idx_vector -octave_sparse_matrix::index_vector (void) const +octave_sparse_matrix::index_vector (bool /* require_integers */) const { if (matrix.numel () == matrix.nnz ()) return idx_vector (array_value ()); diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-re-sparse.h --- a/libinterp/octave-value/ov-re-sparse.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-re-sparse.h Wed Dec 11 23:35:34 2013 -0500 @@ -92,7 +92,7 @@ octave_base_value *try_narrowing_conversion (void); - idx_vector index_vector (void) const; + idx_vector index_vector (bool require_integers = false) const; builtin_type_t builtin_type (void) const { return btyp_double; } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov-scalar.h --- a/libinterp/octave-value/ov-scalar.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov-scalar.h Wed Dec 11 23:35:34 2013 -0500 @@ -76,7 +76,7 @@ type_conv_info numeric_demotion_function (void) const; - idx_vector index_vector (void) const { return idx_vector (scalar); } + idx_vector index_vector (bool /* require_integers */ = false) const { return idx_vector (scalar); } octave_value any (int = 0) const { return (scalar != 0 && ! lo_ieee_isnan (scalar)); } diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave-value/ov.h --- a/libinterp/octave-value/ov.h Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave-value/ov.h Wed Dec 11 23:35:34 2013 -0500 @@ -455,8 +455,10 @@ octave_value& assign (assign_op, const octave_value& rhs); - idx_vector index_vector (void) const - { return rep->index_vector (); } + idx_vector index_vector (bool require_integers = false) const + { + return rep->index_vector (require_integers); + } // Size. diff -r 4a4897cd6da1 -r e473c4853afc libinterp/octave.cc --- a/libinterp/octave.cc Wed Dec 11 22:22:28 2013 -0500 +++ b/libinterp/octave.cc Wed Dec 11 23:35:34 2013 -0500 @@ -482,7 +482,6 @@ FPS1 (octave_value (">> ")); FPS2 (octave_value ("")); FPS4 (octave_value ("")); - Fallow_noninteger_range_as_index (octave_value (true)); Fbeep_on_error (octave_value (true)); Fconfirm_recursive_rmdir (octave_value (false)); Fcrash_dumps_octave_core (octave_value (false)); @@ -497,9 +496,6 @@ disable_warning ("Octave:function-name-clash"); disable_warning ("Octave:load-file-in-path"); disable_warning ("Octave:possible-matlab-short-circuit-operator"); - - // Initialized to "error" by default. - set_warning_state ("Octave:noninteger-range-as-index", "on"); } // EMBEDDED is declared int instead of bool because this function is