changeset 29956:a956ca6698d2

move some error handling functions inside octave namespace * error.h, error.cc (defun_usage_message, set_warning_state, warning_enabled, disable_warning, interpreter_try): Move functions inside octave namespace. Deprecated global function names. Change uses as needed.
author John W. Eaton <jwe@octave.org>
date Sat, 14 Aug 2021 16:27:53 -0400
parents 693329e53f25
children 64e3ef97384e
files libinterp/corefcn/error.cc libinterp/corefcn/error.h libinterp/corefcn/graphics.cc libinterp/corefcn/interpreter.cc libinterp/corefcn/jsonencode.cc libinterp/octave-value/ov-class.cc libinterp/octave-value/ov-oncleanup.cc libinterp/parse-tree/pt-eval.cc libinterp/parse-tree/pt.cc
diffstat 9 files changed, 85 insertions(+), 29 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/error.cc	Sat Aug 14 15:47:41 2021 -0400
+++ b/libinterp/corefcn/error.cc	Sat Aug 14 16:27:53 2021 -0400
@@ -1051,13 +1051,6 @@
   va_end (args);
 }
 
-int warning_enabled (const std::string& id)
-{
-  octave::error_system& es = octave::__get_error_system__ ("warning_enabled");
-
-  return es.warning_enabled (id);
-}
-
 void
 vwarning (const char *fmt, va_list args)
 {
@@ -1137,12 +1130,16 @@
   va_end (args);
 }
 
+OCTAVE_NAMESPACE_BEGIN
+
 void
 defun_usage_message (const std::string& msg)
 {
-  defun_usage_message ("%s", msg.c_str ());
+  ::defun_usage_message ("%s", msg.c_str ());
 }
 
