diff libinterp/corefcn/stack-frame.cc @ 30723:08b08b7f05b2

Replace direct calls to C library assert() with Octave specialty functions in libinterp/ (bug #61753) Define 4 new inline functions in error.h (panic_if, panic_unless, error_if, error_unless) that call either assert() or Octave's own error() function. Replace calls to assert() in code that maintains state and for which no recovery on detection of a problem is possible with calls to panic_XXX. Replace calls to assert() in interpreter code which could simply return to the Octave prompt when a problem is detected with calls to error_XXX. * error.h (panic_if, panic_unless): New functions which eventually call can call assert(). panic_if (COND) calls assert if COND is true. panic_unless (COND) calls assert if COND is false. * error.h (error_if, error_unless): New functions which eventually call can call Octave's error() function. error_if (COND) calls assert if COND is true. error_unless (COND) calls assert if COND is false. * cellfun.cc, daspk.cc, dasrt.cc, dassl.cc, data.cc, dot.cc, error.cc, graphics.cc, kron.cc, mex.cc, oct-map.cc, oct-stream.cc, pr-output.cc, schur.cc, stack-frame.cc, typecast.cc, variables.cc, ov-base.cc, ov-class.cc, ov-fcn-handle.cc, ov-struct.cc, ov-usr-fcn.cc, ov.h, ovl.cc, ops.h, profiler.cc, pt-classdef.cc, pt-eval.cc, pt-idx.cc, pt-pr-code.cc, pt-tm-const.cc, token.cc: Replace direct calls to C library assert() with Octave specialty functions.
author Arun Giridhar <arungiridhar@gmail.com> and Rik <rik@octave.org>
date Mon, 07 Feb 2022 21:47:53 -0800
parents 83f9f8bda883
children e88a07dec498
line wrap: on
line diff
--- a/libinterp/corefcn/stack-frame.cc	Mon Feb 07 10:46:17 2022 +0900
+++ b/libinterp/corefcn/stack-frame.cc	Mon Feb 07 21:47:53 2022 -0800
@@ -31,6 +31,7 @@
 #include "str-vec.h"
 
 #include "defun.h"
+#include "error.h"
 #include "interpreter.h"
 #include "interpreter-private.h"
 #include "oct-map.h"
@@ -1603,7 +1604,7 @@
     // scope.  If the symbol wasn't present before, it should be outside
     // the range so we need to resize then update offsets.
 
-    assert (data_offset >= size ());
+    panic_unless (data_offset >= size ());
 
     resize (data_offset+1);
 
@@ -1654,7 +1655,7 @@
 
     if (sym)
       {
-        assert (sym.frame_offset () == 0);
+        panic_unless (sym.frame_offset () == 0);
 
         return sym;
       }
@@ -1683,7 +1684,7 @@
         // All symbol records in a script scope should have zero offset,
         // which means we redirect our lookup using
         // lexical_frame_offsets and values_offets.
-        assert (sym.frame_offset () == 0);
+        panic_unless (sym.frame_offset () == 0);
 
         return sym;
       }
@@ -1693,7 +1694,7 @@
 
     sym = scope.find_symbol (name);
 
-    assert (sym);
+    panic_unless (sym.is_valid ());
 
     resize_and_update_script_offsets (sym);
 
@@ -2104,7 +2105,7 @@
           {
             // FIXME: do we need to ensure that the called
             // function is a child of the caller?  Does it hurt
-            // to assert this condition, at least for now?
+            // to panic_unless this condition, at least for now?
 
             alink = static_link;
           }
@@ -2112,7 +2113,7 @@
           {
             // FIXME: do we need to check that the parent of the
             // called function is also a parent of the caller?
-            // Does it hurt to assert this condition, at least
+            // Does it hurt to panic_unless this condition, at least
             // for now?
 
             int links_to_follow = caller_nesting_depth - nesting_depth + 1;
@@ -2225,7 +2226,7 @@
 
     sym = scope.find_symbol (name);
 
-    assert (sym);
+    panic_unless (sym.is_valid ());
 
     return sym;
   }
@@ -2392,7 +2393,7 @@
 
     sym = m_scope.find_symbol (name);
 
-    assert (sym);
+    panic_unless (sym.is_valid ());
 
     return sym;
   }