Merge pull request #1179 from ludovic-henry/pr25-threadpool
[mono.git] / mcs / class / corlib / System.Text / Decoder.cs
index 74062465718f4c05303dfe4d855bbcbf831dd165..c44176989c8acdac1df35754ad32cffbc069bf14 100644 (file)
@@ -29,16 +29,13 @@ using System;
 using System.Runtime.InteropServices;
 
 [Serializable]
-#if NET_2_0
 [ComVisible (true)]
-#endif
 public abstract class Decoder
 {
 
        // Constructor.
        protected Decoder () {}
 
-#if NET_2_0
        DecoderFallback fallback = new DecoderReplacementFallback ();
        DecoderFallbackBuffer fallback_buffer;
 
@@ -61,7 +58,6 @@ public abstract class Decoder
                        return fallback_buffer;
                }
        }
-#endif
 
        // Get the number of characters needed to decode a buffer.
        public abstract int GetCharCount (byte[] bytes, int index, int count);
@@ -70,7 +66,6 @@ public abstract class Decoder
        public abstract int GetChars (byte[] bytes, int byteIndex, int byteCount,
                                                                 char[] chars, int charIndex);
 
-#if NET_2_0
        [ComVisible (false)]
        public virtual int GetCharCount (byte [] bytes, int index, int count, bool flush)
        {
@@ -113,10 +108,11 @@ public abstract class Decoder
                CheckArguments (chars, charCount, bytes, byteCount);
 
                char [] carr = new char [charCount];
-               Marshal.Copy ((IntPtr) chars, carr, 0, charCount);
                byte [] barr = new byte [byteCount];
                Marshal.Copy ((IntPtr) bytes, barr, 0, byteCount);
-               return GetChars (barr, 0, byteCount, carr, 0, flush);
+               int charsUsed = GetChars (barr, 0, byteCount, carr, 0, flush);
+               Marshal.Copy (carr, 0, (IntPtr) chars, charsUsed);
+               return charsUsed;
        }
 
        [ComVisible (false)]
@@ -154,7 +150,10 @@ public abstract class Decoder
                out int bytesUsed, out int charsUsed, out bool completed)
        {
                CheckArguments (bytes, byteIndex, byteCount);
-               CheckArguments (chars, charIndex);
+               if (chars == null)
+                       throw new ArgumentNullException ("chars");
+               if (charIndex < 0)
+                       throw new ArgumentOutOfRangeException ("charIndex");
                if (charCount < 0 || chars.Length < charIndex + charCount)
                        throw new ArgumentOutOfRangeException ("charCount");
 
@@ -174,7 +173,7 @@ public abstract class Decoder
        {
                if (chars == null)
                        throw new ArgumentNullException ("chars");
-               if (charIndex < 0 || chars.Length <= charIndex)
+               if (charIndex < 0 || chars.Length < charIndex)
                        throw new ArgumentOutOfRangeException ("charIndex");
        }
 
@@ -182,7 +181,7 @@ public abstract class Decoder
        {
                if (bytes == null)
                        throw new ArgumentNullException ("bytes");
-               if (byteIndex < 0 || bytes.Length <= byteIndex)
+               if (byteIndex < 0)
                        throw new ArgumentOutOfRangeException ("byteIndex");
                if (byteCount < 0 || bytes.Length < byteIndex + byteCount)
                        throw new ArgumentOutOfRangeException ("byteCount");
@@ -199,8 +198,6 @@ public abstract class Decoder
                if (byteCount < 0)
                        throw new ArgumentOutOfRangeException ("byteCount");
        }
-#endif
-
 }; // class Decoder
 
 }; // namespace System.Text