diff libinterp/parse-tree/profiler.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 32d2b6604a9f
line wrap: on
line diff
--- a/libinterp/parse-tree/profiler.cc	Mon Feb 07 10:46:17 2022 +0900
+++ b/libinterp/parse-tree/profiler.cc	Mon Feb 07 21:47:53 2022 -0800
@@ -52,8 +52,6 @@
     for (const auto& nm : list)
       retval(i++) = nm;
 
-    assert (i == n);
-
     return retval;
   }
 
@@ -88,10 +86,10 @@
   profiler::tree_node*
   profiler::tree_node::exit (octave_idx_type /* fcn */)
   {
-    // FIXME: These assert statements don't make sense if profile() is called
-    //        from within a function hierarchy to begin with.  See bug #39587.
-    //  assert (m_parent);
-    //  assert (m_fcn_id == fcn);
+    // FIXME: These panic_unless statements don't make sense if profile() is
+    //  called from within a function hierarchy to begin with.  See bug #39587.
+    //  panic_unless (m_parent);
+    //  panic_unless (m_fcn_id == fcn);
 
     return m_parent;
   }
@@ -108,7 +106,7 @@
         entry.m_time += m_time;
         entry.m_calls += m_calls;
 
-        assert (m_parent);
+        panic_unless (m_parent);
         if (m_parent->m_fcn_id != 0)
           {
             entry.m_parents.insert (m_parent->m_fcn_id);
@@ -162,7 +160,6 @@
 
         ++i;
       }
-    assert (i == n);
 
     octave_map retval;
 
@@ -196,8 +193,8 @@
   profiler::enter_function (const std::string& fcn)
   {
     // The enter class will check and only call us if the profiler is active.
-    assert (enabled ());
-    assert (m_call_tree);
+    panic_unless (enabled ());
+    panic_unless (m_call_tree);
 
     // If there is already an active function, add to its time before
     // pushing the new one.
@@ -230,11 +227,11 @@
   {
     if (m_active_fcn)
       {
-        assert (m_call_tree);
-        // FIXME: This assert statements doesn't make sense if profile() is
-        // called from within a function hierarchy to begin with.  See bug
-        // #39587.
-        //assert (m_active_fcn != m_call_tree);
+        panic_unless (m_call_tree);
+        // FIXME: This panic_unless statements doesn't make sense if profile()
+        //        is called from within a function hierarchy to begin with.
+        //        See bug #39587.
+        // panic_unless (m_active_fcn != m_call_tree);
 
         // Usually, if we are disabled this function is not even called.  But
         // the call disabling the profiler is an exception.  So also check here
@@ -243,10 +240,10 @@
           add_current_time ();
 
         fcn_index_map::iterator pos = m_fcn_index.find (fcn);
-        // FIXME: This assert statements doesn't make sense if profile() is
-        // called from within a function hierarchy to begin with.  See bug
-        // #39587.
-        //assert (pos != m_fcn_index.end ());
+        // FIXME: This panic_unless statements doesn't make sense if profile()
+        //        is called from within a function hierarchy to begin with.
+        //        See bug #39587.
+        // panic_unless (pos != m_fcn_index.end ());
         m_active_fcn = m_active_fcn->exit (pos->second);
 
         // If this was an "inner call", we resume executing the parent function