comparison src/ov-usr-fcn.cc @ 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 72c96de7a403
children 1c0f0e8f9a1b
comparison
equal deleted inserted replaced
14570:d07d96e53612 14571:6131fead3135
596 symbol_table::mark_automatic (".nargout."); 596 symbol_table::mark_automatic (".nargout.");
597 597
598 if (takes_varargs ()) 598 if (takes_varargs ())
599 symbol_table::varref ("varargin") = va_args.cell_value (); 599 symbol_table::varref ("varargin") = va_args.cell_value ();
600 600
601 // Force .ignored. variable to be undefined by default.
602 symbol_table::varref (".ignored.") = octave_value ();
603
601 if (lvalue_list) 604 if (lvalue_list)
602 { 605 {
603 octave_idx_type nbh = 0; 606 octave_idx_type nbh = 0;
604 for (std::list<octave_lvalue>::const_iterator p = lvalue_list->begin (); 607 for (std::list<octave_lvalue>::const_iterator p = lvalue_list->begin ();
605 p != lvalue_list->end (); p++) 608 p != lvalue_list->end (); p++)
617 bh(l++) = k+1; 620 bh(l++) = k+1;
618 k += p->numel (); 621 k += p->numel ();
619 } 622 }
620 623
621 symbol_table::varref (".ignored.") = bh; 624 symbol_table::varref (".ignored.") = bh;
622
623 symbol_table::mark_hidden (".ignored.");
624 symbol_table::mark_automatic (".ignored.");
625 } 625 }
626 } 626 }
627
628 symbol_table::mark_hidden (".ignored.");
629 symbol_table::mark_automatic (".ignored.");
627 } 630 }
628 631
629 DEFUN (nargin, args, , 632 DEFUN (nargin, args, ,
630 "-*- texinfo -*-\n\ 633 "-*- texinfo -*-\n\
631 @deftypefn {Built-in Function} {} nargin ()\n\ 634 @deftypefn {Built-in Function} {} nargin ()\n\
871 else 874 else
872 print_usage (); 875 print_usage ();
873 876
874 return retval; 877 return retval;
875 } 878 }
879
880 /*
881 %!function [x, y] = try_isargout ()
882 %! if (isargout (1))
883 %! if (isargout (2))
884 %! x = 1; y = 2;
885 %! else
886 %! x = -1;
887 %! endif
888 %! else
889 %! if (isargout (2))
890 %! y = -2;
891 %! else
892 %! error ("no outputs requested");
893 %! endif
894 %! endif
895 %!endfunction
896 %!
897 %!test
898 %! [x, y] = try_isargout ();
899 %! assert ([x, y], [1, 2]);
900 %!
901 %!test
902 %! [x, ~] = try_isargout ();
903 %! assert (x, -1);
904 %!
905 %!test
906 %! [~, y] = try_isargout ();
907 %! assert (y, -2);
908 %!
909 %!error [~, ~] = try_isargout ();
910 %!
911 %% Check to see that isargout isn't sticky:
912 %!test
913 %! [x, y] = try_isargout ();
914 %! assert ([x, y], [1, 2]);
915 */