[Mono-list] Array.cs

Paolo Molaro lupus@ximian.com
Wed, 6 Mar 2002 12:09:42 +0100

On 03/06/02 Martin Baulig wrote:
> > Can you post some info about what kind of changes to the array code
> > you want to do?
> well, several things which are now all in CVS:

My reason for asking information was to see the changes _before_ they
went in cvs. I hope I don't sound like a prick, but any change to
fundamental classes most likely bites me before anyone else, because I
routinely run the most complex C# app (mcs) with our class library.
Excuse me if I'm a little paranoid with changes to Array.
And while a simple bug added may not appear in the test suite or
may be lost in the noise of hundreds of errors, it is likely to show up
when running large or complex programs (ie I can't compile).

One problem is that the test suite needs to be changed to be more
fine-grained: a single test method contains many subtests and if the
first fails, the others are not run. This needs to be fixed.

> 2.) Rewrote the Array:Copy implementation so that it can now copy multi-
>     dimensional arrays.
>     I'm also planning to implement this directly in C so that it can use
>     memcpy() whenever possible.

See icall.c:ves_icall_System_Array_FastCopy().

> 6.) Made sure that all tests in the test suite pass.

Several Array test fail for me here after updating to cvs (though they
likely failed before as well).

I haven't checked the other stuff, but this chunk got my attention

> RCS file: /cvs/public/mcs/class/corlib/System/Array.cs,v
> retrieving revision 1.20
> retrieving revision 1.21
> diff -u -d -r1.20 -r1.21
> @@ -602,7 +646,7 @@
>  			// but that's how the microsoft runtime does it.
>  			if (this.Rank > 1)
>  				throw new RankException ();
> -			if (index + this.GetLength(0) > array.GetLength(0))
> +			if (index >= array.GetLength(0))
>  				throw new ArgumentException ();
>  			if (array.Rank > 1)
>  				throw new RankException ();

This is in Array.CopyTo (). Here is the history of this line in the last
few changes:

1.19         (martin   01-Mar-02): 			if (index >= array.GetLength(0))
1.20         (lupus    04-Mar-02): 			if (index + this.GetLength(0) > array.GetLength(0))
1.21         (martin   05-Mar-02): 			if (index >= array.GetLength(0))

I.e. I changed that line a couple of days ago, because it broke the
compiler and you changed it back (broking the compiler again).
Please, tell me what test case your change fixes that mine wouldn't.
Here is the test that your change breaks, instead.

using System;

namespace Test {
        public class Test {
                public static int Main () {
                        int[] src = new int [0];
                        int[] dest = new int [0];
                        src.CopyTo (dest, 0);
                        return 0;


lupus@debian.org                                     debian/rules
lupus@ximian.com                             Monkeys do it better