# HG changeset patch # User John W. Eaton # Date 1642613298 28800 # Wed Jan 19 09:28:18 2022 -0800 # Branch stable # Node ID c148b7147af0d2b35ad6c2f1820f0f8b92b9254e # Parent ac74380e9d463ebd24213487c6b112c2f0011b36 Fix error in rethrow with anonymous functions (bug #61841). Always set column field in debug stack frame struct. * error.cc (make_stack_map): Delete "have_column" variable. Always add "column" to debug stack frame. * error.cc (make_stack_frame_list): Delete "have_column" variable. Always extract Cell from "column" field of octave_map. Always return column.int_value () for each stack frame. (error_system::rethrow_error): Ensure that stack structure array has "column" field. * error.tst: Update rethrow test for user-defined stack struct array. diff --git a/libinterp/corefcn/error.cc b/libinterp/corefcn/error.cc --- a/libinterp/corefcn/error.cc +++ b/libinterp/corefcn/error.cc @@ -380,8 +380,6 @@ OCTAVE_NAMESPACE_BEGIN Cell& line = retval.contents (2); Cell& column = retval.contents (3); - bool have_column = false; - octave_idx_type k = 0; for (const auto& frm : frames) @@ -389,19 +387,11 @@ OCTAVE_NAMESPACE_BEGIN file(k) = frm.file_name (); name(k) = frm.fcn_name (); line(k) = frm.line (); - int c = frm.column (); - if (c > 0) - { - have_column = true; - column(k) = c; - } + column(k) = frm.column (); k++; } - if (! have_column) - retval.rmfield ("column"); - return retval; } @@ -413,13 +403,7 @@ OCTAVE_NAMESPACE_BEGIN Cell file = stack.contents ("file"); Cell name = stack.contents ("name"); Cell line = stack.contents ("line"); - Cell column; - bool have_column = false; - if (stack.contains ("column")) - { - have_column = true; - column = stack.contents ("column"); - } + Cell column = stack.contents ("column"); octave_idx_type nel = name.numel (); @@ -427,8 +411,7 @@ OCTAVE_NAMESPACE_BEGIN frames.push_back (frame_info (file(i).string_value (), name(i).string_value (), line(i).int_value (), - (have_column - ? column(i).int_value () : -1))); + column(i).int_value ())); return frames; } @@ -619,13 +602,23 @@ OCTAVE_NAMESPACE_BEGIN execution_exception ee ("error", id, msg, stack_info); - if (! stack.isempty () - && ! (stack.contains ("file") && stack.contains ("name") - && stack.contains ("line"))) - error ("rethrow: STACK struct must contain the fields 'file', 'name', and 'line'"); + if (! stack.isempty ()) + { + if (! (stack.contains ("file") && stack.contains ("name") + && stack.contains ("line"))) + error ("rethrow: STACK struct must contain the fields 'file', 'name', and 'line'"); - if (! stack.isempty ()) - ee.set_stack_info (make_stack_frame_list (stack)); + if (! stack.contains ("column")) + { + octave_map new_stack = stack; + + new_stack.setfield ("column", Cell (octave_value (-1))); + + ee.set_stack_info (make_stack_frame_list (new_stack)); + } + else + ee.set_stack_info (make_stack_frame_list (stack)); + } throw_error (ee); } diff --git a/test/error.tst b/test/error.tst --- a/test/error.tst +++ b/test/error.tst @@ -123,6 +123,9 @@ %! struct ("file", "foo.m", "name", "foo", "line", 13)); %! rethrow (y); %! catch +%! stk = y.stack; +%! [stk.column] = deal (-1); +%! y.stack = stk; %! assert (y, lasterror ()); %! end_try_catch %! end_try_catch