Mercurial > octave
changeset 23487:af2f1f3dbe06
eliminate --enable-bounds-check configure option
* configure.ac (--enable-bounds-check): Warn that the option is
obsolete. Don't define ENABLE_BOUNDS_CHECK.
* install.txi: Document --enable-address-sanitizer-flags. Delete
documentation for --enable-bounds-check.
* toplev.cc (conf_info_struct): Don't include ENABLE_BOUNDS_CHECK in
the struct.
* oct-map.cc, oct-map.h, Array.cc, Array.h, DiagArray2.h,
PermMatrix.h, Range.cc, Range.h, Sparse.h, dim-vector.h, idx-vector.h:
Eliminate conditional code for bounds checking in operator ().
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 11 May 2017 17:50:49 -0400 |
parents | fec7e5b14fb2 |
children | 52a74f14345c |
files | configure.ac doc/interpreter/install.txi libinterp/corefcn/oct-map.cc libinterp/corefcn/oct-map.h libinterp/corefcn/toplev.cc liboctave/array/Array.cc liboctave/array/Array.h liboctave/array/DiagArray2.h liboctave/array/PermMatrix.h liboctave/array/Range.cc liboctave/array/Range.h liboctave/array/Sparse.h liboctave/array/dim-vector.h liboctave/array/idx-vector.h |
diffstat | 14 files changed, 55 insertions(+), 132 deletions(-) [+] |
line wrap: on
line diff
--- a/configure.ac Thu May 11 12:03:16 2017 -0700 +++ b/configure.ac Thu May 11 17:50:49 2017 -0400 @@ -299,10 +299,11 @@ ENABLE_BOUNDS_CHECK=no AC_ARG_ENABLE([bounds-check], [AS_HELP_STRING([--enable-bounds-check], - [enable bounds checking for indexing in internal array classes])], + [OBSOLETE: use --enable-address-sanitizer-flags instead])], [if test "$enableval" = yes; then ENABLE_BOUNDS_CHECK=yes; fi], []) if test $ENABLE_BOUNDS_CHECK = yes; then - AC_DEFINE(OCTAVE_ENABLE_BOUNDS_CHECK, 1, [Define to 1 to use internal bounds checking.]) + warn_bounds_check="--enable-bounds-check is obsolete; use --enable-address-sanitizer-flags instead" + OCTAVE_CONFIGURE_WARNING([warn_bounds_check]) fi ### Use atomic operations for internal reference counting. This is required @@ -3360,7 +3361,6 @@ Build Octave Qt GUI: $build_qt_gui JIT compiler for loops: $ENABLE_JIT Build Java interface: $build_java - Do internal array bounds checking: $ENABLE_BOUNDS_CHECK Build static libraries: $STATIC_LIBS Build shared libraries: $SHARED_LIBS Dynamic Linking: $ENABLE_DYNAMIC_LINKING $DL_API_MSG
--- a/doc/interpreter/install.txi Thu May 11 12:03:16 2017 -0700 +++ b/doc/interpreter/install.txi Thu May 11 17:50:49 2017 -0400 @@ -384,11 +384,12 @@ @xref{Compiling Octave with 64-bit Indexing}, for more details about building Octave with more complete support for large arrays. -@item --enable-bounds-check -Enable bounds checking for indexing operators in the internal array -classes. This option is primarily used for debugging Octave. Building -Octave with this option has a negative impact on performance and is not -recommended for general use. +@item --enable-address-sanitizer-flags +Enable compiler options @code{-fsanitize=address} and +@code{-fomit-frame-pointer} for memory access checking. This option is +primarily used for debugging Octave. Building Octave with this option +has a negative impact on performance and is not recommended for general +use. It may also interfere with proper functioning of the GUI. @item --disable-docs Disable building all forms of the documentation (Info, PDF, HTML). The
--- a/libinterp/corefcn/oct-map.cc Thu May 11 12:03:16 2017 -0700 +++ b/libinterp/corefcn/oct-map.cc Thu May 11 17:50:49 2017 -0400 @@ -355,7 +355,7 @@ } octave_scalar_map -octave_map::checkelem (octave_idx_type n) const +octave_map::elem (octave_idx_type n) const { octave_scalar_map retval (xkeys); @@ -366,7 +366,7 @@ } octave_scalar_map -octave_map::checkelem (octave_idx_type i, octave_idx_type j) const +octave_map::elem (octave_idx_type i, octave_idx_type j) const { octave_scalar_map retval (xkeys); @@ -377,7 +377,7 @@ } octave_scalar_map -octave_map::checkelem (const Array<octave_idx_type>& ra_idx) const +octave_map::elem (const Array<octave_idx_type>& ra_idx) const { octave_scalar_map retval (xkeys);
--- a/libinterp/corefcn/oct-map.h Thu May 11 12:03:16 2017 -0700 +++ b/libinterp/corefcn/oct-map.h Thu May 11 17:50:49 2017 -0400 @@ -377,20 +377,33 @@ octave_idx_type columns (void) const { return dimensions(1); } // Extract a scalar substructure. - octave_scalar_map checkelem (octave_idx_type n) const; - octave_scalar_map checkelem (octave_idx_type i, octave_idx_type j) const; + // FIXME: actually check something. + octave_scalar_map checkelem (octave_idx_type n) const + { return elem (n); } + + // FIXME: actually check something. + octave_scalar_map checkelem (octave_idx_type i, octave_idx_type j) const + { return elem (i, j); } - octave_scalar_map - checkelem (const Array<octave_idx_type>& ra_idx) const; + // FIXME: actually check something. + octave_scalar_map checkelem (const Array<octave_idx_type>& ra_idx) const + { return elem (ra_idx); } + + octave_scalar_map elem (octave_idx_type n) const; + + octave_scalar_map elem (octave_idx_type i, octave_idx_type j) const; + + octave_scalar_map elem (const Array<octave_idx_type>& ra_idx) const; octave_scalar_map operator () (octave_idx_type n) const - { return checkelem (n); } + { return elem (n); } + octave_scalar_map operator () (octave_idx_type i, octave_idx_type j) const - { return checkelem (i, j); } + { return elem (i, j); } octave_scalar_map operator () (const Array<octave_idx_type>& ra_idx) const - { return checkelem (ra_idx); } + { return elem (ra_idx); } octave_map squeeze (void) const;
--- a/libinterp/corefcn/toplev.cc Thu May 11 12:03:16 2017 -0700 +++ b/libinterp/corefcn/toplev.cc Thu May 11 17:50:49 2017 -0400 @@ -337,12 +337,6 @@ { "ENABLE_ATOMIC_REFCOUNT", false }, #endif -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - { "ENABLE_BOUNDS_CHECK", true }, -#else - { "ENABLE_BOUNDS_CHECK", false }, -#endif - #if defined (ENABLE_DOCS) { "ENABLE_DOCS", true }, #else
--- a/liboctave/array/Array.cc Thu May 11 12:03:16 2017 -0700 +++ b/liboctave/array/Array.cc Thu May 11 17:50:49 2017 -0400 @@ -260,10 +260,6 @@ Array<T>::column (octave_idx_type k) const { octave_idx_type r = dimensions(0); -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - if (k < 0 || k > dimensions.numel (1)) - octave::err_index_out_of_range (2, 2, k+1, dimensions.numel (1), dimensions); -#endif return Array<T> (*this, dim_vector (r, 1), k*r, k*r + r); } @@ -275,10 +271,6 @@ octave_idx_type r = dimensions(0); octave_idx_type c = dimensions(1); octave_idx_type p = r*c; -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - if (k < 0 || k > dimensions.numel (2)) - octave::err_index_out_of_range (3, 3, k+1, dimensions.numel (2), dimensions); -#endif return Array<T> (*this, dim_vector (r, c), k*p, k*p + p); } @@ -287,13 +279,9 @@ Array<T> Array<T>::linear_slice (octave_idx_type lo, octave_idx_type up) const { -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - if (lo < 0) - octave::err_index_out_of_range (1, 1, lo+1, numel (), dimensions); - if (up > numel ()) - octave::err_index_out_of_range (1, 1, up, numel (), dimensions); -#endif - if (up < lo) up = lo; + if (up < lo) + up = lo; + return Array<T> (*this, dim_vector (up - lo, 1), lo, up); }
--- a/liboctave/array/Array.h Thu May 11 12:03:16 2017 -0700 +++ b/liboctave/array/Array.h Thu May 11 17:50:49 2017 -0400 @@ -478,8 +478,11 @@ // a copy, but that is not so easy, and I see no clean way to do it. T& checkelem (octave_idx_type n); + T& checkelem (octave_idx_type i, octave_idx_type j); + T& checkelem (octave_idx_type i, octave_idx_type j, octave_idx_type k); + T& checkelem (const Array<octave_idx_type>& ra_idx); T& elem (octave_idx_type n) @@ -496,27 +499,20 @@ T& elem (const Array<octave_idx_type>& ra_idx) { return Array<T>::elem (compute_index_unchecked (ra_idx)); } -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - T& operator () (octave_idx_type n) { return checkelem (n); } - T& operator () (octave_idx_type i, octave_idx_type j) - { return checkelem (i, j); } - T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) - { return checkelem (i, j, k); } - T& operator () (const Array<octave_idx_type>& ra_idx) - { return checkelem (ra_idx); } -#else T& operator () (octave_idx_type n) { return elem (n); } T& operator () (octave_idx_type i, octave_idx_type j) { return elem (i, j); } T& operator () (octave_idx_type i, octave_idx_type j, octave_idx_type k) { return elem (i, j, k); } T& operator () (const Array<octave_idx_type>& ra_idx) { return elem (ra_idx); } -#endif crefT checkelem (octave_idx_type n) const; + crefT checkelem (octave_idx_type i, octave_idx_type j) const; + crefT checkelem (octave_idx_type i, octave_idx_type j, octave_idx_type k) const; + crefT checkelem (const Array<octave_idx_type>& ra_idx) const; crefT elem (octave_idx_type n) const { return xelem (n); } @@ -530,16 +526,6 @@ crefT elem (const Array<octave_idx_type>& ra_idx) const { return Array<T>::xelem (compute_index_unchecked (ra_idx)); } -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - crefT operator () (octave_idx_type n) const { return checkelem (n); } - crefT operator () (octave_idx_type i, octave_idx_type j) const - { return checkelem (i, j); } - crefT operator () (octave_idx_type i, octave_idx_type j, - octave_idx_type k) const - { return checkelem (i, j, k); } - crefT operator () (const Array<octave_idx_type>& ra_idx) const - { return checkelem (ra_idx); } -#else crefT operator () (octave_idx_type n) const { return elem (n); } crefT operator () (octave_idx_type i, octave_idx_type j) const { return elem (i, j); } @@ -548,11 +534,8 @@ { return elem (i, j, k); } crefT operator () (const Array<octave_idx_type>& ra_idx) const { return elem (ra_idx); } -#endif // Fast extractors. All of these produce shallow copies. - // Warning: none of these do check bounds, unless - // OCTAVE_ENABLE_BOUNDS_CHECK is defined! //! Extract column: A(:,k+1). Array<T> column (octave_idx_type k) const;
--- a/liboctave/array/DiagArray2.h Thu May 11 12:03:16 2017 -0700 +++ b/liboctave/array/DiagArray2.h Thu May 11 17:50:49 2017 -0400 @@ -124,28 +124,18 @@ { return Array<T>::elem (i); } T checkelem (octave_idx_type r, octave_idx_type c) const - { - return check_idx (r, c) ? elem (r, c) : T (0); - } + { return check_idx (r, c) ? elem (r, c) : T (0); } T operator () (octave_idx_type r, octave_idx_type c) const { -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - return checkelem (r, c); -#else return elem (r, c); -#endif } T& checkelem (octave_idx_type r, octave_idx_type c); T& operator () (octave_idx_type r, octave_idx_type c) { -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - return checkelem (r, c); -#else return elem (r, c); -#endif } // No checking.
--- a/liboctave/array/PermMatrix.h Thu May 11 12:03:16 2017 -0700 +++ b/liboctave/array/PermMatrix.h Thu May 11 17:50:49 2017 -0400 @@ -91,11 +91,7 @@ octave_idx_type operator () (octave_idx_type i, octave_idx_type j) const { -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - return checkelem (i, j); -#else return elem (i, j); -#endif } // These are, in fact, super-fast.
--- a/liboctave/array/Range.cc Thu May 11 12:03:16 2017 -0700 +++ b/liboctave/array/Range.cc Thu May 11 17:50:49 2017 -0400 @@ -87,16 +87,12 @@ double Range::elem (octave_idx_type i) const { -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - return checkelem (i); -#else if (i == 0) return rng_base; else if (i < rng_numel - 1) return rng_base + i * rng_inc; else return rng_limit; -#endif } // Helper class used solely for idx_vector.loop () function call
--- a/liboctave/array/Range.h Thu May 11 12:03:16 2017 -0700 +++ b/liboctave/array/Range.h Thu May 11 17:50:49 2017 -0400 @@ -111,6 +111,8 @@ double elem (octave_idx_type i) const; + double operator () (octave_idx_type i) const { return elem (i); } + Array<double> index (const idx_vector& i) const; void set_base (double b);
--- a/liboctave/array/Sparse.h Thu May 11 12:03:16 2017 -0700 +++ b/liboctave/array/Sparse.h Thu May 11 17:50:49 2017 -0400 @@ -373,23 +373,6 @@ T& elem (const Array<octave_idx_type>& ra_idx) { return Sparse<T>::elem (compute_index (ra_idx)); } -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - T& operator () (octave_idx_type n) - { - return checkelem (n); - } - - T& operator () (octave_idx_type i, octave_idx_type j) - { - return checkelem (i, j); - } - - T& operator () (const Array<octave_idx_type>& ra_idx) - { - return checkelem (ra_idx); - } - -#else T& operator () (octave_idx_type n) { return elem (n); @@ -405,8 +388,6 @@ return elem (ra_idx); } -#endif - T checkelem (octave_idx_type n) const { if (n < 0 || n >= numel ()) @@ -440,20 +421,8 @@ T elem (const Array<octave_idx_type>& ra_idx) const { return Sparse<T>::elem (compute_index (ra_idx)); } -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - T operator () (octave_idx_type n) const { return checkelem (n); } - T operator () (octave_idx_type i, octave_idx_type j) const - { - return checkelem (i, j); - } + T operator () (octave_idx_type n) const { return elem (n); } - T operator () (const Array<octave_idx_type>& ra_idx) const - { - return checkelem (ra_idx); - } - -#else - T operator () (octave_idx_type n) const { return elem (n); } T operator () (octave_idx_type i, octave_idx_type j) const { return elem (i, j); @@ -463,7 +432,6 @@ { return elem (ra_idx); } -#endif Sparse<T> maybe_compress (bool remove_zeros = false) {
--- a/liboctave/array/dim-vector.h Thu May 11 12:03:16 2017 -0700 +++ b/liboctave/array/dim-vector.h Thu May 11 17:50:49 2017 -0400 @@ -217,20 +217,11 @@ octave_idx_type& elem (int i) { -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - assert (i >= 0 && i < ndims ()); -#endif make_unique (); return xelem (i); } - octave_idx_type elem (int i) const - { -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - assert (i >= 0 && i < ndims ()); -#endif - return xelem (i); - } + octave_idx_type elem (int i) const { return xelem (i); } void chop_trailing_singletons (void) {
--- a/liboctave/array/idx-vector.h Thu May 11 12:03:16 2017 -0700 +++ b/liboctave/array/idx-vector.h Thu May 11 17:50:49 2017 -0400 @@ -87,6 +87,7 @@ virtual octave_idx_type xelem (octave_idx_type i) const = 0; // Range-checking element query. + OCTAVE_DEPRECATED ("use 'elem' instead") virtual octave_idx_type checkelem (octave_idx_type i) const = 0; // Length of the index vector. @@ -136,6 +137,7 @@ octave_idx_type xelem (octave_idx_type i) const { return i; } + OCTAVE_DEPRECATED ("use 'elem' instead") octave_idx_type checkelem (octave_idx_type i) const; octave_idx_type length (octave_idx_type n) const { return n; } @@ -183,6 +185,7 @@ octave_idx_type xelem (octave_idx_type i) const { return start + i * step; } + OCTAVE_DEPRECATED ("use 'elem' instead") octave_idx_type checkelem (octave_idx_type i) const; octave_idx_type length (octave_idx_type) const { return len; } @@ -244,6 +247,7 @@ octave_idx_type xelem (octave_idx_type) const { return data; } + OCTAVE_DEPRECATED ("use 'elem' instead") octave_idx_type checkelem (octave_idx_type i) const; octave_idx_type length (octave_idx_type) const { return 1; } @@ -317,6 +321,7 @@ octave_idx_type xelem (octave_idx_type i) const { return data[i]; } + OCTAVE_DEPRECATED ("use 'elem' instead") octave_idx_type checkelem (octave_idx_type i) const; octave_idx_type length (octave_idx_type) const { return len; } @@ -386,6 +391,7 @@ octave_idx_type xelem (octave_idx_type i) const; + OCTAVE_DEPRECATED ("use 'elem' instead") octave_idx_type checkelem (octave_idx_type i) const; octave_idx_type length (octave_idx_type) const { return len; } @@ -563,17 +569,12 @@ octave_idx_type xelem (octave_idx_type n) const { return rep->xelem (n); } + OCTAVE_DEPRECATED ("use 'elem' instead") octave_idx_type checkelem (octave_idx_type n) const - { return rep->checkelem (n); } + { return rep->xelem (n); } octave_idx_type operator () (octave_idx_type n) const - { -#if defined (OCTAVE_ENABLE_BOUNDS_CHECK) - return rep->checkelem (n); -#else - return rep->xelem (n); -#endif - } + { return rep->xelem (n); } operator bool (void) const { return ! rep->err; }