+OCTAVE_NAMESPACE_END
+
 DEFMETHOD (rethrow, interp, args, ,
            doc: /* -*- texinfo -*-
 @deftypefn {} {} rethrow (@var{err})
@@ -1819,6 +1816,8 @@
 
 */
 
+OCTAVE_NAMESPACE_BEGIN
+
 octave_value_list
 set_warning_state (const std::string& id, const std::string& state)
 {
@@ -1842,6 +1841,14 @@
   return Fwarning (interp, args, 1);
 }
 
+int
+warning_enabled (const std::string& id)
+{
+  octave::error_system& es = octave::__get_error_system__ ("warning_enabled");
+
+  return es.warning_enabled (id);
+}
+
 void
 disable_warning (const std::string& id)
 {
@@ -1850,6 +1857,8 @@
   es.disable_warning (id);
 }
 
+OCTAVE_NAMESPACE_END
+
 DEFMETHOD (lasterror, interp, args, ,
            doc: /* -*- texinfo -*-
 @deftypefn  {} {@var{lasterr} =} lasterror ()
@@ -2176,6 +2185,8 @@
   return es.debug_on_warning (args, nargout);
 }
 
+OCTAVE_NAMESPACE_BEGIN
+
 void
 interpreter_try (octave::unwind_protect& frame)
 {
@@ -2185,6 +2196,8 @@
   es.interpreter_try (frame);
 }
 
+OCTAVE_NAMESPACE_END
+
 // Deprecated variables and functions.
 
 // This variable is obsolete and always has the value 0.
--- a/libinterp/corefcn/error.h	Sat Aug 14 15:47:41 2021 -0400
+++ b/libinterp/corefcn/error.h	Sat Aug 14 16:27:53 2021 -0400
@@ -412,8 +412,6 @@
 #define panic_impossible()                                              \
   panic ("impossible state reached in file '%s' at line %d", __FILE__, __LINE__)
 
-extern OCTINTERP_API int warning_enabled (const std::string& id);
-
 extern OCTINTERP_API void
 vmessage (const char *name, const char *fmt, va_list args);
 
@@ -509,21 +507,66 @@
 OCTAVE_NORETURN
 extern OCTINTERP_API void panic (const char *fmt, ...);
 
+OCTAVE_NAMESPACE_BEGIN
+
 //! Helper function for print_usage defined in defun.cc.
 
 extern OCTINTERP_API void defun_usage_message (const std::string& msg);
 
+// Convenience functions.
+
 extern OCTINTERP_API octave_value_list
 set_warning_state (const std::string& id, const std::string& state);
 
 extern OCTINTERP_API octave_value_list
 set_warning_state (const octave_value_list& args);
 
+extern OCTINTERP_API int warning_enabled (const std::string& id);
+
 extern OCTINTERP_API void disable_warning (const std::string& id);
 
 extern OCTINTERP_API void interpreter_try (octave::unwind_protect&);
 
+OCTAVE_NAMESPACE_END
+
 #if defined (OCTAVE_PROVIDE_DEPRECATED_SYMBOLS)
+OCTAVE_DEPRECATED (7, "use 'octave::defun_usage_message' instead")
+inline void defun_usage_message (const std::string& msg)
+{
+  octave::defun_usage_message (msg);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::set_warning_state' instead")
+inline octave_value_list
+set_warning_state (const std::string& id, const std::string& state)
+{
+  return octave::set_warning_state (id, state);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::set_warning_state' instead")
+inline octave_value_list set_warning_state (const octave_value_list& args)
+{
+  return octave::set_warning_state (args);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::warning_enabled' instead")
+extern OCTINTERP_API int warning_enabled (const std::string& id)
+{
+  return octave::warning_enabled (id);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::disable_warning' instead")
+inline void disable_warning (const std::string& id)
+{
+  octave::disable_warning (id);
+}
+
+OCTAVE_DEPRECATED (7, "use 'octave::interpreter_try' instead")
+inline void interpreter_try (octave::unwind_protect& uwp)
+{
+  octave::interpreter_try (uwp);
+}
+
 OCTAVE_DEPRECATED (6, "this variable is obsolete and always has the value 0")
 extern OCTINTERP_API int error_state;
 
--- a/libinterp/corefcn/graphics.cc	Sat Aug 14 15:47:41 2021 -0400
+++ b/libinterp/corefcn/graphics.cc	Sat Aug 14 16:27:53 2021 -0400
@@ -3243,15 +3243,15 @@
 {
   if (! on)
     {
-      state = warning_enabled (id);
-      disable_warning (id);
+      state = octave::warning_enabled (id);
+      octave::disable_warning (id);
     }
   else
     {
       if (state == 1)
-        set_warning_state (id, "on");
+        octave::set_warning_state (id, "on");
       else if (state == 2)
-        set_warning_state (id, "error");
+        octave::set_warning_state (id, "error");
     }
   return state;
 }
@@ -3757,7 +3757,7 @@
 
       octave::unwind_protect frame;
 
-      interpreter_try (frame);
+      octave::interpreter_try (frame);
 
       try
         {
--- a/libinterp/corefcn/interpreter.cc	Sat Aug 14 15:47:41 2021 -0400
+++ b/libinterp/corefcn/interpreter.cc	Sat Aug 14 16:27:53 2021 -0400
@@ -2035,12 +2035,12 @@
     Fprint_struct_array_contents (octave_value (true));
     Fstruct_levels_to_print (octave_value (0));
 
-    disable_warning ("Octave:abbreviated-property-match");
-    disable_warning ("Octave:colon-nonscalar-argument");
-    disable_warning ("Octave:data-file-in-path");
-    disable_warning ("Octave:empty-index");
-    disable_warning ("Octave:function-name-clash");
-    disable_warning ("Octave:possible-matlab-short-circuit-operator");
+    m_error_system.disable_warning ("Octave:abbreviated-property-match");
+    m_error_system.disable_warning ("Octave:colon-nonscalar-argument");
+    m_error_system.disable_warning ("Octave:data-file-in-path");
+    m_error_system.disable_warning ("Octave:empty-index");
+    m_error_system.disable_warning ("Octave:function-name-clash");
+    m_error_system.disable_warning ("Octave:possible-matlab-short-circuit-operator");
   }
 
   void interpreter::execute_pkg_add (const std::string& dir)
--- a/libinterp/corefcn/jsonencode.cc	Sat Aug 14 15:47:41 2021 -0400
+++ b/libinterp/corefcn/jsonencode.cc	Sat Aug 14 16:27:53 2021 -0400
@@ -420,8 +420,8 @@
       octave::unwind_action restore_warning_state
         ([] (const octave_value_list& old_warning_state)
          {
-           set_warning_state (old_warning_state);
-         }, set_warning_state ("Octave:classdef-to-struct", "off"));
+           octave::set_warning_state (old_warning_state);
+         }, octave::set_warning_state ("Octave:classdef-to-struct", "off"));
 
       encode_struct (writer, obj.scalar_map_value ().getfield ("map"),
                      ConvertInfAndNaN);
@@ -431,8 +431,8 @@
       octave::unwind_action restore_warning_state
         ([] (const octave_value_list& old_warning_state)
          {
-           set_warning_state (old_warning_state);
-         }, set_warning_state ("Octave:classdef-to-struct", "off"));
+           octave::set_warning_state (old_warning_state);
+         }, octave::set_warning_state ("Octave:classdef-to-struct", "off"));
 
       encode_struct (writer, obj.scalar_map_value (), ConvertInfAndNaN);
     }
--- a/libinterp/octave-value/ov-class.cc	Sat Aug 14 15:47:41 2021 -0400
+++ b/libinterp/octave-value/ov-class.cc	Sat Aug 14 16:27:53 2021 -0400
@@ -1077,7 +1077,7 @@
 
           // Simulate try/catch.
 
-          interpreter_try (frame);
+          octave::interpreter_try (frame);
 
           bool execution_error = false;
 
--- a/libinterp/octave-value/ov-oncleanup.cc	Sat Aug 14 15:47:41 2021 -0400
+++ b/libinterp/octave-value/ov-oncleanup.cc	Sat Aug 14 16:27:53 2021 -0400
@@ -167,7 +167,7 @@
   octave::interpreter& interp
     = octave::__get_interpreter__ ("octave_oncleanup::call_object_destructor");
 
-  interpreter_try (frame);
+  octave::interpreter_try (frame);
 
   try
     {
--- a/libinterp/parse-tree/pt-eval.cc	Sat Aug 14 15:47:41 2021 -0400
+++ b/libinterp/parse-tree/pt-eval.cc	Sat Aug 14 16:27:53 2021 -0400
@@ -3946,7 +3946,7 @@
 
         unwind_protect frame;
 
-        interpreter_try (frame);
+        octave::interpreter_try (frame);
 
         // The catch code is *not* added to unwind_protect stack; it
         // doesn't need to be run on interrupts.
--- a/libinterp/parse-tree/pt.cc	Sat Aug 14 15:47:41 2021 -0400
+++ b/libinterp/parse-tree/pt.cc	Sat Aug 14 16:27:53 2021 -0400
@@ -72,7 +72,7 @@
 
         unwind_protect frame;
 
-        interpreter_try (frame);
+        octave::interpreter_try (frame);
 
         retval = true;                // default to stopping if any error
         try