Mercurial > octave-nkf
diff src/pt-misc.cc @ 9644:080e11f1b0c1
don't return undefined output values from user functions
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 15 Sep 2009 17:17:13 +0200 |
parents | eb63fbe60fab |
children | 318e0cdd31bd |
line wrap: on
line diff
--- a/src/pt-misc.cc Tue Sep 15 10:00:53 2009 +0200 +++ b/src/pt-misc.cc Tue Sep 15 17:17:13 2009 +0200 @@ -204,26 +204,37 @@ } octave_value_list -tree_parameter_list::convert_to_const_vector (const Cell& varargout) +tree_parameter_list::convert_to_const_vector (int nargout, + const Cell& varargout) { octave_idx_type vlen = varargout.numel (); - int nout = length () + vlen; + // Special case. Will do a shallow copy. + if (length () == 0 && vlen == nargout) + return varargout; - octave_value_list retval (nout, octave_value ()); + // We want always at least one return value. + int nout = std::max (nargout, 1); + octave_value_list retval (nout); int i = 0; - for (iterator p = begin (); p != end (); p++) + for (iterator p = begin (); p != end () && i < nout; p++) { tree_decl_elt *elt = *p; retval(i++) = elt->is_defined () ? elt->rvalue1 () : octave_value (); } + vlen = std::min (vlen, nout - i); + for (octave_idx_type j = 0; j < vlen; j++) retval(i++) = varargout(j); + // If there was zero outputs requested, and nothing is defined, don't return anything. + if (nargout == 0 && retval(0).is_undefined ()) + retval = octave_value_list (); + return retval; }