Mercurial > octave
changeset 29688:b36e83cdbf05
ensure idx_vector(int) constructor is defined (bug #60531)
* idx-vector.h (idx_vector constructor): Define constructor that
accepts int value if not already defined because octave_idx_type is
int. Only define specifically for octave_f77_int_type if size is
different from both octave_idx_type and int. Eliminate all casts from
int to octave_idx_type that were used to avoid overload resolution
errors if no int constructor was defined.
* configure.ac: Check for sizeof int and also define OCTAVE_SIZEOF_INT.
* mk-octave-config-h.sh: Copy OCTAVE_SIZEOF_INT to octave-config.h file.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 17 May 2021 15:26:37 -0400 |
parents | 03d840d96b3a |
children | 26ad902a6749 |
files | build-aux/mk-octave-config-h.sh configure.ac libinterp/corefcn/debug.cc libinterp/corefcn/fft.cc libinterp/parse-tree/bp-table.cc liboctave/array/Sparse.cc liboctave/array/boolSparse.cc liboctave/array/idx-vector.h |
diffstat | 8 files changed, 21 insertions(+), 14 deletions(-) [+] |
line wrap: on
line diff
--- a/build-aux/mk-octave-config-h.sh Mon May 17 08:01:46 2021 +0200 +++ b/build-aux/mk-octave-config-h.sh Mon May 17 15:26:37 2021 -0400 @@ -283,6 +283,7 @@ $SED -n 's/#\(\(undef\|define\) OCTAVE_HAVE_OVERLOAD_CHAR_INT8_TYPES.*$\)/# \1/p' $config_h_file $SED -n 's/#\(\(undef\|define\) OCTAVE_SIZEOF_F77_INT_TYPE.*$\)/# \1/p' $config_h_file $SED -n 's/#\(\(undef\|define\) OCTAVE_SIZEOF_IDX_TYPE.*$\)/# \1/p' $config_h_file +$SED -n 's/#\(\(undef\|define\) OCTAVE_SIZEOF_INT.*$\)/# \1/p' $config_h_file cat << EOF
--- a/configure.ac Mon May 17 08:01:46 2021 +0200 +++ b/configure.ac Mon May 17 15:26:37 2021 -0400 @@ -491,6 +491,10 @@ ### Use a 64-bit integer type for array dimensions and indexing, if possible. +AC_CHECK_SIZEOF([int]) +AC_DEFINE_UNQUOTED(OCTAVE_SIZEOF_INT, [$ac_cv_sizeof_int], + [Define to the size of int.]) + AC_CHECK_SIZEOF([void *]) if test $ac_cv_sizeof_void_p -ge 8; then ENABLE_64=yes
--- a/libinterp/corefcn/debug.cc Mon May 17 08:01:46 2021 +0200 +++ b/libinterp/corefcn/debug.cc Mon May 17 15:26:37 2021 -0400 @@ -915,7 +915,7 @@ octave_idx_type num_skip = std::min (nskip, stk.numel ()); - idx_vector first = idx_vector (static_cast<octave_idx_type> (0)); + idx_vector first = idx_vector (0); for (octave_idx_type i = 0; i < num_skip; i++) stk.delete_elements (first);
--- a/libinterp/corefcn/fft.cc Mon May 17 08:01:46 2021 +0200 +++ b/libinterp/corefcn/fft.cc Mon May 17 15:26:37 2021 -0400 @@ -111,7 +111,7 @@ octave_value_list idx (ndims); for (octave_idx_type i = 0; i < ndims; i++) idx(i) = octave::idx_vector::colon; - idx(dim) = octave::idx_vector (static_cast<octave_idx_type> (0)); + idx(dim) = octave::idx_vector (0); return arg.index_op (idx); }
--- a/libinterp/parse-tree/bp-table.cc Mon May 17 08:01:46 2021 +0200 +++ b/libinterp/parse-tree/bp-table.cc Mon May 17 15:26:37 2021 -0400 @@ -147,7 +147,7 @@ fail = (U.numel () > 1); else { - Array<octave_value> W = U.index (static_cast<octave_idx_type> (0)); + Array<octave_value> W = U.index (0); if (W.isempty () || W(0).isempty ()) es.debug_on_error (true); // like "dbstop if error" with no identifier else if (! W(0).iscell ()) @@ -174,7 +174,7 @@ fail = (U.numel () > 1); else { - Array<octave_value> W = U.index (static_cast<octave_idx_type> (0)); + Array<octave_value> W = U.index (0); if (W.isempty () || W(0).isempty ()) es.debug_on_caught (true); // like "dbstop if caught error" with no ID else if (! W(0).iscell ()) @@ -201,7 +201,7 @@ fail = (U.numel () > 1); else { - Array<octave_value> W = U.index (static_cast<octave_idx_type> (0)); + Array<octave_value> W = U.index (0); if (W.isempty () || W(0).isempty ()) es.debug_on_warning (true); // like "dbstop if warning" with no identifier else if (! W(0).iscell ())
--- a/liboctave/array/Sparse.cc Mon May 17 08:01:46 2021 +0200 +++ b/liboctave/array/Sparse.cc Mon May 17 15:26:37 2021 -0400 @@ -1994,9 +1994,7 @@ idx.copy_data (new_ri.fortran_vec () + nz); new_data.assign (octave::idx_vector (nz, new_nz), rhs.array_value ()); // ... reassembly. - *this = Sparse<T> (new_data, new_ri, - static_cast<octave_idx_type> (0), - nr, nc, false); + *this = Sparse<T> (new_data, new_ri, 0, nr, nc, false); } } else
--- a/liboctave/array/boolSparse.cc Mon May 17 08:01:46 2021 +0200 +++ b/liboctave/array/boolSparse.cc Mon May 17 15:26:37 2021 -0400 @@ -181,8 +181,7 @@ std::copy_n (ridx (), nz, tmp.fortran_vec ()); retval = Sparse<bool> (Array<bool> (dim_vector (1, 1), true), octave::idx_vector (tmp), - octave::idx_vector (static_cast<octave_idx_type> (0)), - nr, 1, false); + octave::idx_vector (0), nr, 1, false); } } @@ -232,8 +231,7 @@ std::copy_n (ridx (), nz, tmp.fortran_vec ()); retval = Sparse<double> (Array<double> (dim_vector (1, 1), 1.0), octave::idx_vector (tmp), - octave::idx_vector (static_cast<octave_idx_type> (0)), - nr, 1); + octave::idx_vector (0), nr, 1); } }
--- a/liboctave/array/idx-vector.h Mon May 17 08:01:46 2021 +0200 +++ b/liboctave/array/idx-vector.h Mon May 17 15:26:37 2021 -0400 @@ -452,9 +452,15 @@ // Zero-based constructors (for use from C++). idx_vector (octave_idx_type i) : m_rep (new idx_scalar_rep (i)) { } -#if OCTAVE_SIZEOF_F77_INT_TYPE != OCTAVE_SIZEOF_IDX_TYPE +#if SIZEOF_INT != OCTAVE_SIZEOF_IDX_TYPE + idx_vector (int i) + : m_rep (new idx_scalar_rep (static_cast<octave_idx_type> (i))) { } +#endif + +#if (OCTAVE_SIZEOF_F77_INT_TYPE != OCTAVE_SIZEOF_IDX_TYPE \ + && OCTAVE_SIZEOF_F77_INT_TYPE != OCTAVE_SIZEOF_INT) idx_vector (octave_f77_int_type i) - : m_rep (new idx_scalar_rep (static_cast<octave_idx_type> (i))) { } + : m_rep (new idx_scalar_rep (static_cast<octave_idx_type> (i))) { } #endif idx_vector (octave_idx_type start, octave_idx_type limit,