# HG changeset patch # User John W. Eaton # Date 1444099662 14400 # Node ID 56fee8f84fe70d212b818f631785d42e05789c6d # Parent 0650b8431037461fd9d75761a92b7a8153fcac4d eliminate more simple uses of error_state * cellfun.cc, syscalls.cc, urlwrite.cc, ov.cc, pt-eval.cc: Eliminate uses of error_state. diff -r 0650b8431037 -r 56fee8f84fe7 libinterp/corefcn/cellfun.cc --- a/libinterp/corefcn/cellfun.cc Mon Oct 05 21:37:03 2015 -0400 +++ b/libinterp/corefcn/cellfun.cc Mon Oct 05 22:47:42 2015 -0400 @@ -183,19 +183,18 @@ if (d < 0) error ("cellfun: K must be a positive integer"); - if (! error_state) + NDA result (f_args.dims ()); + + for (octave_idx_type count = 0; count < k; count++) { - NDA result (f_args.dims ()); - for (octave_idx_type count = 0; count < k; count++) - { - dim_vector dv = f_args.elem (count).dims (); - if (d < dv.length ()) - result(count) = static_cast (dv(d)); - else - result(count) = 1.0; - } - retval(0) = result; + dim_vector dv = f_args.elem (count).dims (); + if (d < dv.length ()) + result(count) = static_cast (dv(d)); + else + result(count) = 1.0; } + + retval(0) = result; } else error ("cellfun: not enough arguments for \"size\""); @@ -431,7 +430,7 @@ { retval = try_cellfun_internal_ops(args, nargin); - if (error_state || ! retval.empty ()) + if (! retval.empty ()) return retval; // See if we can convert the string into a function. @@ -447,7 +446,7 @@ = extract_function (args(0), "cellfun", fcn_name, fname, "; endfunction"); - if (ptr_func && ! error_state) + if (ptr_func) func = octave_value (ptr_func, true); } else @@ -458,7 +457,7 @@ error ("cellfun: invalid function NAME: %s", name.c_str ()); } - if (error_state || ! retval.empty ()) + if (! retval.empty ()) return retval; } @@ -507,7 +506,7 @@ retval = try_cellfun_internal_ops (tmp_args, nargin); - if (error_state || ! retval.empty ()) + if (! retval.empty ()) return retval; } @@ -517,11 +516,9 @@ func = f; } } + nevermind: - if (error_state) - return octave_value_list (); - // Extract cell arguments. octave_value_list inputlist (nargin, octave_value ()); @@ -599,9 +596,6 @@ = get_output_list (count, nargout, inputlist, func, error_handler); - if (error_state) - return retval; - if (nargout > 0 && tmp.length () < nargout) { error ("cellfun: function returned fewer than nargout values"); @@ -650,9 +644,6 @@ idx_list.front ()(0) = count + 1.0; retv[j].assign (octave_value::op_asn_eq, idx_type, idx_list, val); - - if (error_state) - break; } else { @@ -664,9 +655,6 @@ } } } - - if (error_state) - break; } retval.resize (nargout1); @@ -700,9 +688,6 @@ = get_output_list (count, nargout, inputlist, func, error_handler); - if (error_state) - return retval; - if (nargout > 0 && tmp.length () < nargout) { error ("cellfun: function returned fewer than nargout values"); @@ -1202,7 +1187,7 @@ = extract_function (args(0), "arrayfun", fcn_name, fname, "; endfunction"); - if (ptr_func && ! error_state) + if (ptr_func) func = octave_value (ptr_func, true); } else @@ -1216,9 +1201,6 @@ symbol_table_lookup = true; } - - if (error_state) - return retval; } if (func.is_function_handle () || func.is_inline_function () @@ -1256,9 +1238,6 @@ get_mapper_fun_options (args, nargin, uniform_output, error_handler); - if (error_state) - return octave_value_list (); - octave_value_list inputlist (nargin, octave_value ()); OCTAVE_LOCAL_BUFFER (octave_value, inputs, nargin); @@ -1325,18 +1304,12 @@ { if (mask[j]) inputlist.xelem (j) = inputs[j].do_index_op (idx_list); - - if (error_state) - return retval; } const octave_value_list tmp = get_output_list (count, nargout, inputlist, func, error_handler); - if (error_state) - return retval; - if (nargout > 0 && tmp.length () < nargout) { error_with_id ("Octave:invalid-fun-call", @@ -1387,9 +1360,6 @@ idx_list.front ()(0) = count + 1.0; retv[j].assign (octave_value::op_asn_eq, idx_type, idx_list, val); - - if (error_state) - break; } else { @@ -1402,9 +1372,6 @@ } } } - - if (error_state) - break; } retval.resize (nargout1); @@ -1438,18 +1405,12 @@ { if (mask[j]) inputlist.xelem (j) = inputs[j].do_index_op (idx_list); - - if (error_state) - return retval; } const octave_value_list tmp = get_output_list (count, nargout, inputlist, func, error_handler); - if (error_state) - return retval; - if (nargout > 0 && tmp.length () < nargout) { error_with_id ("Octave:invalid-fun-call", @@ -1781,8 +1742,6 @@ dim_vector celldv, arraydv; Array perm; do_num2cell_helper (array.dims (), dimv, celldv, arraydv, perm); - if (error_state) - return Cell (); NDA parray = array.permute (perm); @@ -1834,23 +1793,17 @@ { dim_vector dv = get_object_dims (array); - if (! error_state) - { - retval.resize (dv); + retval.resize (dv); - octave_value_list idx (1); + octave_value_list idx (1); - for (octave_idx_type i = 0; i < dv.numel (); i++) - { - octave_quit (); - - idx(0) = double (i+1); + for (octave_idx_type i = 0; i < dv.numel (); i++) + { + octave_quit (); - retval.xelem (i) = array.single_subsref ("(", idx); + idx(0) = double (i+1); - if (error_state) - break; - } + retval.xelem (i) = array.single_subsref ("(", idx); } } else @@ -1909,9 +1862,7 @@ if (nargin > 1) dimv = args(1).int_vector_value (true); - if (error_state) - ; - else if (array.is_bool_type ()) + if (array.is_bool_type ()) retval = do_num2cell (array.bool_array_value (), dimv); else if (array.is_char_matrix ()) retval = do_num2cell (array.char_array_value (), dimv); @@ -2182,9 +2133,6 @@ retval(j) = a.do_index_op (ra_idx); - if (error_state) - break; - rdv.increment_index (ridx); } @@ -2247,11 +2195,7 @@ OCTAVE_LOCAL_BUFFER (Array, d, nargin-1); for (int i = 1; i < nargin; i++) - { - d[i-1] = args(i).octave_idx_type_vector_value (true); - if (error_state) - return retval; - } + d[i-1] = args(i).octave_idx_type_vector_value (true); octave_value a = args(0); bool sparse = a.is_sparse_type (); @@ -2341,7 +2285,7 @@ || (dim == 0 && array.columns () == 1) || (dim == 1 && array.rows () == 1))) { - for (octave_idx_type i = 0; i < n && ! error_state; i++) + for (octave_idx_type i = 0; i < n; i++) retval(i) = array.index (idx_vector (lb(i) - 1, ub(i))); } else @@ -2354,7 +2298,7 @@ Array idx (dim_vector (ndims, 1), idx_vector::colon); - for (octave_idx_type i = 0; i < n && ! error_state; i++) + for (octave_idx_type i = 0; i < n; i++) { idx(dim) = idx_vector (lb(i) - 1, ub(i)); retval(i) = array.index (idx); @@ -2403,88 +2347,85 @@ error ("cellslices: DIM must be a valid dimension"); } - if (! error_state) + if (lb.numel () != ub.numel ()) + error ("cellslices: the lengths of LB and UB must match"); + else { - if (lb.numel () != ub.numel ()) - error ("cellslices: the lengths of LB and UB must match"); - else + Cell retcell; + if (! x.is_sparse_type () && x.is_matrix_type ()) { - Cell retcell; - if (! x.is_sparse_type () && x.is_matrix_type ()) + // specialize for some dense arrays. + if (x.is_bool_type ()) + retcell = do_cellslices_nda (x.bool_array_value (), + lb, ub, dim); + else if (x.is_char_matrix ()) + retcell = do_cellslices_nda (x.char_array_value (), + lb, ub, dim); + else if (x.is_integer_type ()) { - // specialize for some dense arrays. - if (x.is_bool_type ()) - retcell = do_cellslices_nda (x.bool_array_value (), + if (x.is_int8_type ()) + retcell = do_cellslices_nda (x.int8_array_value (), lb, ub, dim); - else if (x.is_char_matrix ()) - retcell = do_cellslices_nda (x.char_array_value (), + else if (x.is_int16_type ()) + retcell = do_cellslices_nda (x.int16_array_value (), + lb, ub, dim); + else if (x.is_int32_type ()) + retcell = do_cellslices_nda (x.int32_array_value (), lb, ub, dim); - else if (x.is_integer_type ()) - { - if (x.is_int8_type ()) - retcell = do_cellslices_nda (x.int8_array_value (), - lb, ub, dim); - else if (x.is_int16_type ()) - retcell = do_cellslices_nda (x.int16_array_value (), - lb, ub, dim); - else if (x.is_int32_type ()) - retcell = do_cellslices_nda (x.int32_array_value (), - lb, ub, dim); - else if (x.is_int64_type ()) - retcell = do_cellslices_nda (x.int64_array_value (), - lb, ub, dim); - else if (x.is_uint8_type ()) - retcell = do_cellslices_nda (x.uint8_array_value (), - lb, ub, dim); - else if (x.is_uint16_type ()) - retcell = do_cellslices_nda (x.uint16_array_value (), - lb, ub, dim); - else if (x.is_uint32_type ()) - retcell = do_cellslices_nda (x.uint32_array_value (), - lb, ub, dim); - else if (x.is_uint64_type ()) - retcell = do_cellslices_nda (x.uint64_array_value (), - lb, ub, dim); - } - else if (x.is_complex_type ()) - { - if (x.is_single_type ()) - retcell = do_cellslices_nda (x.float_complex_array_value (), - lb, ub, dim); - else - retcell = do_cellslices_nda (x.complex_array_value (), - lb, ub, dim); - } + else if (x.is_int64_type ()) + retcell = do_cellslices_nda (x.int64_array_value (), + lb, ub, dim); + else if (x.is_uint8_type ()) + retcell = do_cellslices_nda (x.uint8_array_value (), + lb, ub, dim); + else if (x.is_uint16_type ()) + retcell = do_cellslices_nda (x.uint16_array_value (), + lb, ub, dim); + else if (x.is_uint32_type ()) + retcell = do_cellslices_nda (x.uint32_array_value (), + lb, ub, dim); + else if (x.is_uint64_type ()) + retcell = do_cellslices_nda (x.uint64_array_value (), + lb, ub, dim); + } + else if (x.is_complex_type ()) + { + if (x.is_single_type ()) + retcell = do_cellslices_nda (x.float_complex_array_value (), + lb, ub, dim); else - { - if (x.is_single_type ()) - retcell = do_cellslices_nda (x.float_array_value (), - lb, ub, dim); - else - retcell = do_cellslices_nda (x.array_value (), - lb, ub, dim); - } + retcell = do_cellslices_nda (x.complex_array_value (), + lb, ub, dim); } else { - // generic code. - octave_idx_type n = lb.numel (); - retcell = Cell (1, n); - const dim_vector dv = x.dims (); - int ndims = dv.length (); - if (dim < 0) - dim = dv.first_non_singleton (); - ndims = std::max (ndims, dim + 1); - octave_value_list idx (ndims, octave_value::magic_colon_t); - for (octave_idx_type i = 0; i < n && ! error_state; i++) - { - idx(dim) = Range (lb(i), ub(i)); - retcell(i) = x.do_index_op (idx); - } + if (x.is_single_type ()) + retcell = do_cellslices_nda (x.float_array_value (), + lb, ub, dim); + else + retcell = do_cellslices_nda (x.array_value (), + lb, ub, dim); } - if (! error_state) - retval = retcell; } + else + { + // generic code. + octave_idx_type n = lb.numel (); + retcell = Cell (1, n); + const dim_vector dv = x.dims (); + int ndims = dv.length (); + if (dim < 0) + dim = dv.first_non_singleton (); + ndims = std::max (ndims, dim + 1); + octave_value_list idx (ndims, octave_value::magic_colon_t); + for (octave_idx_type i = 0; i < n; i++) + { + idx(dim) = Range (lb(i), ub(i)); + retcell(i) = x.do_index_op (idx); + } + } + + retval = retcell; } } else @@ -2519,6 +2460,7 @@ @end deftypefn") { octave_value retval; + if (args.length () >= 1) { if (args(0).is_cell ()) @@ -2531,10 +2473,10 @@ for (octave_idx_type i = 0; i < nel; i++) { octave_quit (); + octave_value tmp = x(i); + y(i) = tmp.do_index_op (idx); - if (error_state) - break; } retval = y; diff -r 0650b8431037 -r 56fee8f84fe7 libinterp/corefcn/syscalls.cc --- a/libinterp/corefcn/syscalls.cc Mon Oct 05 21:37:03 2015 -0400 +++ b/libinterp/corefcn/syscalls.cc Mon Oct 05 22:47:42 2015 -0400 @@ -137,20 +137,17 @@ octave_stream new_stream = octave_stream_list::lookup (args(1), "dup2"); - if (! error_state) - { - int i_old = old_stream.file_number (); - int i_new = new_stream.file_number (); + int i_old = old_stream.file_number (); + int i_new = new_stream.file_number (); - if (i_old >= 0 && i_new >= 0) - { - std::string msg; + if (i_old >= 0 && i_new >= 0) + { + std::string msg; - int status = octave_syscalls::dup2 (i_old, i_new, msg); + int status = octave_syscalls::dup2 (i_old, i_new, msg); - retval(1) = msg; - retval(0) = status; - } + retval(1) = msg; + retval(0) = status; } } else @@ -223,20 +220,17 @@ exec_args[0] = exec_file; } - if (! error_state) - { - octave_history_write_timestamp (); + octave_history_write_timestamp (); - if (! command_history::ignoring_entries ()) - command_history::clean_up_and_save (); + if (! command_history::ignoring_entries ()) + command_history::clean_up_and_save (); - std::string msg; - - int status = octave_syscalls::execvp (exec_file, exec_args, msg); + std::string msg; - retval(1) = msg; - retval(0) = status; - } + int status = octave_syscalls::execvp (exec_file, exec_args, msg); + + retval(1) = msg; + retval(0) = status; } else error ("exec: FILE must be a string"); @@ -339,36 +333,33 @@ { bool sync_mode = (nargin == 3 ? args(2).bool_value () : false); - if (! error_state) - { - int fildes[2]; - std::string msg; - pid_t pid; + int fildes[2]; + std::string msg; + pid_t pid; - pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, - fildes, msg, interactive); - if (pid >= 0) - { - FILE *ifile = fdopen (fildes[1], "r"); - FILE *ofile = fdopen (fildes[0], "w"); + pid = octave_syscalls::popen2 (exec_file, arg_list, sync_mode, + fildes, msg, interactive); + if (pid >= 0) + { + FILE *ifile = fdopen (fildes[1], "r"); + FILE *ofile = fdopen (fildes[0], "w"); - std::string nm; + std::string nm; - octave_stream is = octave_stdiostream::create (nm, ifile, - std::ios::in); + octave_stream is = octave_stdiostream::create (nm, ifile, + std::ios::in); - octave_stream os = octave_stdiostream::create (nm, ofile, + octave_stream os = octave_stdiostream::create (nm, ofile, std::ios::out); - Cell file_ids (1, 2); + Cell file_ids (1, 2); - retval(2) = pid; - retval(1) = octave_stream_list::insert (is); - retval(0) = octave_stream_list::insert (os); - } - else - error (msg.c_str ()); + retval(2) = pid; + retval(1) = octave_stream_list::insert (is); + retval(0) = octave_stream_list::insert (os); } + else + error (msg.c_str ()); } else error ("popen2: all arguments must be strings"); @@ -527,20 +518,17 @@ int req = args(1).int_value (true); int arg = args(2).int_value (true); - if (! error_state) + // FIXME: Need better checking here? + if (fid < 0) + error ("fcntl: invalid file id"); + else { - // FIXME: Need better checking here? - if (fid < 0) - error ("fcntl: invalid file id"); - else - { - std::string msg; + std::string msg; - int status = octave_fcntl (fid, req, arg, msg); + int status = octave_fcntl (fid, req, arg, msg); - retval(1) = msg; - retval(0) = status; - } + retval(1) = msg; + retval(0) = status; } } else @@ -768,20 +756,14 @@ { pid_t pid = args(0).int_value (true); - if (! error_state) - { - int sig = args(1).int_value (true); + int sig = args(1).int_value (true); + + std::string msg; - if (! error_state) - { - std::string msg; + int status = octave_syscalls::kill (pid, sig, msg); - int status = octave_syscalls::kill (pid, sig, msg); - - retval(1) = msg; - retval(0) = status; - } - } + retval(1) = msg; + retval(0) = status; } else print_usage (); @@ -806,12 +788,9 @@ { std::string fname = args(0).string_value (); - if (! error_state) - { - file_stat fs (fname, false); + file_stat fs (fname, false); - retval = mk_stat_result (fs); - } + retval = mk_stat_result (fs); } else print_usage (); @@ -888,17 +867,14 @@ { int mode = convert (octal_mode, 8, 10); - if (! error_state) - { - std::string msg; + std::string msg; - int status = octave_mkfifo (name, mode, msg); + int status = octave_mkfifo (name, mode, msg); - retval(0) = status; + retval(0) = status; - if (status < 0) - retval(1) = msg; - } + if (status < 0) + retval(1) = msg; } } else @@ -1085,23 +1061,17 @@ { int fid = octave_stream_list::get_file_number (args(0)); - if (! error_state) - { - file_fstat fs (fid); + file_fstat fs (fid); - retval = mk_stat_result (fs); - } + retval = mk_stat_result (fs); } else { std::string fname = args(0).string_value (); - if (! error_state) - { - file_stat fs (fname); + file_stat fs (fname); - retval = mk_stat_result (fs); - } + retval = mk_stat_result (fs); } } else diff -r 0650b8431037 -r 56fee8f84fe7 libinterp/corefcn/urlwrite.cc --- a/libinterp/corefcn/urlwrite.cc Mon Oct 05 21:37:03 2015 -0400 +++ b/libinterp/corefcn/urlwrite.cc Mon Oct 05 22:47:42 2015 -0400 @@ -607,14 +607,10 @@ if (nargin > 2) passwd = args(2).string_value (); - if (! error_state) - { - curl_handle ch - = ch_manager::make_curl_handle (host, user, passwd, octave_stdout); + curl_handle ch + = ch_manager::make_curl_handle (host, user, passwd, octave_stdout); - if (! error_state) - retval = ch.value (); - } + retval = ch.value (); } return retval; @@ -636,9 +632,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) retval = curl.pwd (); else @@ -664,9 +657,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) { std::string path = ""; @@ -702,9 +692,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) { if (nargout == 0) @@ -783,9 +770,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) curl.ascii (); else @@ -811,9 +795,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) curl.binary (); else @@ -839,9 +820,6 @@ { curl_handle h = ch_manager::lookup (args(0)); - if (error_state) - return retval; - if (h.ok ()) ch_manager::free (h); else @@ -867,9 +845,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) retval = (curl.is_ascii () ? "ascii" : "binary"); else @@ -895,9 +870,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) { std::string file = args(1).string_value (); @@ -930,9 +902,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) { std::string dir = args(1).string_value (); @@ -965,9 +934,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) { std::string dir = args(1).string_value (); @@ -1000,9 +966,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) { std::string oldname = args(1).string_value (); @@ -1036,9 +999,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) { std::string pat = args(1).string_value (); @@ -1127,9 +1087,6 @@ { url_transfer curl = ch_manager::get_object (args(0)); - if (error_state) - return retval; - if (curl.is_valid ()) { std::string file = args(1).string_value (); diff -r 0650b8431037 -r 56fee8f84fe7 libinterp/octave-value/ov.cc --- a/libinterp/octave-value/ov.cc Mon Oct 05 21:37:03 2015 -0400 +++ b/libinterp/octave-value/ov.cc Mon Oct 05 22:47:42 2015 -0400 @@ -1318,7 +1318,7 @@ const std::list& idx, size_t skip) { - if (! error_state && idx.size () > skip) + if (idx.size () > skip) { std::list new_idx (idx); for (size_t i = 0; i < skip; i++) @@ -1334,7 +1334,7 @@ const std::list& idx, size_t skip) { - if (! error_state && idx.size () > skip) + if (idx.size () > skip) { std::list new_idx (idx); for (size_t i = 0; i < skip; i++) @@ -1351,7 +1351,7 @@ const std::list *lvalue_list, size_t skip) { - if (! error_state && idx.size () > skip) + if (idx.size () > skip) { std::list new_idx (idx); for (size_t i = 0; i < skip; i++) @@ -1367,7 +1367,7 @@ const std::list& idx, size_t skip) { - if (! error_state && idx.size () > skip) + if (idx.size () > skip) { std::list new_idx (idx); for (size_t i = 0; i < skip; i++) @@ -1443,28 +1443,21 @@ { octave_value t = subsref (type, idx); - if (! error_state) - { - binary_op binop = op_eq_to_binary_op (op); - - if (! error_state) - t_rhs = do_binary_op (binop, t, rhs); - } + binary_op binop = op_eq_to_binary_op (op); + + t_rhs = do_binary_op (binop, t, rhs); } else error ("in computed assignment A(index) OP= X, A must be defined first"); } - if (! error_state) - { - octave_value tmp = subsasgn (type, idx, t_rhs); - - if (error_state) - gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq), - type_name (), rhs.type_name ()); - else - *this = tmp; - } + octave_value tmp = subsasgn (type, idx, t_rhs); + + if (error_state) + gripe_assign_failed_or_no_method (assign_op_as_string (op_asn_eq), + type_name (), rhs.type_name ()); + else + *this = tmp; return *this; } @@ -1499,13 +1492,9 @@ binary_op binop = op_eq_to_binary_op (op); - if (! error_state) - { - octave_value t = do_binary_op (binop, *this, rhs); - - if (! error_state) - operator = (t); - } + octave_value t = do_binary_op (binop, *this, rhs); + + operator = (t); } } else @@ -1548,7 +1537,7 @@ octave_value tmp = do_binary_op (octave_value::op_eq, *this, test); // Empty array also means a match. - if (! error_state && tmp.is_defined ()) + if (tmp.is_defined ()) retval = tmp.is_true () || tmp.is_empty (); } @@ -1685,12 +1674,9 @@ { Array retval = array_value (force_string_conv); - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "real vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "real vector")); } template @@ -1736,36 +1722,30 @@ else { const NDArray a = array_value (force_string_conv); - if (! error_state) + + if (require_int) { - if (require_int) + retval.resize (a.dims ()); + for (octave_idx_type i = 0; i < a.numel (); i++) { - retval.resize (a.dims ()); - for (octave_idx_type i = 0; i < a.numel (); i++) + double ai = a.elem (i); + int v = static_cast (ai); + if (ai == v) + retval.xelem (i) = v; + else { - double ai = a.elem (i); - int v = static_cast (ai); - if (ai == v) - retval.xelem (i) = v; - else - { - error_with_cfn ("conversion to integer value failed"); - break; - } + error_with_cfn ("conversion to integer value failed"); + break; } } - else - retval = Array (a); } + else + retval = Array (a); } - - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "integer vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "integer vector")); } template @@ -1812,36 +1792,30 @@ else { const NDArray a = array_value (force_string_conv); - if (! error_state) + + if (require_int) { - if (require_int) + retval.resize (a.dims ()); + for (octave_idx_type i = 0; i < a.numel (); i++) { - retval.resize (a.dims ()); - for (octave_idx_type i = 0; i < a.numel (); i++) + double ai = a.elem (i); + octave_idx_type v = static_cast (ai); + if (ai == v) + retval.xelem (i) = v; + else { - double ai = a.elem (i); - octave_idx_type v = static_cast (ai); - if (ai == v) - retval.xelem (i) = v; - else - { - error_with_cfn ("conversion to integer value failed"); - break; - } + error_with_cfn ("conversion to integer value failed"); + break; } } - else - retval = Array (a); } + else + retval = Array (a); } - - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "integer vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "integer vector")); } Array @@ -1850,12 +1824,9 @@ { Array retval = complex_array_value (force_string_conv); - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "complex vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "complex vector")); } FloatColumnVector @@ -1897,12 +1868,9 @@ { Array retval = float_array_value (force_string_conv); - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "real vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "real vector")); } Array @@ -1911,12 +1879,9 @@ { Array retval = float_complex_array_value (force_string_conv); - if (error_state) - return retval; - else - return retval.reshape (make_vector_dims (retval.dims (), - force_vector_conversion, - type_name (), "complex vector")); + return retval.reshape (make_vector_dims (retval.dims (), + force_vector_conversion, + type_name (), "complex vector")); } octave_value @@ -2966,15 +2931,12 @@ decode_subscripts ("subsref", args(1), type, idx); - if (! error_state) - { - octave_value arg0 = args(0); - - if (type.empty ()) - retval = arg0; - else - retval = arg0.subsref (type, idx, nargout); - } + octave_value arg0 = args(0); + + if (type.empty ()) + retval = arg0; + else + retval = arg0.subsref (type, idx, nargout); } else print_usage (); @@ -3024,23 +2986,19 @@ decode_subscripts ("subsasgn", args(1), type, idx); - if (! error_state) + if (type.empty ()) { - if (type.empty ()) - { - // Regularize a null matrix if stored into a variable. - - retval = args(2).storable_value (); - } - else - { - octave_value arg0 = args(0); - - arg0.make_unique (); - - if (! error_state) - retval= arg0.subsasgn (type, idx, args(2)); - } + // Regularize a null matrix if stored into a variable. + + retval = args(2).storable_value (); + } + else + { + octave_value arg0 = args(0); + + arg0.make_unique (); + + retval= arg0.subsasgn (type, idx, args(2)); } } else diff -r 0650b8431037 -r 56fee8f84fe7 libinterp/parse-tree/pt-eval.cc --- a/libinterp/parse-tree/pt-eval.cc Mon Oct 05 21:37:03 2015 -0400 +++ b/libinterp/parse-tree/pt-eval.cc Mon Oct 05 22:47:42 2015 -0400 @@ -97,15 +97,12 @@ void tree_evaluator::visit_break_command (tree_break_command& cmd) { - if (! error_state) - { - if (debug_mode) - do_breakpoint (cmd.is_breakpoint ()); + if (debug_mode) + do_breakpoint (cmd.is_breakpoint ()); - if (statement_context == function || statement_context == script - || in_loop_command) - tree_break_command::breaking = 1; - } + if (statement_context == function || statement_context == script + || in_loop_command) + tree_break_command::breaking = 1; } void @@ -117,15 +114,12 @@ void tree_evaluator::visit_continue_command (tree_continue_command& cmd) { - if (! error_state) - { - if (debug_mode) - do_breakpoint (cmd.is_breakpoint ()); + if (debug_mode) + do_breakpoint (cmd.is_breakpoint ()); - if (statement_context == function || statement_context == script - || in_loop_command) - tree_continue_command::continuing = 1; - } + if (statement_context == function || statement_context == script + || in_loop_command) + tree_continue_command::continuing = 1; } void @@ -152,23 +146,20 @@ { id->mark_global (); - if (! error_state) - { - octave_lvalue ult = id->lvalue (); + octave_lvalue ult = id->lvalue (); - if (ult.is_undefined ()) - { - tree_expression *expr = elt.expression (); + if (ult.is_undefined ()) + { + tree_expression *expr = elt.expression (); - octave_value init_val; + octave_value init_val; - if (expr) - init_val = expr->rvalue1 (); - else - init_val = Matrix (); + if (expr) + init_val = expr->rvalue1 (); + else + init_val = Matrix (); - ult.assign (octave_value::op_asn_eq, init_val); - } + ult.assign (octave_value::op_asn_eq, init_val); } } } @@ -212,9 +203,6 @@ tree_decl_elt *elt = *p; fcn (*elt); - - if (error_state) - break; } } } @@ -255,12 +243,9 @@ octave_value init_val = expr->rvalue1 (); - if (! error_state) - { - ult.assign (octave_value::op_asn_eq, init_val); + ult.assign (octave_value::op_asn_eq, init_val); - retval = true; - } + retval = true; } return retval; @@ -284,8 +269,7 @@ if (tree_continue_command::continuing) tree_continue_command::continuing--; - bool quit = (error_state - || tree_return_command::returning + bool quit = (tree_return_command::returning || tree_break_command::breaking || tree_continue_command::continuing); @@ -298,9 +282,6 @@ void tree_evaluator::visit_simple_for_command (tree_simple_for_command& cmd) { - if (error_state) - return; - if (debug_mode) do_breakpoint (cmd.is_breakpoint ()); @@ -322,7 +303,7 @@ return; #endif - if (error_state || rhs.is_undefined ()) + if (rhs.is_undefined ()) return; { @@ -330,9 +311,6 @@ octave_lvalue ult = lhs->lvalue (); - if (error_state) - return; - tree_statement_list *loop_body = cmd.body (); if (rhs.is_range ()) @@ -347,7 +325,7 @@ ult.assign (octave_value::op_asn_eq, val); - if (! error_state && loop_body) + if (loop_body) loop_body->accept (*this); if (quit_loop_now ()) @@ -358,7 +336,7 @@ { ult.assign (octave_value::op_asn_eq, rhs); - if (! error_state && loop_body) + if (loop_body) loop_body->accept (*this); // Maybe decrement break and continue states. @@ -404,7 +382,7 @@ ult.assign (octave_value::op_asn_eq, val); - if (! error_state && loop_body) + if (loop_body) loop_body->accept (*this); if (quit_loop_now ()) @@ -423,9 +401,6 @@ void tree_evaluator::visit_complex_for_command (tree_complex_for_command& cmd) { - if (error_state) - return; - if (debug_mode) do_breakpoint (cmd.is_breakpoint ()); @@ -439,7 +414,7 @@ octave_value rhs = expr->rvalue1 (); - if (error_state || rhs.is_undefined ()) + if (rhs.is_undefined ()) return; if (rhs.is_map ()) @@ -481,7 +456,7 @@ val_ref.assign (octave_value::op_asn_eq, val); key_ref.assign (octave_value::op_asn_eq, key); - if (! error_state && loop_body) + if (loop_body) loop_body->accept (*this); if (quit_loop_now ()) @@ -574,13 +549,10 @@ if (tic->is_else_clause () || expr->is_logically_true ("if")) { - if (! error_state) - { - tree_statement_list *stmt_lst = tic->commands (); + tree_statement_list *stmt_lst = tic->commands (); - if (stmt_lst) - stmt_lst->accept (*this); - } + if (stmt_lst) + stmt_lst->accept (*this); break; } @@ -657,24 +629,21 @@ void tree_evaluator::visit_return_command (tree_return_command& cmd) { - if (! error_state) - { - if (debug_mode) - do_breakpoint (cmd.is_breakpoint ()); + if (debug_mode) + do_breakpoint (cmd.is_breakpoint ()); - // Act like dbcont. + // Act like dbcont. - if (Vdebugging - && octave_call_stack::current_frame () == current_frame) - { - Vdebugging = false; + if (Vdebugging + && octave_call_stack::current_frame () == current_frame) + { + Vdebugging = false; - reset_debug_state (); - } - else if (statement_context == function || statement_context == script - || in_loop_command) - tree_return_command::returning = 1; + reset_debug_state (); } + else if (statement_context == function || statement_context == script + || in_loop_command) + tree_return_command::returning = 1; } void @@ -745,7 +714,7 @@ octave_value tmp_result = expr->rvalue1 (0); - if (do_bind_ans && ! (error_state || tmp_result.is_undefined ())) + if (do_bind_ans && tmp_result.is_defined ()) bind_ans (tmp_result, expr->print_result () && statement_printing_enabled ()); @@ -755,13 +724,10 @@ } catch (const std::bad_alloc&) { - // FIXME: We want to use error_with_id here so that we set - // the error state, give users control over this error - // message, and so that we set the error_state appropriately - // so we'll get stack trace info when appropriate. But - // error_with_id will require some memory allocations. Is - // there anything we can do to make those more likely to - // succeed? + // FIXME: We want to use error_with_id here so that give users + // control over this error message but error_with_id will + // require some memory allocations. Is there anything we can + // do to make those more likely to succeed? error_with_id ("Octave:bad-alloc", "out of memory or dimension too large for Octave's index type"); @@ -774,9 +740,6 @@ { static octave_value_list empty_list; - if (error_state) - return; - tree_statement_list::iterator p = lst.begin (); if (p != lst.end ()) @@ -791,9 +754,6 @@ elt->accept (*this); - if (error_state) - break; - if (tree_break_command::breaking || tree_continue_command::continuing) break; @@ -853,7 +813,7 @@ tree_switch_case_list *lst = cmd.case_list (); - if (! error_state && lst) + if (lst) { for (tree_switch_case_list::iterator p = lst->begin (); p != lst->end (); p++) @@ -862,9 +822,6 @@ if (t->is_default_case () || t->label_matches (val)) { - if (error_state) - break; - tree_statement_list *stmt_lst = t->commands (); if (stmt_lst) @@ -1060,9 +1017,7 @@ // of interrupt or out-of-memory. do_unwind_protect_cleanup_code (cleanup_code); - // FIXME: should error_state be checked here? - // We want to rethrow the exception, even if error_state is set, so - // that interrupts continue. + // We want to rethrow the exception so that interrupts continue. throw; } @@ -1073,9 +1028,6 @@ void tree_evaluator::visit_while_command (tree_while_command& cmd) { - if (error_state) - return; - #if HAVE_LLVM if (tree_jit::execute (cmd)) return; @@ -1102,12 +1054,7 @@ tree_statement_list *loop_body = cmd.body (); if (loop_body) - { - loop_body->accept (*this); - - if (error_state) - return; - } + loop_body->accept (*this); if (quit_loop_now ()) break; @@ -1120,9 +1067,6 @@ void tree_evaluator::visit_do_until_command (tree_do_until_command& cmd) { - if (error_state) - return; - #if HAVE_LLVM if (tree_jit::execute (cmd)) return; @@ -1144,12 +1088,7 @@ tree_statement_list *loop_body = cmd.body (); if (loop_body) - { - loop_body->accept (*this); - - if (error_state) - return; - } + loop_body->accept (*this); if (quit_loop_now ()) break;