changeset 5052:c6ef19da4b24

[project @ 2004-10-19 18:40:48 by jwe]
author jwe
date Tue, 19 Oct 2004 18:40:48 +0000
parents cab27aa905c4
children c08cb1098afc
files liboctave/Array.cc liboctave/ChangeLog
diffstat 2 files changed, 21 insertions(+), 10 deletions(-) [+]
line wrap: on
line diff
--- a/liboctave/Array.cc	Tue Oct 19 15:29:15 2004 +0000
+++ b/liboctave/Array.cc	Tue Oct 19 18:40:48 2004 +0000
@@ -2940,7 +2940,9 @@
 
       if (n_idx < lhs_dims_len)
 	{
-	  // Collapse dimensions beyond last index.
+	  // Collapse dimensions beyond last index.  Note that we
+	  // delay resizing LHS until we know that the assignment will
+	  // succeed.
 
 	  if (liboctave_wfi_flag && ! (idx(n_idx-1).is_colon ()))
 	    (*current_liboctave_warning_handler)
@@ -2951,10 +2953,6 @@
 
 	  lhs_dims.resize (n_idx);
 
-	  lhs.resize (lhs_dims);
-
-	  lhs_dims = lhs.dims ();
-
 	  lhs_dims_len = lhs_dims.length ();
 	}
 
@@ -3010,6 +3008,11 @@
 	    }
 	  else
 	    {
+	      // Determine final dimensions for LHS and reset the
+	      // current size of the LHS.  Note that we delay actually
+	      // resizing LHS until we know that the assignment will
+	      // succeed.
+
 	      if (n_idx < orig_lhs_dims_len)
 		{
 		  for (int i = 0; i < n_idx-1; i++)
@@ -3018,9 +3021,7 @@
 	      else
 		final_lhs_dims = new_dims;
 
-	      lhs.resize_and_fill (new_dims, rfv);
-
-	      lhs_dims = lhs.dims ();
+	      lhs_dims = new_dims;
 
 	      lhs_dims_len = lhs_dims.length ();
 
@@ -3028,6 +3029,8 @@
 
 	      if (rhs_is_scalar)
 		{
+		  lhs.resize_and_fill (new_dims, rfv);
+
 		  if  (! final_lhs_dims.any_zero ())
 		    {
 		      int n = Array<LT>::get_size (frozen_len);
@@ -3085,6 +3088,8 @@
 		    }
 		  else
 		    {
+		      lhs.resize_and_fill (new_dims, rfv);
+
 		      if  (! final_lhs_dims.any_zero ())
 			{
 			  int n = Array<LT>::get_size (frozen_len);
@@ -3105,10 +3110,12 @@
 	    }
 	}
 
-      lhs.resize (final_lhs_dims);
+      if (retval != 0)
+	lhs.resize (final_lhs_dims);
     }
 
-  lhs.chop_trailing_singletons ();
+  if (retval != 0)
+    lhs.chop_trailing_singletons ();
 
   lhs.clear_index ();
 
--- a/liboctave/ChangeLog	Tue Oct 19 15:29:15 2004 +0000
+++ b/liboctave/ChangeLog	Tue Oct 19 18:40:48 2004 +0000
@@ -1,3 +1,7 @@
+2004-10-19  John W. Eaton  <jwe@octave.org>
+
+	* Array.cc (assignN): Avoid resizing if assignment will fail.
+
 2004-10-18  John W. Eaton  <jwe@octave.org>
 
 	* Array.cc (assign2): Save result of squeeze operation.