Author: gert
Date: 2005-06-22 14:04:04 -0400 (Wed, 22 Jun 2005)
New Revision: 46376

Modified:
   trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog
   trunk/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs
   trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
   trunk/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTest.cs
Log:
* MethodBuilder.cs: In CreateMethodBody, throw ArgumentOutOfRangeException
instead of ArgumentException when count is not within range of array. Do not
allow zero-length method body to be emitted when using 2.0 profile. Fixes
bug #75236.
* MethodBuilderTest.cs: Updated existing tests to no longer define zero-length
method body. Added tests for bug #75236.


Modified: trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog     2005-06-22 
18:03:03 UTC (rev 46375)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/ChangeLog     2005-06-22 
18:04:04 UTC (rev 46376)
@@ -5,6 +5,13 @@
 
 2005-06-12  Gert Driesen <[EMAIL PROTECTED]>
 
+       * MethodBuilder.cs: In CreateMethodBody, throw 
+       ArgumentOutOfRangeException instead of ArgumentException when count 
+       is not within range of array. Do not allow zero length method body 
+       to be emitted when using 2.0 profile. Fixes bug #75236.
+
+2005-06-12  Gert Driesen <[EMAIL PROTECTED]>
+
        * FieldBuilder.cs: FieldBuilder.FieldHandle should throw
        NotSupportedException to match MS.NET (both 1.x and 2.x). 
        Fixes regression introduced in r45750.

