Mercurial > hg > octave-lojdl
changeset 8121:061febbf23ad
clear index before throwing error in Array indexed assignment functions
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 19 Sep 2008 11:05:34 -0400 |
parents | 8f0150a0d19e |
children | 99602635172a |
files | liboctave/Array.cc liboctave/ChangeLog |
diffstat | 2 files changed, 54 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/liboctave/Array.cc +++ b/liboctave/Array.cc @@ -2154,8 +2154,12 @@ retval = index (idx[0]); } else - (*current_liboctave_error_handler) - ("Array<T>::value: invalid number of indices specified"); + { + clear_index (); + + (*current_liboctave_error_handler) + ("Array<T>::value: invalid number of indices specified"); + } clear_index (); @@ -2943,6 +2947,8 @@ } else { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(I) = X: X must be a scalar or a vector with same length as I"); @@ -2951,6 +2957,8 @@ } else { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(I) = X: unable to resize A"); @@ -2971,11 +2979,17 @@ lhs.xelem (i) = rhs.elem (i); } else if (rhs_len != lhs_len) - (*current_liboctave_error_handler) - ("A(:) = X: A must be the same size as X"); + { + lhs.clear_index (); + + (*current_liboctave_error_handler) + ("A(:) = X: A must be the same size as X"); + } } else if (! (rhs_len == 1 || rhs_len == 0)) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A([]) = X: X must also be an empty matrix or a scalar"); @@ -3037,6 +3051,7 @@ break; default: + lhs.clear_index (); (*current_liboctave_error_handler) ("Array<T>::assign2: Dimension mismatch"); return 0; @@ -3151,6 +3166,8 @@ { if (! (rhs_is_scalar || (rhs_nr == 0 || rhs_nc == 0))) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A([], []) = X: X must be an empty matrix or a scalar"); @@ -3159,12 +3176,10 @@ } else { - (*current_liboctave_error_handler) - ("A(I, J) = X: X must be a scalar or the number of elements in I must"); + lhs.clear_index (); + (*current_liboctave_error_handler) - ("match the number of rows in X and the number of elements in J must"); - (*current_liboctave_error_handler) - ("match the number of columns in X"); + ("A(I, J) = X: X must be a scalar or the number of elements in I must match the number of rows in X and the number of elements in J must match the number of columns in X"); retval = 0; } @@ -3279,8 +3294,14 @@ else if (len == 0) { if (! (rhs_is_scalar || (rhs_nr == 0 || rhs_nc == 0))) - (*current_liboctave_error_handler) - ("A([]) = X: X must be an empty matrix or scalar"); + { + lhs.clear_index (); + + (*current_liboctave_error_handler) + ("A([]) = X: X must be an empty matrix or scalar"); + + retval = 0; + } } else if (len == rhs_nr * rhs_nc) { @@ -3322,6 +3343,8 @@ } else { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(I) = X: X must be a scalar or a matrix with the same size as I"); @@ -3368,6 +3391,8 @@ } else if (n_idx == 0) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("invalid number of indices for matrix expression"); @@ -3392,6 +3417,8 @@ { if (! (rhs_dims.all_ones () || rhs_dims.any_zero ())) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A([]) = X: X must be an empty matrix or scalar"); @@ -3440,6 +3467,8 @@ } else { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(I) = X: X must be a scalar or a matrix with the same size as I"); @@ -3551,6 +3580,8 @@ } else if (new_dims_numel != rhs_dims_numel || new_dims_vec > 1) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(IDX-LIST) = RHS: mismatched index and RHS dimension"); return retval; @@ -3578,6 +3609,8 @@ k++; else if (nelem != 1) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(IDX-LIST) = RHS: mismatched index and RHS dimension"); return retval; @@ -3620,6 +3653,8 @@ // be an error, because we don't know how to undo that // later... + lhs.clear_index (); + (*current_liboctave_error_handler) ("array index %d (= %d) for assignment requires invalid resizing operation", n_idx, new_dims(n_idx-1)); @@ -3746,6 +3781,8 @@ if (n != rhs.numel ()) { + lhs.clear_index (); + (*current_liboctave_error_handler) ("A(IDX-LIST) = X: X must be a scalar or size of X must equal number of elements indexed by IDX-LIST");
--- a/liboctave/ChangeLog +++ b/liboctave/ChangeLog @@ -1,3 +1,9 @@ +2008-09-19 John W. Eaton <jwe@octave.org> + + * Array.cc (assign1, assign2, assignN): + Clear lhs index before throwing error. + (Array<T>::value): Clear index before throwing error. + 2008-09-18 Jaroslav Hajek <highegg@gmail.com> * Array.cc (maybe_delete_elements_2 (idx_vector&)): Fix tests to get