Mercurial > hg > octave-lyh
changeset 14571:6131fead3135 stable
ensure isargout is not sticky
* ov-usr-fcn.cc (octave_user_function::bind_automatic_vars):
Ensure .ignored. is undefined by default. New tests.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Wed, 18 Apr 2012 14:21:34 -0400 |
parents | d07d96e53612 |
children | 000cd393f3c1 |
files | src/ov-usr-fcn.cc |
diffstat | 1 files changed, 43 insertions(+), 3 deletions(-) [+] |
line wrap: on
line diff
--- a/src/ov-usr-fcn.cc +++ b/src/ov-usr-fcn.cc @@ -598,6 +598,9 @@ if (takes_varargs ()) symbol_table::varref ("varargin") = va_args.cell_value (); + // Force .ignored. variable to be undefined by default. + symbol_table::varref (".ignored.") = octave_value (); + if (lvalue_list) { octave_idx_type nbh = 0; @@ -619,11 +622,11 @@ } symbol_table::varref (".ignored.") = bh; - - symbol_table::mark_hidden (".ignored."); - symbol_table::mark_automatic (".ignored."); } } + + symbol_table::mark_hidden (".ignored."); + symbol_table::mark_automatic (".ignored."); } DEFUN (nargin, args, , @@ -873,3 +876,40 @@ return retval; } + +/* +%!function [x, y] = try_isargout () +%! if (isargout (1)) +%! if (isargout (2)) +%! x = 1; y = 2; +%! else +%! x = -1; +%! endif +%! else +%! if (isargout (2)) +%! y = -2; +%! else +%! error ("no outputs requested"); +%! endif +%! endif +%!endfunction +%! +%!test +%! [x, y] = try_isargout (); +%! assert ([x, y], [1, 2]); +%! +%!test +%! [x, ~] = try_isargout (); +%! assert (x, -1); +%! +%!test +%! [~, y] = try_isargout (); +%! assert (y, -2); +%! +%!error [~, ~] = try_isargout (); +%! +%% Check to see that isargout isn't sticky: +%!test +%! [x, y] = try_isargout (); +%! assert ([x, y], [1, 2]); +*/