changeset 30666:8c6486ffc1d9 stable

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.
author John W. Eaton <jwe@octave.org>
date Wed, 19 Jan 2022 09:28:18 -0800
parents 27566803b3b1
children f3e5f531e6b2 7a9d358fb66d
files libinterp/corefcn/error.cc test/error.tst
diffstat 2 files changed, 22 insertions(+), 26 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/error.cc	Sat Jan 22 11:25:04 2022 +0100
+++ b/libinterp/corefcn/error.cc	Wed Jan 19 09:28:18 2022 -0800
@@ -380,8 +380,6 @@
     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 @@
         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 @@
     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 @@
       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 @@
 
     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);
   }
--- a/test/error.tst	Sat Jan 22 11:25:04 2022 +0100
+++ b/test/error.tst	Wed Jan 19 09:28:18 2022 -0800
@@ -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