changeset 20619:eef93a493ce3

use new cell_value method to handle value extraction errors * cellfun.cc, ov-class.cc, ov-struct.cc, ov-usr-fcn.cc: Use new cell_value method.
author John W. Eaton <jwe@octave.org>
date Fri, 09 Oct 2015 14:43:36 -0400
parents e5986cba4ca8
children e5f36a7854a5
files libinterp/corefcn/cellfun.cc libinterp/octave-value/ov-class.cc libinterp/octave-value/ov-struct.cc libinterp/octave-value/ov-usr-fcn.cc
diffstat 4 files changed, 18 insertions(+), 64 deletions(-) [+]
line wrap: on
line diff
--- a/libinterp/corefcn/cellfun.cc	Fri Oct 09 14:41:49 2015 -0400
+++ b/libinterp/corefcn/cellfun.cc	Fri Oct 09 14:43:36 2015 -0400
@@ -2463,26 +2463,21 @@
 
   if (args.length () >= 1)
     {
-      if (args(0).is_cell ())
-        {
-          const Cell x = args(0).cell_value ();
-          NoAlias<Cell> y(x.dims ());
-          octave_idx_type nel = x.numel ();
-          octave_value_list idx = args.slice (1, args.length () - 1);
+      const Cell x = args(0).cell_value ("cellindexmat: X must be a cell");
+      NoAlias<Cell> y(x.dims ());
+      octave_idx_type nel = x.numel ();
+      octave_value_list idx = args.slice (1, args.length () - 1);
 
-          for (octave_idx_type i = 0; i < nel; i++)
-            {
-              octave_quit ();
-
-              octave_value tmp = x(i);
+      for (octave_idx_type i = 0; i < nel; i++)
+        {
+          octave_quit ();
 
-              y(i) = tmp.do_index_op (idx);
-            }
+          octave_value tmp = x(i);
 
-          retval = y;
+          y(i) = tmp.do_index_op (idx);
         }
-      else
-        error ("cellindexmat: X must be a cell");
+
+      retval = y;
     }
   else
     print_usage ();
--- a/libinterp/octave-value/ov-class.cc	Fri Oct 09 14:41:49 2015 -0400
+++ b/libinterp/octave-value/ov-class.cc	Fri Oct 09 14:43:36 2015 -0400
@@ -1301,13 +1301,7 @@
                   if (! is)
                     break;
 
-                  Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
-
-                  if (error_state)
-                    {
-                      error ("load: internal error loading class elements");
-                      return false;
-                    }
+                  Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading class elements") : Cell (t2);
 
                   m.assign (nm, tcell);
                 }
@@ -1444,13 +1438,7 @@
           if (! is)
             break;
 
-          Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
-
-          if (error_state)
-            {
-              error ("load: internal error loading class elements");
-              return false;
-            }
+          Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading class elements") : Cell (t2);
 
           m.assign (nm, tcell);
         }
@@ -1684,13 +1672,7 @@
     {
       octave_value t2 = dsub.tc;
 
-      Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
-
-      if (error_state)
-        {
-          error ("load: internal error loading class elements");
-          return false;
-        }
+      Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading class elements") : Cell (t2);
 
       m.assign (dsub.name, tcell);
 
--- a/libinterp/octave-value/ov-struct.cc	Fri Oct 09 14:41:49 2015 -0400
+++ b/libinterp/octave-value/ov-struct.cc	Fri Oct 09 14:43:36 2015 -0400
@@ -799,13 +799,7 @@
               if (!is)
                 break;
 
-              Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
-
-              if (error_state)
-                {
-                  error ("load: internal error loading struct elements");
-                  return false;
-                }
+              Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading struct elements") : Cell (t2);
 
               m.setfield (nm, tcell);
             }
@@ -927,13 +921,7 @@
           if (!is)
             break;
 
-          Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
-
-          if (error_state)
-            {
-              error ("load: internal error loading struct elements");
-              return false;
-            }
+          Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading struct elements") : Cell (t2);
 
           m.setfield (nm, tcell);
         }
@@ -1030,13 +1018,7 @@
     {
       octave_value t2 = dsub.tc;
 
-      Cell tcell = t2.is_cell () ? t2.cell_value () : Cell (t2);
-
-      if (error_state)
-        {
-          error ("load: internal error loading struct elements");
-          return false;
-        }
+      Cell tcell = t2.is_cell () ? t2.cell_value ("load: internal error loading struct elements") : Cell (t2);
 
       m.setfield (dsub.name, tcell);
 
--- a/libinterp/octave-value/ov-usr-fcn.cc	Fri Oct 09 14:41:49 2015 -0400
+++ b/libinterp/octave-value/ov-usr-fcn.cc	Fri Oct 09 14:43:36 2015 -0400
@@ -635,12 +635,7 @@
           octave_value varargout_varval = symbol_table::varval ("varargout");
 
           if (varargout_varval.is_defined ())
-            {
-              varargout = varargout_varval.cell_value ();
-
-              if (error_state)
-                error ("expecting varargout to be a cell array object");
-            }
+            varargout = varargout_varval.cell_value ("expecting varargout to be a cell array object");
         }
 
       retval = ret_list->convert_to_const_vector (nargout, varargout);