Mercurial > octave
changeset 20667:8742e0b1cc49
eliminate more uses of error_state
* Cell.cc, __contourc__.cc, __dsearchn__.cc, debug.cc, dirfns.cc,
octave-link.cc, sparse.cc, symbfact.cc, ov-usr-fcn.cc:
Eliminate simple uses of error_state.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 29 Oct 2015 17:16:38 -0400 |
parents | e0e2c2ce7e94 |
children | 0ec7ce024c92 |
files | libinterp/corefcn/Cell.cc libinterp/corefcn/__contourc__.cc libinterp/corefcn/__dsearchn__.cc libinterp/corefcn/debug.cc libinterp/corefcn/dirfns.cc libinterp/corefcn/octave-link.cc libinterp/corefcn/sparse.cc libinterp/dldfcn/symbfact.cc libinterp/octave-value/ov-usr-fcn.cc |
diffstat | 9 files changed, 198 insertions(+), 245 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/Cell.cc Fri Oct 23 16:55:23 2015 -0400 +++ b/libinterp/corefcn/Cell.cc Thu Oct 29 17:16:38 2015 -0400 @@ -191,8 +191,7 @@ k = 1; idx_vector j = idx_arg(1).index_vector (); - if (! error_state) - retval = Array<octave_value>::index (i, j, resize_ok, Matrix ()); + retval = Array<octave_value>::index (i, j, resize_ok, Matrix ()); } break;
--- a/libinterp/corefcn/__contourc__.cc Fri Oct 23 16:55:23 2015 -0400 +++ b/libinterp/corefcn/__contourc__.cc Thu Oct 29 17:16:38 2015 -0400 @@ -312,19 +312,14 @@ Matrix Z = args(2).matrix_value (); RowVector L = args(3).row_vector_value (); - if (! error_state) - { - contourc.resize (2, 0); - - for (int i = 0; i < L.numel (); i++) - cntr (X, Y, Z, L (i)); + contourc.resize (2, 0); - end_contour (); + for (int i = 0; i < L.numel (); i++) + cntr (X, Y, Z, L (i)); - retval = contourc; - } - else - error ("__contourc__: invalid argument values"); + end_contour (); + + retval = contourc; } else print_usage ();
--- a/libinterp/corefcn/__dsearchn__.cc Fri Oct 23 16:55:23 2015 -0400 +++ b/libinterp/corefcn/__dsearchn__.cc Thu Oct 29 17:16:38 2015 -0400 @@ -52,20 +52,18 @@ Matrix x = args(0).matrix_value ().transpose (); Matrix xi = args(1).matrix_value ().transpose (); - if (! error_state) + if (x.rows () != xi.rows () || x.columns () < 1) + error ("__dsearch__: number of rows of X and XI must match"); + else { - if (x.rows () != xi.rows () || x.columns () < 1) - error ("__dsearch__: number of rows of X and XI must match"); - else - { - octave_idx_type n = x.rows (); - octave_idx_type nx = x.columns (); - octave_idx_type nxi = xi.columns (); + octave_idx_type n = x.rows (); + octave_idx_type nx = x.columns (); + octave_idx_type nxi = xi.columns (); - ColumnVector idx (nxi); - double *pidx = idx.fortran_vec (); - ColumnVector dist (nxi); - double *pdist = dist.fortran_vec (); + ColumnVector idx (nxi); + double *pidx = idx.fortran_vec (); + ColumnVector dist (nxi); + double *pdist = dist.fortran_vec (); #define DIST(dd, y, yi, m) \ dd = 0.; \ @@ -76,34 +74,33 @@ } \ dd = sqrt (dd); - const double *pxi = xi.fortran_vec (); - for (octave_idx_type i = 0; i < nxi; i++) + const double *pxi = xi.fortran_vec (); + for (octave_idx_type i = 0; i < nxi; i++) + { + double d0; + const double *px = x.fortran_vec (); + DIST(d0, px, pxi, n); + *pidx = 1.; + for (octave_idx_type j = 1; j < nx; j++) { - double d0; - const double *px = x.fortran_vec (); - DIST(d0, px, pxi, n); - *pidx = 1.; - for (octave_idx_type j = 1; j < nx; j++) + px += n; + double d; + DIST (d, px, pxi, n); + if (d < d0) { - px += n; - double d; - DIST (d, px, pxi, n); - if (d < d0) - { - d0 = d; - *pidx = static_cast<double>(j + 1); - } - OCTAVE_QUIT; + d0 = d; + *pidx = static_cast<double>(j + 1); } - - *pdist++ = d0; - pidx++; - pxi += n; + OCTAVE_QUIT; } - retval(1) = dist; - retval(0) = idx; + *pdist++ = d0; + pidx++; + pxi += n; } + + retval(1) = dist; + retval(0) = idx; } return retval;
--- a/libinterp/corefcn/debug.cc Fri Oct 23 16:55:23 2015 -0400 +++ b/libinterp/corefcn/debug.cc Thu Oct 29 17:16:38 2015 -0400 @@ -1546,15 +1546,7 @@ bool state = true; if (nargin == 1) - { - state = args(0).bool_value (); - - if (error_state) - { - gripe_wrong_type_arg ("db_next_breakpoint", args(0), true); - return retval; - } - } + state = args(0).bool_value (); tree_evaluator::quiet_breakpoint_flag = state; }
--- a/libinterp/corefcn/dirfns.cc Fri Oct 23 16:55:23 2015 -0400 +++ b/libinterp/corefcn/dirfns.cc Thu Oct 29 17:16:38 2015 -0400 @@ -630,14 +630,9 @@ string_vector pat = args(0).all_strings (); string_vector str = args(1).all_strings (); - if (error_state) - gripe_wrong_type_arg ("fnmatch", args(0)); - else - { - glob_match pattern (file_ops::tilde_expand (pat)); + glob_match pattern (file_ops::tilde_expand (pat)); - retval = pattern.match (str); - } + retval = pattern.match (str); } else print_usage ();
--- a/libinterp/corefcn/octave-link.cc Fri Oct 23 16:55:23 2015 -0400 +++ b/libinterp/corefcn/octave-link.cc Thu Oct 29 17:16:38 2015 -0400 @@ -214,55 +214,50 @@ (flist.columns () > 1 ? flist(i,1) : ""))); - if (! error_state) - { - flush_octave_stdout (); - - std::list<std::string> items_lst - = octave_link::file_dialog (filter_lst, title, filename, pathname, - multi_on); - - nel = items_lst.size (); + flush_octave_stdout (); - retval.resize (3); + std::list<std::string> items_lst + = octave_link::file_dialog (filter_lst, title, filename, pathname, + multi_on); - // If 3, then retval is filename, directory, and selected index. - if (nel <= 3) - { - int idx = 0; - for (std::list<std::string>::iterator it = items_lst.begin (); - it != items_lst.end (); it++) - { - retval(idx++) = *it; + nel = items_lst.size (); + + retval.resize (3); - if (idx == 1 && retval(0).string_value ().length () == 0) - retval(0) = 0; - - if (idx == 3) - retval(2) = atoi (retval(2).string_value ().c_str ()); - } - } - else + // If 3, then retval is filename, directory, and selected index. + if (nel <= 3) + { + int idx = 0; + for (std::list<std::string>::iterator it = items_lst.begin (); + it != items_lst.end (); it++) { - // Multiple files. - nel = items_lst.size () - 2; - Cell items (dim_vector (1, nel)); - - std::list<std::string>::iterator it = items_lst.begin (); + retval(idx++) = *it; - for (int idx = 0; idx < nel; idx++) - { - items.xelem (idx) = *it; - it++; - } + if (idx == 1 && retval(0).string_value ().length () == 0) + retval(0) = 0; - retval(0) = items; - retval(1) = *it++; - retval(2) = atoi (it->c_str ()); + if (idx == 3) + retval(2) = atoi (retval(2).string_value ().c_str ()); } } else - error ("invalid arguments"); + { + // Multiple files. + nel = items_lst.size () - 2; + Cell items (dim_vector (1, nel)); + + std::list<std::string>::iterator it = items_lst.begin (); + + for (int idx = 0; idx < nel; idx++) + { + items.xelem (idx) = *it; + it++; + } + + retval(0) = items; + retval(1) = *it++; + retval(2) = atoi (it->c_str ()); + } } return retval;
--- a/libinterp/corefcn/sparse.cc Fri Oct 23 16:55:23 2015 -0400 +++ b/libinterp/corefcn/sparse.cc Thu Oct 29 17:16:38 2015 -0400 @@ -185,7 +185,7 @@ { get_dimensions (args(3), args(4), "sparse", m, n); - if (! error_state && (m < 0 || n < 0)) + if (m < 0 || n < 0) error ("sparse: dimensions must be non-negative"); } else if (nargin != 3)
--- a/libinterp/dldfcn/symbfact.cc Fri Oct 23 16:55:23 2015 -0400 +++ b/libinterp/dldfcn/symbfact.cc Thu Oct 29 17:16:38 2015 -0400 @@ -198,165 +198,152 @@ if (A->stype && A->nrow != A->ncol) error ("symbfact: S must be a square matrix"); - if (!error_state) + OCTAVE_LOCAL_BUFFER (octave_idx_type, Parent, n); + OCTAVE_LOCAL_BUFFER (octave_idx_type, Post, n); + OCTAVE_LOCAL_BUFFER (octave_idx_type, ColCount, n); + OCTAVE_LOCAL_BUFFER (octave_idx_type, First, n); + OCTAVE_LOCAL_BUFFER (octave_idx_type, Level, n); + + cholmod_sparse *F = CHOLMOD_NAME(transpose) (A, 0, cm); + cholmod_sparse *Aup, *Alo; + + if (A->stype == 1 || coletree) { - OCTAVE_LOCAL_BUFFER (octave_idx_type, Parent, n); - OCTAVE_LOCAL_BUFFER (octave_idx_type, Post, n); - OCTAVE_LOCAL_BUFFER (octave_idx_type, ColCount, n); - OCTAVE_LOCAL_BUFFER (octave_idx_type, First, n); - OCTAVE_LOCAL_BUFFER (octave_idx_type, Level, n); + Aup = A ; + Alo = F ; + } + else + { + Aup = F ; + Alo = A ; + } + + CHOLMOD_NAME(etree) (Aup, Parent, cm); + + if (cm->status < CHOLMOD_OK) + error ("matrix corrupted"); - cholmod_sparse *F = CHOLMOD_NAME(transpose) (A, 0, cm); - cholmod_sparse *Aup, *Alo; + if (CHOLMOD_NAME(postorder) (Parent, n, 0, Post, cm) != n) + error ("postorder failed"); + + CHOLMOD_NAME(rowcolcounts) (Alo, 0, 0, Parent, Post, 0, + ColCount, First, Level, cm); + + if (cm->status < CHOLMOD_OK) + error ("matrix corrupted"); + + if (nargout > 4) + { + cholmod_sparse *A1, *A2; - if (A->stype == 1 || coletree) + if (A->stype == 1) + { + A1 = A; + A2 = 0; + } + else if (A->stype == -1) { - Aup = A ; - Alo = F ; + A1 = F; + A2 = 0; + } + else if (coletree) + { + A1 = F; + A2 = A; } else { - Aup = F ; - Alo = A ; - } - - CHOLMOD_NAME(etree) (Aup, Parent, cm); - - if (cm->status < CHOLMOD_OK) - { - error ("matrix corrupted"); - goto symbfact_error; - } - - if (CHOLMOD_NAME(postorder) (Parent, n, 0, Post, cm) != n) - { - error ("postorder failed"); - goto symbfact_error; - } - - CHOLMOD_NAME(rowcolcounts) (Alo, 0, 0, Parent, Post, 0, - ColCount, First, Level, cm); - - if (cm->status < CHOLMOD_OK) - { - error ("matrix corrupted"); - goto symbfact_error; + A1 = A; + A2 = F; } - if (nargout > 4) - { - cholmod_sparse *A1, *A2; - - if (A->stype == 1) - { - A1 = A; - A2 = 0; - } - else if (A->stype == -1) - { - A1 = F; - A2 = 0; - } - else if (coletree) - { - A1 = F; - A2 = A; - } - else - { - A1 = A; - A2 = F; - } - - // count the total number of entries in L - octave_idx_type lnz = 0 ; - for (octave_idx_type j = 0 ; j < n ; j++) - lnz += ColCount[j]; + // count the total number of entries in L + octave_idx_type lnz = 0 ; + for (octave_idx_type j = 0 ; j < n ; j++) + lnz += ColCount[j]; - // allocate the output matrix L (pattern-only) - SparseBoolMatrix L (n, n, lnz); + // allocate the output matrix L (pattern-only) + SparseBoolMatrix L (n, n, lnz); - // initialize column pointers - lnz = 0; - for (octave_idx_type j = 0 ; j < n ; j++) - { - L.xcidx(j) = lnz; - lnz += ColCount[j]; - } - L.xcidx(n) = lnz; + // initialize column pointers + lnz = 0; + for (octave_idx_type j = 0 ; j < n ; j++) + { + L.xcidx(j) = lnz; + lnz += ColCount[j]; + } + L.xcidx(n) = lnz; - /* create a copy of the column pointers */ - octave_idx_type *W = First; - for (octave_idx_type j = 0 ; j < n ; j++) - W[j] = L.xcidx (j); + /* create a copy of the column pointers */ + octave_idx_type *W = First; + for (octave_idx_type j = 0 ; j < n ; j++) + W[j] = L.xcidx (j); - // get workspace for computing one row of L - cholmod_sparse *R - = CHOLMOD_NAME (allocate_sparse) (n, 1, n, false, true, - 0, CHOLMOD_PATTERN, cm); - octave_idx_type *Rp = static_cast<octave_idx_type *>(R->p); - octave_idx_type *Ri = static_cast<octave_idx_type *>(R->i); + // get workspace for computing one row of L + cholmod_sparse *R + = CHOLMOD_NAME (allocate_sparse) (n, 1, n, false, true, + 0, CHOLMOD_PATTERN, cm); + octave_idx_type *Rp = static_cast<octave_idx_type *>(R->p); + octave_idx_type *Ri = static_cast<octave_idx_type *>(R->i); - // compute L one row at a time - for (octave_idx_type k = 0 ; k < n ; k++) - { - // get the kth row of L and store in the columns of L - CHOLMOD_NAME (row_subtree) (A1, A2, k, Parent, R, cm) ; - for (octave_idx_type p = 0 ; p < Rp[1] ; p++) - L.xridx (W[Ri[p]]++) = k ; + // compute L one row at a time + for (octave_idx_type k = 0 ; k < n ; k++) + { + // get the kth row of L and store in the columns of L + CHOLMOD_NAME (row_subtree) (A1, A2, k, Parent, R, cm) ; + for (octave_idx_type p = 0 ; p < Rp[1] ; p++) + L.xridx (W[Ri[p]]++) = k ; - // add the diagonal entry - L.xridx (W[k]++) = k ; - } + // add the diagonal entry + L.xridx (W[k]++) = k ; + } - // free workspace - CHOLMOD_NAME (free_sparse) (&R, cm) ; + // free workspace + CHOLMOD_NAME (free_sparse) (&R, cm) ; - // transpose L to get R, or leave as is - if (nargin < 3) - L = L.transpose (); - - // fill numerical values of L with one's - for (octave_idx_type p = 0 ; p < lnz ; p++) - L.xdata(p) = true; + // transpose L to get R, or leave as is + if (nargin < 3) + L = L.transpose (); - retval(4) = L; - } - - ColumnVector tmp (n); - if (nargout > 3) - { - for (octave_idx_type i = 0; i < n; i++) - tmp(i) = Post[i] + 1; - retval(3) = tmp; - } + // fill numerical values of L with one's + for (octave_idx_type p = 0 ; p < lnz ; p++) + L.xdata(p) = true; - if (nargout > 2) - { - for (octave_idx_type i = 0; i < n; i++) - tmp(i) = Parent[i] + 1; - retval(2) = tmp; - } + retval(4) = L; + } - if (nargout > 1) - { - /* compute the elimination tree height */ - octave_idx_type height = 0 ; - for (int i = 0 ; i < n ; i++) - height = (height > Level[i] ? height : Level[i]); - height++ ; - retval(1) = static_cast<double> (height); - } - + ColumnVector tmp (n); + if (nargout > 3) + { for (octave_idx_type i = 0; i < n; i++) - tmp(i) = ColCount[i]; - retval(0) = tmp; + tmp(i) = Post[i] + 1; + retval(3) = tmp; } -symbfact_error: + if (nargout > 2) + { + for (octave_idx_type i = 0; i < n; i++) + tmp(i) = Parent[i] + 1; + retval(2) = tmp; + } + + if (nargout > 1) + { + /* compute the elimination tree height */ + octave_idx_type height = 0 ; + for (int i = 0 ; i < n ; i++) + height = (height > Level[i] ? height : Level[i]); + height++ ; + retval(1) = static_cast<double> (height); + } + + for (octave_idx_type i = 0; i < n; i++) + tmp(i) = ColCount[i]; + retval(0) = tmp; + #else error ("symbfact: not available in this version of Octave"); #endif
--- a/libinterp/octave-value/ov-usr-fcn.cc Fri Oct 23 16:55:23 2015 -0400 +++ b/libinterp/octave-value/ov-usr-fcn.cc Thu Oct 29 17:16:38 2015 -0400 @@ -1083,11 +1083,6 @@ if (! symbol_table::at_top_level ()) { int nargout1 = symbol_table::varval (".nargout.").int_value (); - if (error_state) - { - error ("isargout: internal error"); - return retval; - } Matrix ignored; octave_value tmp = symbol_table::varval (".ignored."); @@ -1105,9 +1100,7 @@ const NDArray ka = args(0).array_value (); boolNDArray r (ka.dims ()); - for (octave_idx_type i = 0; - i < ka.numel () && ! error_state; - i++) + for (octave_idx_type i = 0; i < ka.numel (); i++) r(i) = isargout1 (nargout1, ignored, ka(i)); retval = r;