# HG changeset patch # User Jaroslav Hajek # Date 1260878825 -3600 # Node ID 76cf4aec34e9d955997cdfadfac6be044b0c1b7d # Parent bb30843c49291763758539af81bcff5eebc23b77 allow functions returning no value in cellfun diff -r bb30843c4929 -r 76cf4aec34e9 src/ChangeLog --- a/src/ChangeLog Tue Dec 15 10:05:38 2009 +0100 +++ b/src/ChangeLog Tue Dec 15 13:07:05 2009 +0100 @@ -1,3 +1,9 @@ +2009-12-15 Jaroslav Hajek + + * 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 * ov-range.cc (octave_range::do_index_op): Defer single subscript to diff -r bb30843c4929 -r 76cf4aec34e9 src/DLD-FUNCTIONS/cellfun.cc --- a/src/DLD-FUNCTIONS/cellfun.cc Tue Dec 15 10:05:38 2009 +0100 +++ b/src/DLD-FUNCTIONS/cellfun.cc Tue Dec 15 13:07:05 2009 +0100 @@ -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, retptr, nargout); + OCTAVE_LOCAL_BUFFER (std::auto_ptr, 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]; }