Mercurial > octave
changeset 32781:2348f7dec6b8
maint: merge stable to default
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 19 Jan 2024 09:36:49 -0500 |
parents | dd46b69b0330 (current diff) e96e2f9f9f37 (diff) |
children | ae45ab1e5d7c ac661cacb725 |
files | libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt-eval.h test/Makefile.am |
diffstat | 4 files changed, 87 insertions(+), 26 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/pt-eval.cc Thu Jan 18 14:43:19 2024 -0800 +++ b/libinterp/parse-tree/pt-eval.cc Fri Jan 19 09:36:49 2024 -0500 @@ -2341,8 +2341,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 (); @@ -2353,9 +2352,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) { @@ -2367,14 +2363,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; @@ -2388,14 +2380,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++) @@ -3720,9 +3708,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 14:43:19 2024 -0800 +++ b/libinterp/parse-tree/pt-eval.h Fri Jan 19 09:36:49 2024 -0500 @@ -412,8 +412,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 14:43:19 2024 -0800 +++ b/test/Makefile.am Fri Jan 19 09:36:49 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:36:49 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