dotgnu-pnet-commits
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Dotgnu-pnet-commits] CVS: pnetlib/runtime/System Array.cs,1.19,1.20 Co


From: Rhys Weatherley <address@hidden>
Subject: [Dotgnu-pnet-commits] CVS: pnetlib/runtime/System Array.cs,1.19,1.20 Convert.cs,1.9,1.10
Date: Mon, 14 Apr 2003 21:05:29 -0400

Update of /cvsroot/dotgnu-pnet/pnetlib/runtime/System
In directory subversions:/tmp/cvs-serv24039/runtime/System

Modified Files:
        Array.cs Convert.cs 
Log Message:


Test cases and bug fixes for "Array.Copy"; implement primitive type
conversions in ECMA_COMPAT mode.


Index: Array.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Array.cs,v
retrieving revision 1.19
retrieving revision 1.20
diff -C2 -r1.19 -r1.20
*** Array.cs    14 Apr 2003 07:02:28 -0000      1.19
--- Array.cs    15 Apr 2003 01:05:27 -0000      1.20
***************
*** 205,208 ****
--- 205,239 ----
                                         int destinationIndex, int length);
  
+       // Determine if it is possible to cast between two types,
+       // without using a narrowing conversion.
+       private static bool ArrayTypeCompatible(Type src, Type dest)
+                       {
+                               if(dest.IsAssignableFrom(src))
+                               {
+                                       // Direct assignment with or without 
boxing conversion.
+                                       return true;
+                               }
+                               else if(dest.IsValueType && 
src.IsAssignableFrom(dest))
+                               {
+                                       // Unboxing conversion.
+                                       return true;
+                               }
+                               else if(src.IsPrimitive && dest.IsPrimitive)
+                               {
+                                       // Primitive numeric cast.
+                                       return 
Convert.HasWideningConversion(src, dest);
+                               }
+                               else if(!src.IsValueType && !dest.IsValueType)
+                               {
+                                       // Try using an explicit cast up the 
tree.
+                                       return src.IsAssignableFrom(dest);
+                               }
+                               else
+                               {
+                                       // No conversion possible.
+                                       return false;
+                               }
+                       }
+ 
        // Copy the contents of one array into another (general-purpose 
version).
        public static void Copy(Array sourceArray, int sourceIndex,
***************
*** 263,282 ****
                }
  
!               // Copy the array contents the hard way.
                int index;
                for(index = 0; index < length; ++index)
                {
!                       try
!                       {
!                               destinationArray.SetRelative(
!                                       Convert.ConvertObject(
!                                               
sourceArray.GetRelative(sourceIndex + index), 
!                                               arrayType2), destinationIndex + 
index);
!                       }
!                       catch(Exception)
!                       {
!                               throw new ArrayTypeMismatchException // error
!                                                       
(_("Exception_ArrayTypeMismatch")); 
!                       }
                }
        }
--- 294,315 ----
                }
  
!               // Check that casting between the types is possible,
!               // without using a narrowing conversion.
!               if(!ArrayTypeCompatible(arrayType1, arrayType2))
!               {
!                       throw new ArrayTypeMismatchException
!                               (_("Exception_ArrayTypeMismatch")); 
!               }
! 
!               // Copy the array contents the hard way.  We don't have to
!               // worry about overlapping ranges because there is no way
!               // to get here if the source and destination are the same.
                int index;
                for(index = 0; index < length; ++index)
                {
!                       destinationArray.SetRelative(
!                               Convert.ConvertObject(
!                                       sourceArray.GetRelative(sourceIndex + 
index - srcLower), 
!                                       arrayType2), destinationIndex + index - 
dstLower);
                }
        }

Index: Convert.cs
===================================================================
RCS file: /cvsroot/dotgnu-pnet/pnetlib/runtime/System/Convert.cs,v
retrieving revision 1.9
retrieving revision 1.10
diff -C2 -r1.9 -r1.10
*** Convert.cs  2 Jan 2003 15:04:39 -0000       1.9
--- Convert.cs  15 Apr 2003 01:05:27 -0000      1.10
***************
*** 2,6 ****
   * Convert.cs - Implementation of the "System.Convert" class.
   *
!  * Copyright (C) 2001  Southern Storm Software, Pty Ltd.
   *
   * This program is free software; you can redistribute it and/or modify
--- 2,6 ----
   * Convert.cs - Implementation of the "System.Convert" class.
   *
!  * Copyright (C) 2001, 2003  Southern Storm Software, Pty Ltd.
   *
[...1351 lines suppressed...]
!                                                       to == typeof(double));
!                               }
!                               else if(from == typeof(ulong))
!                               {
!                                       return (to == typeof(ulong) ||
!                                                       to == typeof(float) ||
!                                                       to == typeof(double));
!                               }
!                               else if(from == typeof(float))
!                               {
!                                       return (to == typeof(float) ||
!                                                       to == typeof(double));
!                               }
!                               else if(from == typeof(double))
!                               {
!                                       return (to == typeof(double));
!                               }
!                               return false;
                        }
  





reply via email to

[Prev in Thread] Current Thread [Next in Thread]