Author: marek
Date: 2007-12-23 07:09:55 -0500 (Sun, 23 Dec 2007)
New Revision: 91826

Modified:
   trunk/mcs/mcs/ChangeLog
   trunk/mcs/mcs/class.cs
Log:
2007-12-23  Marek Safar  <[EMAIL PROTECTED]>

        A fix for bug #347189
        * class.cs (FixedField): Use non-dependent code only in the define 
phase.



Modified: trunk/mcs/mcs/ChangeLog
===================================================================
--- trunk/mcs/mcs/ChangeLog     2007-12-23 12:08:33 UTC (rev 91825)
+++ trunk/mcs/mcs/ChangeLog     2007-12-23 12:09:55 UTC (rev 91826)
@@ -1,5 +1,10 @@
 2007-12-23  Marek Safar  <[EMAIL PROTECTED]>
 
+       A fix for bug #347189
+       * class.cs (FixedField): Use non-dependent code only in the define 
phase.
+
+2007-12-23  Marek Safar  <[EMAIL PROTECTED]>
+
        A fix for bug #348076
        * ecore.cs (FieldExpr.DoResolve): Allow any variable based expression.
 

Modified: trunk/mcs/mcs/class.cs
===================================================================
--- trunk/mcs/mcs/class.cs      2007-12-23 12:08:33 UTC (rev 91825)
+++ trunk/mcs/mcs/class.cs      2007-12-23 12:09:55 UTC (rev 91826)
@@ -5906,12 +5906,6 @@
                        if ((ModFlags & (Modifiers.PUBLIC | 
Modifiers.PROTECTED)) != 0)
                                Report.Warning (-23, 1, Location, "Only private 
or internal fixed sized buffers are supported by .NET 1.x");
 #endif
-
-                       if (Parent.PartialContainer.Kind != Kind.Struct) {
-                               Report.Error (1642, Location, "`{0}': Fixed 
size buffer fields may only be members of structs",
-                                       GetSignatureForError ());
-                       }
-
                        if (!Parent.IsInUnsafeScope)
                                Expression.UnsafeError (Location);
 
@@ -5921,23 +5915,44 @@
                        if (!TypeManager.IsPrimitiveType (MemberType)) {
                                Report.Error (1663, Location, "`{0}': Fixed 
size buffers type must be one of the following: bool, byte, short, int, long, 
char, sbyte, ushort, uint, ulong, float or double",
                                        GetSignatureForError ());
-                               return false;
+                       }                       
+                       
+                       // Create nested fixed buffer container
+                       string name = String.Format ("<{0}>__FixedBuffer{1}", 
Name, GlobalCounter++);
+                       fixed_buffer_type = Parent.TypeBuilder.DefineNestedType 
(name,
+                               TypeAttributes.NestedPublic | 
TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, TypeManager.value_type);
+                       
+                       element = fixed_buffer_type.DefineField 
(FixedElementName, MemberType, FieldAttributes.Public);
+                       RootContext.RegisterCompilerGeneratedType 
(fixed_buffer_type);
+                       
+                       FieldBuilder = Parent.TypeBuilder.DefineField (Name, 
fixed_buffer_type, Modifiers.FieldAttr (ModFlags));
+                       Parent.MemberCache.AddMember (FieldBuilder, this);
+                       TypeManager.RegisterFieldBase (FieldBuilder, this);
+
+                       return true;
+               }
+
+               public override void Emit()
+               {
+                       if (Parent.PartialContainer.Kind != Kind.Struct) {
+                               Report.Error (1642, Location, "`{0}': Fixed 
size buffer fields may only be members of structs",
+                                       GetSignatureForError ());
                        }
 
                        EmitContext ec = new EmitContext (this, Parent, 
Location, null, TypeManager.void_type, ModFlags);
                        Constant c = size_expr.ResolveAsConstant (ec, this);
                        if (c == null)
-                               return false;
+                               return;
 
                        IntConstant buffer_size_const = 
c.ImplicitConversionRequired (TypeManager.int32_type, Location) as IntConstant;
                        if (buffer_size_const == null)
-                               return false;
+                               return;
 
                        buffer_size = buffer_size_const.Value;
 
                        if (buffer_size <= 0) {
                                Report.Error (1665, Location, "`{0}': Fixed 
size buffers must have a length greater than zero", GetSignatureForError ());
-                               return false;
+                               return;
                        }
 
                        int type_size = Expression.GetTypeSize (MemberType);
@@ -5945,29 +5960,11 @@
                        if (buffer_size > int.MaxValue / type_size) {
                                Report.Error (1664, Location, "Fixed size 
buffer `{0}' of length `{1}' and type `{2}' exceeded 2^31 limit",
                                        GetSignatureForError (), 
buffer_size.ToString (), TypeManager.CSharpName (MemberType));
-                               return false;
+                               return;
                        }
 
                        buffer_size *= type_size;
 
-                       // Define nested
-                       string name = String.Format ("<{0}>__FixedBuffer{1}", 
Name, GlobalCounter++);
-
-                       fixed_buffer_type = Parent.TypeBuilder.DefineNestedType 
(name,
-                               TypeAttributes.NestedPublic | 
TypeAttributes.Sealed | TypeAttributes.BeforeFieldInit, TypeManager.value_type);
-                       element = fixed_buffer_type.DefineField 
(FixedElementName, MemberType, FieldAttributes.Public);
-                       RootContext.RegisterCompilerGeneratedType 
(fixed_buffer_type);
-
-                       FieldBuilder = Parent.TypeBuilder.DefineField (Name, 
fixed_buffer_type, Modifiers.FieldAttr (ModFlags));
-
-                       Parent.MemberCache.AddMember (FieldBuilder, this);
-                       TypeManager.RegisterFieldBase (FieldBuilder, this);
-
-                       return true;
-               }
-
-               public override void Emit()
-               {
                        if (fi == null)
                                fi = new FieldInfo [] { 
TypeManager.struct_layout_attribute_type.GetField ("Size") };
 

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

Reply via email to