changeset 32782:ae45ab1e5d7c bytecode-interpreter

maint: merge default to bytecode-interpreter
author John W. Eaton <jwe@octave.org>
date Fri, 19 Jan 2024 09:38:36 -0500
parents d780af3b0e9f (current diff) 2348f7dec6b8 (diff)
children 298c18eb7645
files libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h test/Makefile.am
diffstat 5 files changed, 89 insertions(+), 27 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/parse-tree/oct-parse.yy	Thu Jan 18 20:15:21 2024 +0100
+++ b/libinterp/parse-tree/oct-parse.yy	Fri Jan 19 09:38:36 2024 -0500
@@ -5525,7 +5525,8 @@
     if (in_file)
       {
         output_buf << str
-                   << " near line " << err_line << ", column " << err_col << "\n";
+                   << " near line " << err_line << ", column " << err_col
+                   << " in file " << m_lexer.m_fcn_file_full_name << "\n";
       }
     else
       {
--- a/libinterp/parse-tree/pt-eval.cc	Thu Jan 18 20:15:21 2024 +0100
+++ b/libinterp/parse-tree/pt-eval.cc	Fri Jan 19 09:38:36 2024 -0500
@@ -2339,8 +2339,7 @@
 
 octave_value_list
 tree_evaluator::convert_return_list_to_const_vector
-  (tree_parameter_list *ret_list, int nargout, const Matrix& ignored_outputs,
-   const Cell& varargout)
+(tree_parameter_list *ret_list, int nargout, const Cell& varargout)
 {
   octave_idx_type vlen = varargout.numel ();
   int len = ret_list->length ();
@@ -2351,9 +2350,6 @@
   else
     {
       int i = 0;
-      int k = 0;
-      int num_ignored = ignored_outputs.numel ();
-      int ignored = num_ignored > 0 ? ignored_outputs(k) - 1 : -1;
 
       if (nargout <= len)
         {
@@ -2365,14 +2361,10 @@
               if (nargout == 0 && ! is_defined (elt->ident ()))
                 break;
 
-              if (ignored >= 0 && i == ignored)
-                {
-                  i++;
-                  k++;
-                  ignored = k < num_ignored ? ignored_outputs(k) - 1 : -1;
-                }
-              else
-                retval(i++) = evaluate (elt);
+              if (is_defined (elt->ident ()))
+                retval(i) = evaluate (elt);
+
+              i++;
 
               if (i == nout)
                 break;
@@ -2386,14 +2378,10 @@
 
           for (tree_decl_elt *elt : *ret_list)
             {
-              if (ignored >= 0 && i == ignored)
-                {
-                  i++;
-                  k++;
-                  ignored = k < num_ignored ? ignored_outputs(k) - 1 : -1;
-                }
-              else
-                retval(i++) = evaluate (elt);
+              if (is_defined (elt->ident ()))
+                retval(i) = evaluate (elt);
+
+              i++;
             }
 
           for (octave_idx_type j = 0; j < vlen; j++)
@@ -3748,9 +3736,7 @@
             varargout = varargout_varval.xcell_value ("varargout must be a cell array object");
         }
 
-      retval = convert_return_list_to_const_vector (ret_list, nargout,
-                                                    ignored_outputs,
-                                                    varargout);
+      retval = convert_return_list_to_const_vector (ret_list, nargout, varargout);
     }
 
   return retval;
--- a/libinterp/parse-tree/pt-eval.h	Thu Jan 18 20:15:21 2024 +0100
+++ b/libinterp/parse-tree/pt-eval.h	Fri Jan 19 09:38:36 2024 -0500
@@ -425,8 +425,7 @@
 
   octave_value_list
   convert_return_list_to_const_vector
-  (tree_parameter_list *ret_list, int nargout,
-   const Matrix& ignored_outputs, const Cell& varargout);
+  (tree_parameter_list *ret_list, int nargout, const Cell& varargout);
 
   bool eval_decl_elt (tree_decl_elt *elt);
 
--- a/test/Makefile.am	Thu Jan 18 20:15:21 2024 +0100
+++ b/test/Makefile.am	Fri Jan 19 09:38:36 2024 -0500
@@ -32,6 +32,7 @@
   bug-55322.tst \
   bug-59950.tst \
   bug-61201.tst \
+  bug-65153.tst \
   colormaps.tst \
   command.tst \
   complex.tst \
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/test/bug-65153.tst	Fri Jan 19 09:38:36 2024 -0500
@@ -0,0 +1,75 @@
+%!function retval = bug65153_flipud (x)
+%!  global bug65153_global_isargout
+%!  bug65153_global_isargout = isargout (1);
+%!  retval = flipud (x);
+%!endfunction
+
+## Bug 65153 revealed two problems related to the way Octave was
+## attempting to handle ignored function outputs.  One is that an
+## ignored output can propagate from one function to another in some
+## contexts.  For example, evaluating
+##
+##   [~, y] = bug65153_1 ()
+##
+## results in isargout(1) -> false in the call to bug65153_flipud.
+## The second problem is that even though the return value is always
+## set in bug65153_flipud, Octave was using the equivalent of the
+## isargout information internally and not assigning the return value
+## internally, so the matrix construction failed.  The second problem
+## is easier to solve than the first.  We test for each problem
+## separately here.
+
+%!function [x, y] = bug65153_1 ()
+%!  n = 10;
+%!  x = (1:n)';
+%!  y = (1:n)';
+%!  [(1:n)', bug65153_flipud((1:n)')];
+%!endfunction
+
+## The bug65153_2 function tests the same problem as bug65153_1 but for
+## a different context.  ANS should be assigned after the call to
+## bug65153_flipud but it was not because of Octave's incorrect internal
+## handling of ignored outputs.
+
+%!function x = bug65153_2 ()
+%!  global bug65153_global
+%!  bug65153_flipud ((1:10)');
+%!  x = ans;
+%!  bug65153_global = x;
+%!endfunction
+
+%!test <65153>
+%! global bug65153_global bug65153_global_isargout
+%! unwind_protect
+%!   [~, y] = bug65153_1 ();
+%!   assert (y, (1:10)');
+%! unwind_protect_cleanup
+%!   clear -global bug65153_global bug65153_global_isargout
+%! end_unwind_protect
+
+%!test <65153>
+%! global bug65153_global bug65153_global_isargout
+%! unwind_protect
+%!   [~, y] = bug65153_1 ();
+%!   assert (bug65153_global_isargout, true);
+%! unwind_protect_cleanup
+%!   clear -global bug65153_global bug65153_global_isargout
+%! end_unwind_protect
+
+%!test <65153>
+%! global bug65153_global bug65153_global_isargout
+%! unwind_protect
+%!   [~] = bug65153_2 ();
+%!   assert (bug65153_global, flipud ((1:10)'));
+%! unwind_protect_cleanup
+%!   clear -global bug65153_global bug65153_global_isargout
+%! end_unwind_protect
+
+%!test <65153>
+%! global bug65153_global bug65153_global_isargout
+%! unwind_protect
+%!   [~] = bug65153_2 ();
+%!   assert (bug65153_global_isargout, true);
+%! unwind_protect_cleanup
+%!   clear -global bug65153_global bug65153_global_isargout
+%! end_unwind_protect