Mercurial > hg > octave-nkf
changeset 18129:e473c4853afc gui-release
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.
line wrap: on
line diff
--- a/NEWS +++ b/NEWS @@ -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 ---------------------------------------------------------
--- a/libinterp/corefcn/error.cc +++ b/libinterp/corefcn/error.cc @@ -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, ,
--- a/libinterp/corefcn/utils.cc +++ b/libinterp/corefcn/utils.cc @@ -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)
--- a/libinterp/octave-value/ov-base-diag.cc +++ b/libinterp/octave-value/ov-base-diag.cc @@ -412,9 +412,9 @@ template <class DMT, class MT> idx_vector -octave_base_diag<DMT, MT>::index_vector (void) const +octave_base_diag<DMT, MT>::index_vector (bool require_integers) const { - return to_dense ().index_vector (); + return to_dense ().index_vector (require_integers); } template <class DMT, class MT>
--- a/libinterp/octave-value/ov-base-diag.h +++ b/libinterp/octave-value/ov-base-diag.h @@ -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;
--- a/libinterp/octave-value/ov-base.cc +++ b/libinterp/octave-value/ov-base.cc @@ -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 ());
--- a/libinterp/octave-value/ov-base.h +++ b/libinterp/octave-value/ov-base.h @@ -287,7 +287,7 @@ const std::list<octave_value_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 (); }
--- a/libinterp/octave-value/ov-bool-mat.h +++ b/libinterp/octave-value/ov-bool-mat.h @@ -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; }
--- a/libinterp/octave-value/ov-bool-sparse.h +++ b/libinterp/octave-value/ov-bool-sparse.h @@ -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; }
--- a/libinterp/octave-value/ov-bool.h +++ b/libinterp/octave-value/ov-bool.h @@ -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; }
--- a/libinterp/octave-value/ov-ch-mat.cc +++ b/libinterp/octave-value/ov-ch-mat.cc @@ -42,7 +42,7 @@ template class octave_base_matrix<charNDArray>; 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 == ':')
--- a/libinterp/octave-value/ov-ch-mat.h +++ b/libinterp/octave-value/ov-ch-mat.h @@ -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; }
--- a/libinterp/octave-value/ov-class.cc +++ b/libinterp/octave-value/ov-class.cc @@ -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
--- a/libinterp/octave-value/ov-class.h +++ b/libinterp/octave-value/ov-class.h @@ -115,7 +115,7 @@ const std::list<octave_value_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 (); }
--- a/libinterp/octave-value/ov-colon.h +++ b/libinterp/octave-value/ov-colon.h @@ -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; }
--- a/libinterp/octave-value/ov-complex.h +++ b/libinterp/octave-value/ov-complex.h @@ -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?)");
--- a/libinterp/octave-value/ov-float.h +++ b/libinterp/octave-value/ov-float.h @@ -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)); }
--- a/libinterp/octave-value/ov-flt-re-mat.h +++ b/libinterp/octave-value/ov-flt-re-mat.h @@ -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; }
--- a/libinterp/octave-value/ov-intx.h +++ b/libinterp/octave-value/ov-intx.h @@ -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,
--- a/libinterp/octave-value/ov-lazy-idx.h +++ b/libinterp/octave-value/ov-lazy-idx.h @@ -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; }
--- a/libinterp/octave-value/ov-perm.cc +++ b/libinterp/octave-value/ov-perm.cc @@ -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
--- a/libinterp/octave-value/ov-perm.h +++ b/libinterp/octave-value/ov-perm.h @@ -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; }
--- a/libinterp/octave-value/ov-range.cc +++ b/libinterp/octave-value/ov-range.cc @@ -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); }
--- a/libinterp/octave-value/ov-range.h +++ b/libinterp/octave-value/ov-range.h @@ -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
--- a/libinterp/octave-value/ov-re-mat.h +++ b/libinterp/octave-value/ov-re-mat.h @@ -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; }
--- a/libinterp/octave-value/ov-re-sparse.cc +++ b/libinterp/octave-value/ov-re-sparse.cc @@ -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 ());
--- a/libinterp/octave-value/ov-re-sparse.h +++ b/libinterp/octave-value/ov-re-sparse.h @@ -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; }
--- a/libinterp/octave-value/ov-scalar.h +++ b/libinterp/octave-value/ov-scalar.h @@ -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)); }
--- a/libinterp/octave-value/ov.h +++ b/libinterp/octave-value/ov.h @@ -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.
--- a/libinterp/octave.cc +++ b/libinterp/octave.cc @@ -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