Modified: trunk/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs
===================================================================
--- trunk/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs      
2005-06-22 18:03:03 UTC (rev 46375)
+++ trunk/mcs/class/corlib/System.Reflection.Emit/MethodBuilder.cs      
2005-06-22 18:04:04 UTC (rev 46376)
@@ -215,7 +215,7 @@
 
                public void CreateMethodBody( byte[] il, int count) {
                        if ((il != null) && ((count < 0) || (count > 
il.Length)))
-                               throw new ArgumentException ("Index was out of 
range.  Must be non-negative and less than the size of the collection.");
+                               throw new ArgumentOutOfRangeException ("Index 
was out of range.  Must be non-negative and less than the size of the 
collection.");
 
                        if ((code != null) || type.is_created)
                                throw new InvalidOperationException ("Type 
definition of the method is complete.");
@@ -275,7 +275,12 @@
 
                internal void fixup () {
                        if (((attrs & (MethodAttributes.Abstract | 
MethodAttributes.PinvokeImpl)) == 0) && ((iattrs & 
(MethodImplAttributes.Runtime | MethodImplAttributes.InternalCall)) == 0)) {
+#if NET_2_0
+                               // do not allow zero length method body on 
MS.NET 2.0 (and higher)
+                               if (((ilgen == null) || 
(ILGenerator.Mono_GetCurrentOffset (ilgen) == 0)) && (code == null || 
code.Length == 0))
+#else
                                if (((ilgen == null) || 
(ILGenerator.Mono_GetCurrentOffset (ilgen) == 0)) && (code == null))
+#endif
                                        throw new InvalidOperationException 
("Method '" + Name + "' does not have a method body.");
                        }
                        if (ilgen != null)

Modified: trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog        
2005-06-22 18:03:03 UTC (rev 46375)
+++ trunk/mcs/class/corlib/Test/System.Reflection.Emit/ChangeLog        
2005-06-22 18:04:04 UTC (rev 46376)
@@ -1,3 +1,8 @@
+2005-06-22  Gert Driesen  <[EMAIL PROTECTED]>
+
+       * MethodBuilderTest.cs: Updated existing tests to no longer define
+       zero-length method body. Added tests for bug #75236.
+
 2005-06-14  Sebastien Pouliot  <[EMAIL PROTECTED]>
 
        * AssemblyBuilderTest.cs: Split AssemblyName_PublicKey to move culture

Modified: 
trunk/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTest.cs
===================================================================
--- trunk/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTest.cs     
2005-06-22 18:03:03 UTC (rev 46375)
+++ trunk/mcs/class/corlib/Test/System.Reflection.Emit/MethodBuilderTest.cs     
2005-06-22 18:04:04 UTC (rev 46376)
@@ -123,7 +123,7 @@
        public void TestMethodHandleComplete () {
                MethodBuilder mb = genClass.DefineMethod (
                        genMethodName (), 0, typeof (void), new Type [0]);
-               mb.CreateMethodBody (new byte[2], 0);
+               mb.CreateMethodBody (new byte[2], 1);
                genClass.CreateType ();
 
                RuntimeMethodHandle handle = mb.MethodHandle;
@@ -192,14 +192,14 @@
                try {
                        mb.CreateMethodBody (new byte[1], -1);
                        Fail ();
-               } catch (ArgumentException) {
+               } catch (ArgumentOutOfRangeException) {
                }
 
                // Check arguments 2.
                try {
                        mb.CreateMethodBody (new byte[1], 2);
                        Fail ();
-               } catch (ArgumentException) {
+               } catch (ArgumentOutOfRangeException) {
                }
 
                mb.CreateMethodBody (new byte[2], 1);
@@ -236,7 +236,7 @@
                        new Type[2] {
                        typeof(int), typeof(int)
                });
-               mb.CreateMethodBody (new byte[2], 0);
+               mb.CreateMethodBody (new byte[2], 1);
                tb.CreateType ();
                mb.DefineParameter (-5, ParameterAttributes.None, "param1");
        }
@@ -251,7 +251,7 @@
                        new Type[2] {
                        typeof(int), typeof(int)
                });
-               mb.CreateMethodBody (new byte[2], 0);
+               mb.CreateMethodBody (new byte[2], 1);
                tb.CreateType ();
                mb.DefineParameter (1, ParameterAttributes.None, "param1");
        }
@@ -285,8 +285,7 @@
                mb.DefineParameter (1, 0, "param1");
                mb.DefineParameter (2, 0, null);
 
-               // Can not be called on a created type
-               mb.CreateMethodBody (new byte[2], 0);
+               mb.CreateMethodBody (new byte[2], 1);
                tb.CreateType ();
                try {
                        mb.DefineParameter (1, 0, "param1");
@@ -297,6 +296,31 @@
        }
 
        [Test]
+#if NET_2_0
+       // MS.NET 2.x no longer allows a zero length method body
+       // to be emitted
+       [ExpectedException (typeof (InvalidOperationException))]
+#endif
+       public void ZeroLengthBodyTest1 ()
+       {
+               MethodBuilder mb = genClass.DefineMethod (
+                       genMethodName (), 0, typeof (void), 
+                       new Type [2] { typeof(int), typeof(int) });
+               mb.CreateMethodBody (new byte[2], 0);
+               genClass.CreateType ();
+       }
+
+       // A zero length method body can be created
+       [Test]
+       public void ZeroLengthBodyTest2 ()
+       {
+               MethodBuilder mb = genClass.DefineMethod (
+                       genMethodName (), 0, typeof (void), 
+                       new Type [2] { typeof(int), typeof(int) });
+               mb.CreateMethodBody (new byte[2], 0);
+       }
+
+       [Test]
        public void TestHashCode ()
        {
                TypeBuilder tb = module.DefineType (genTypeName (), 
TypeAttributes.Public);
@@ -364,8 +388,7 @@
                                          MethodImplAttributes.OPTIL, 
                                          mb.GetMethodImplementationFlags ());
 
-               // Can not be called on a created type
-               mb.CreateMethodBody (new byte[2], 0);
+               mb.CreateMethodBody (new byte[2], 1);
                mb.SetImplementationFlags (MethodImplAttributes.Managed);
                tb.CreateType ();
                try {

_______________________________________________
Mono-patches maillist  -  [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches

Reply via email to