Mercurial > hg > octave-shane
changeset 9988:76cf4aec34e9
allow functions returning no value in cellfun
author | Jaroslav Hajek <highegg@gmail.com> |
---|---|
date | Tue, 15 Dec 2009 13:07:05 +0100 |
parents | bb30843c4929 |
children | d36f8c473dff |
files | src/ChangeLog src/DLD-FUNCTIONS/cellfun.cc |
diffstat | 2 files changed, 33 insertions(+), 17 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,9 @@ +2009-12-15 Jaroslav Hajek <highegg@gmail.com> + + * DLD-FUNCTIONS/cellfun.cc (Fcellfun): Preserve original nargout. Call + functions with this value. Use nargout1 to possibly accumulate extra + outputs, as long as they are defined. + 2009-12-14 Jaroslav Hajek <highegg@gmail.com> * ov-range.cc (octave_range::do_index_op): Defer single subscript to
--- a/src/DLD-FUNCTIONS/cellfun.cc +++ b/src/DLD-FUNCTIONS/cellfun.cc @@ -272,7 +272,7 @@ { octave_value_list retval; int nargin = args.length (); - nargout = (nargout < 1 ? 1 : nargout); + int nargout1 = (nargout < 1 ? 1 : nargout); if (nargin < 2) { @@ -509,7 +509,7 @@ if (uniform_output) { - OCTAVE_LOCAL_BUFFER (std::auto_ptr<scalar_col_helper>, retptr, nargout); + OCTAVE_LOCAL_BUFFER (std::auto_ptr<scalar_col_helper>, retptr, nargout1); for (octave_idx_type count = 0; count < k ; count++) { @@ -541,15 +541,20 @@ if (error_state) goto cellfun_err; - if (tmp.length() < nargout) + if (tmp.length () < nargout1) { - error ("cellfun: too many output arguments"); - goto cellfun_err; + if (tmp.length () < nargout) + { + error ("cellfun: too many output arguments"); + goto cellfun_err; + } + else + nargout1 = 0; } if (count == 0) { - for (int j = 0; j < nargout; j++) + for (int j = 0; j < nargout1; j++) { octave_value val = tmp(j); @@ -564,7 +569,7 @@ } else { - for (int j = 0; j < nargout; j++) + for (int j = 0; j < nargout1; j++) { octave_value val = tmp(j); @@ -583,8 +588,8 @@ break; } - retval.resize (nargout); - for (int j = 0; j < nargout; j++) + retval.resize (nargout1); + for (int j = 0; j < nargout1; j++) { if (retptr[j].get ()) retval(j) = retptr[j]->result (); @@ -594,8 +599,8 @@ } else { - OCTAVE_LOCAL_BUFFER (Cell, results, nargout); - for (int j = 0; j < nargout; j++) + OCTAVE_LOCAL_BUFFER (Cell, results, nargout1); + for (int j = 0; j < nargout1; j++) results[j].resize (fdims); for (octave_idx_type count = 0; count < k ; count++) @@ -628,19 +633,24 @@ if (error_state) goto cellfun_err; - if (tmp.length() < nargout) + if (tmp.length () < nargout1) { - error ("cellfun: too many output arguments"); - goto cellfun_err; + if (tmp.length () < nargout) + { + error ("cellfun: too many output arguments"); + goto cellfun_err; + } + else + nargout1 = 0; } - for (int j = 0; j < nargout; j++) + for (int j = 0; j < nargout1; j++) results[j](count) = tmp(j); } - retval.resize(nargout); - for (int j = 0; j < nargout; j++) + retval.resize(nargout1); + for (int j = 0; j < nargout1; j++) retval(j) = results[j]; }