changeset 20708:a2a99aaf680b

eliminate more uses of error_state * lsode.cc, quad.cc, toplev.cc, utils.cc, ov-cell.cc: Eliminate more uses of error state.
author John W. Eaton <jwe@octave.org>
date Tue, 17 Nov 2015 11:46:22 -0500
parents 453fca9ae397
children 73800f39da6f
files libinterp/corefcn/lsode.cc libinterp/corefcn/quad.cc libinterp/corefcn/toplev.cc libinterp/corefcn/utils.cc libinterp/octave-value/ov-cell.cc test/system.tst
diffstat 6 files changed, 33 insertions(+), 125 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/lsode.cc
+++ b/libinterp/corefcn/lsode.cc
@@ -137,25 +137,6 @@
   return retval;
 }
 
-#define LSODE_ABORT() \
-  return retval
-
-#define LSODE_ABORT1(msg) \
-  do \
-    { \
-      error ("lsode: " msg); \
-      LSODE_ABORT (); \
-    } \
-  while (0)
-
-#define LSODE_ABORT2(fmt, arg) \
-  do \
-    { \
-      error ("lsode: " fmt, arg); \
-      LSODE_ABORT (); \
-    } \
-  while (0)
-
 DEFUN (lsode, args, nargout,
        "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {[@var{x}, @var{istate}, @var{msg}] =} lsode (@var{fcn}, @var{x_0}, @var{t})\n\
@@ -285,7 +266,7 @@
   call_depth++;
 
   if (call_depth > 1)
-    LSODE_ABORT1 ("invalid recursive call");
+    error ("lsode: invalid recursive call");
 
   int nargin = args.length ();
 
@@ -339,7 +320,7 @@
                 }
             }
           else
-            LSODE_ABORT1 ("incorrect number of elements in cell array");
+            error ("lsode: incorrect number of elements in cell array");
         }
 
       if (!lsode_fcn && ! f_arg.is_cell ())
@@ -395,34 +376,23 @@
                   break;
 
                 default:
-                  LSODE_ABORT1
-                  ("first arg should be a string or 2-element string array");
+                  error ("lsode: first arg should be a string or 2-element string array");
                 }
             }
         }
 
-      if (error_state || ! lsode_fcn)
-        LSODE_ABORT ();
-
-      ColumnVector state (args(1).vector_value ());
+      if (! lsode_fcn)
+        error ("lsode: FCN argument is not a valid function name or handle");
 
-      if (error_state)
-        LSODE_ABORT1 ("expecting state vector as second argument");
-
-      ColumnVector out_times (args(2).vector_value ());
-
-      if (error_state)
-        LSODE_ABORT1 ("expecting output time vector as third argument");
+      ColumnVector state = args(1).xvector_value ("lsode: expecting state vector as second argument");
+      ColumnVector out_times = args(2).xvector_value ("lsode: expecting output time vector as third argument");
 
       ColumnVector crit_times;
 
       int crit_times_set = 0;
       if (nargin > 3)
         {
-          crit_times = ColumnVector (args(3).vector_value ());
-
-          if (error_state)
-            LSODE_ABORT1 ("expecting critical time vector as fourth argument");
+          crit_times = args(3).xvector_value ("lsode: expecting critical time vector as fourth argument");
 
           crit_times_set = 1;
         }
--- a/libinterp/corefcn/quad.cc
+++ b/libinterp/corefcn/quad.cc
@@ -147,31 +147,6 @@
   return retval;
 }
 
-#define QUAD_ABORT() \
-  do \
-    { \
-      if (fcn_name.length ()) \
-        clear_function (fcn_name); \
-      return retval; \
-    } \
-  while (0)
-
-#define QUAD_ABORT1(msg) \
-  do \
-    { \
-      error ("quad: " msg); \
-      QUAD_ABORT (); \
-    } \
-  while (0)
-
-#define QUAD_ABORT2(fmt, arg) \
-  do \
-    { \
-      error ("quad: " fmt, arg); \
-      QUAD_ABORT (); \
-    } \
-  while (0)
-
 DEFUN (quad, args, nargout,
        "-*- texinfo -*-\n\
 @deftypefn  {Built-in Function} {@var{q} =} quad (@var{f}, @var{a}, @var{b})\n\
@@ -230,7 +205,7 @@
   call_depth++;
 
   if (call_depth > 1)
-    QUAD_ABORT1 ("invalid recursive call");
+    error ("quad: invalid recursive call");
 
   int nargin = args.length ();
 
@@ -246,22 +221,16 @@
           fname.append ("(x) y = ");
           quad_fcn = extract_function (args(0), "quad", fcn_name, fname,
                                        "; endfunction");
+          frame.add_fcn (clear_function, fcn_name);
         }
 
       if (! quad_fcn)
-        QUAD_ABORT ();
+        error ("quad: FCN argument is not a valid function name or handle");
 
       if (args(1).is_single_type () || args(2).is_single_type ())
         {
-          float a = args(1).float_value ();
-
-          if (error_state)
-            QUAD_ABORT1 ("expecting second argument to be a scalar");
-
-          float b = args(2).float_value ();
-
-          if (error_state)
-            QUAD_ABORT1 ("expecting third argument to be a scalar");
+          float a = args(1).xfloat_value ("quad: expecting second argument to be a scalar");
+          float b = args(2).xfloat_value ("quad: expecting third argument to be a scalar");
 
           int indefinite = 0;
           FloatIndefQuad::IntegralType indef_type
@@ -297,20 +266,14 @@
             {
             case 5:
               if (indefinite)
-                QUAD_ABORT1 ("singularities not allowed on infinite intervals");
+                error ("quad: singularities not allowed on infinite intervals");
 
               have_sing = true;
 
-              sing = FloatColumnVector (args(4).float_vector_value ());
-
-              if (error_state)
-                QUAD_ABORT1 ("expecting vector of singularities as fourth argument");
+              sing = args(4).xfloat_vector_value ("quad: expecting vector of singularities as fourth argument");
 
             case 4:
-              tol = FloatColumnVector (args(3).float_vector_value ());
-
-              if (error_state)
-                QUAD_ABORT1 ("expecting vector of tolerances as fifth argument");
+              tol = args(3).xfloat_vector_value ("quad: expecting vector of tolerances as fifth argument");
 
               switch (tol.numel ())
                 {
@@ -322,7 +285,7 @@
                   break;
 
                 default:
-                  QUAD_ABORT1 ("expecting tol to contain no more than two values");
+                  error ("quad: expecting tol to contain no more than two values");
                 }
 
             case 3:
@@ -363,15 +326,8 @@
         }
       else
         {
-          double a = args(1).double_value ();
-
-          if (error_state)
-            QUAD_ABORT1 ("expecting second argument to be a scalar");
-
-          double b = args(2).double_value ();
-
-          if (error_state)
-            QUAD_ABORT1 ("expecting third argument to be a scalar");
+          double a = args(1).xdouble_value ("quad: expecting second argument to be a scalar");
+          double b = args(2).xdouble_value ("quad: expecting third argument to be a scalar");
 
           int indefinite = 0;
           IndefQuad::IntegralType indef_type = IndefQuad::doubly_infinite;
@@ -406,20 +362,14 @@
             {
             case 5:
               if (indefinite)
-                QUAD_ABORT1 ("singularities not allowed on infinite intervals");
+                error ("quad: singularities not allowed on infinite intervals");
 
               have_sing = true;
 
-              sing = ColumnVector (args(4).vector_value ());
-
-              if (error_state)
-                QUAD_ABORT1 ("expecting vector of singularities as fourth argument");
+              sing = args(4).vector_value ("quad: expecting vector of singularities as fourth argument");
 
             case 4:
-              tol = ColumnVector (args(3).vector_value ());
-
-              if (error_state)
-                QUAD_ABORT1 ("expecting vector of tolerances as fifth argument");
+              tol = args(3).xvector_value ("quad: expecting vector of tolerances as fifth argument");
 
               switch (tol.numel ())
                 {
@@ -431,7 +381,7 @@
                   break;
 
                 default:
-                  QUAD_ABORT1 ("expecting tol to contain no more than two values");
+                  error ("quad: expecting tol to contain no more than two values");
                 }
 
             case 3:
--- a/libinterp/corefcn/toplev.cc
+++ b/libinterp/corefcn/toplev.cc
@@ -1228,12 +1228,7 @@
       bool add_mode = true;
 
       if (nargin == 2)
-        {
-          add_mode = args(1).bool_value ();
-
-          if (error_state)
-            error ("atexit: FLAG argument must be a logical value");
-        }
+        add_mode = args(1).xbool_value ("atexit: FLAG argument must be a logical value");
 
       if (add_mode)
         octave_add_atexit_function (arg);
--- a/libinterp/corefcn/utils.cc
+++ b/libinterp/corefcn/utils.cc
@@ -323,13 +323,13 @@
               octave_env::make_absolute (load_path::find_first_of (names));
           else if (nargin == 2)
             {
-              std::string opt = args(1).string_value ();
+              std::string opt = args(1).xstring_value ("file_in_loadpath: expecting option to be a string");
 
-              if (! error_state && opt == "all")
+              if (opt == "all")
                 retval = Cell (make_absolute
                                (load_path::find_all_first_of (names)));
               else
-                error ("file_in_loadpath: invalid option");
+                error ("file_in_loadpath: invalid option `%s'", opt.c_str ());
             }
         }
       else
@@ -403,13 +403,13 @@
             retval = search_path_for_file (path, names);
           else if (nargin == 3)
             {
-              std::string opt = args(2).string_value ();
+              std::string opt = args(2).xstring_value ("file_in_path: expecting option to be a string");
 
-              if (! error_state && opt == "all")
+              if (opt == "all")
                 retval = Cell (make_absolute
                                (search_path_for_all_files (path, names)));
               else
-                error ("file_in_path: invalid option");
+                error ("file_in_path: invalid option `%s'", opt.c_str ());
             }
         }
       else
--- a/libinterp/octave-value/ov-cell.cc
+++ b/libinterp/octave-value/ov-cell.cc
@@ -1299,15 +1299,8 @@
         dims.resize (nargin);
 
         for (int i = 0; i < nargin; i++)
-          {
-            dims(i) = args(i).is_empty () ? 0 : args(i).nint_value ();
-
-            if (error_state)
-              {
-                error ("cell: expecting scalar arguments");
-                break;
-              }
-          }
+          dims(i) = (args(i).is_empty ()
+                     ? 0 : args(i).xnint_value ("cell: expecting scalar arguments"));
       }
       break;
     }
--- a/test/system.tst
+++ b/test/system.tst
@@ -225,7 +225,7 @@
 
 %!assert (ischar (file_in_path (path (), "date.m")))
 
-%!error <invalid option> file_in_path ("foo", "bar", 1)
+%!error <file_in_path: expecting option to be a string> file_in_path ("foo", "bar", 1)
 %!error <Invalid call to file_in_path> file_in_path ()
 %!error <Invalid call to file_in_path> file_in_path ("foo", "bar", "baz", "ooka")