Remove SRE.UnmanagedMarshal dependency from System.Reflection.
authorRodrigo Kumpera <kumpera@gmail.com>
Mon, 5 Nov 2012 19:13:57 +0000 (14:13 -0500)
committerRodrigo Kumpera <kumpera@gmail.com>
Mon, 5 Nov 2012 19:16:12 +0000 (14:16 -0500)
* FieldInfo.cs:
* MonoMethod.cs:
* ParameterInfo.cs: Remove silly dep on UnmanagedMarshal to use
MarshalAsAttribute which is what we need in the end.

* icall.c:
* reflection.c: Use the custom attribute type instead of the SRE
one. This allows FULL_AOT_RUNTIME to work with stuff that uses
MarshalAs.

mcs/class/corlib/System.Reflection.Emit/UnmanagedMarshal.cs
mcs/class/corlib/System.Reflection/FieldInfo.cs
mcs/class/corlib/System.Reflection/MonoMethod.cs
mcs/class/corlib/System.Reflection/ParameterInfo.cs
mcs/class/corlib/System/Environment.cs
mono/metadata/appdomain.c
mono/metadata/icall-def.h
mono/metadata/icall.c
mono/metadata/object-internals.h
mono/metadata/reflection.c

index b9ed853e90204e18fb718ece95dd540b415df86f..9c123e9706800c70cfdcbaf99ff7095168d04445 100644 (file)
@@ -126,22 +126,5 @@ namespace System.Reflection.Emit {
 
                        return res;
                }
-
-               internal MarshalAsAttribute ToMarshalAsAttribute () {
-                       MarshalAsAttribute attr = new MarshalAsAttribute (t);
-                       attr.ArraySubType = tbase;
-                       attr.MarshalCookie = mcookie;
-                       attr.MarshalType = marshaltype;
-                       attr.MarshalTypeRef = marshaltyperef;
-                       if (count == -1)
-                               attr.SizeConst = 0;
-                       else
-                               attr.SizeConst = count;
-                       if (param_num == -1)
-                               attr.SizeParamIndex = 0;
-                       else
-                               attr.SizeParamIndex = (short)param_num;
-                       return attr;
-               }
        }
 }
index cd0d848fc48fc6b253238a98cdfe2356cfe9d541..93ac75de4af8e78bcca863876f7bcc30e3cf581a 100644 (file)
@@ -28,7 +28,6 @@
 // WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
 
 using System.Diagnostics;
-using System.Reflection.Emit;
 using System.Globalization;
 using System.Runtime.CompilerServices;
 using System.Runtime.InteropServices;
@@ -191,7 +190,7 @@ namespace System.Reflection {
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               private extern UnmanagedMarshal GetUnmanagedMarshal ();
+               private extern MarshalAsAttribute get_marshal_info ();
 
                internal object[] GetPseudoCustomAttributes ()
                {
@@ -203,7 +202,7 @@ namespace System.Reflection {
                        if (DeclaringType.IsExplicitLayout)
                                count ++;
 
-                       UnmanagedMarshal marshalAs = UMarshal;
+                       MarshalAsAttribute marshalAs = get_marshal_info ();
                        if (marshalAs != null)
                                count ++;
 
@@ -217,7 +216,7 @@ namespace System.Reflection {
                        if (DeclaringType.IsExplicitLayout)
                                attrs [count ++] = new FieldOffsetAttribute (GetFieldOffset ());
                        if (marshalAs != null)
-                               attrs [count ++] = marshalAs.ToMarshalAsAttribute ();
+                               attrs [count ++] = marshalAs;
 
                        return attrs;
                }
index 234acd90a0d08d01f3f19f0218888181d490bada..40366b43d0f43101cc18d7e04a7229339d143c29 100644 (file)
@@ -99,7 +99,7 @@ namespace System.Reflection {
                }
 
                [MethodImplAttribute(MethodImplOptions.InternalCall)]
-               static extern UnmanagedMarshal get_retval_marshal (IntPtr handle);
+               static extern MarshalAsAttribute get_retval_marshal (IntPtr handle);
 
                static internal ParameterInfo GetReturnParameterInfo (MonoMethod method)
                {
index 7ea808b863918637dd34e6050732fd56eb9d66c8..8d16f7e63a6324b10550a3ec21ded6dfd2c42060 100644 (file)
@@ -45,8 +45,7 @@ namespace System.Reflection
                protected string NameImpl;
                protected int PositionImpl;
                protected ParameterAttributes AttrsImpl;
-               private UnmanagedMarshal marshalAs;
-               //ParameterInfo parent;
+               private MarshalAsAttribute marshalAs;
 
                protected ParameterInfo () {
                }
@@ -90,7 +89,7 @@ namespace System.Reflection
                }
 
                /* to build a ParameterInfo for the return type of a method */
-               internal ParameterInfo (Type type, MemberInfo member, UnmanagedMarshal marshalAs) {
+               internal ParameterInfo (Type type, MemberInfo member, MarshalAsAttribute marshalAs) {
                        this.ClassImpl = type;
                        this.MemberImpl = member;
                        this.NameImpl = "";
@@ -244,7 +243,7 @@ namespace System.Reflection
                                attrs [count ++] = new OutAttribute ();
 
                        if (marshalAs != null)
-                               attrs [count ++] = marshalAs.ToMarshalAsAttribute ();
+                               attrs [count ++] = marshalAs.Copy ();
 
                        return attrs;
                }                       
index 0571215dafd6e3876928259621cce8030ac013a8..3f8878b0439bb5d04ba580ba6551da9fe9371d71 100644 (file)
@@ -56,7 +56,7 @@ namespace System {
                 * of icalls, do not require an increment.
                 */
 #pragma warning disable 169
-               private const int mono_corlib_version = 107;
+               private const int mono_corlib_version = 108;
 #pragma warning restore 169
 
                [ComVisible (true)]
index 2907af6d4924abfa77ff292be48f3fa5215d5d9f..04ce7e331a50771506d4fe7b9f16d206b95d15a4 100644 (file)
@@ -75,7 +75,7 @@
  * Changes which are already detected at runtime, like the addition
  * of icalls, do not require an increment.
  */
-#define MONO_CORLIB_VERSION 107
+#define MONO_CORLIB_VERSION 108
 
 typedef struct
 {
index 515b971212d5211324cfbfffcd6805535151e69f..4173b721b160ff3aeac7cd995764ba7a0b5c1e61 100644 (file)
@@ -572,7 +572,7 @@ ICALL(TYPEB_7, "setup_internal_class", mono_reflection_setup_internal_class)
 
 ICALL_TYPE(FIELDI, "System.Reflection.FieldInfo", FILEDI_1)
 ICALL(FILEDI_1, "GetTypeModifiers", ves_icall_System_Reflection_FieldInfo_GetTypeModifiers)
-ICALL(FILEDI_2, "GetUnmanagedMarshal", ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal)
+ICALL(FILEDI_2, "get_marshal_info", ves_icall_System_Reflection_FieldInfo_get_marshal_info)
 ICALL(FILEDI_3, "internal_from_handle_type", ves_icall_System_Reflection_FieldInfo_internal_from_handle_type)
 
 ICALL_TYPE(MEMBERI, "System.Reflection.MemberInfo", MEMBERI_1)
index e58903aa88ae32ce21eab684712b7c40e4b61aa6..8747f4c6baa558d74baa8725c9954cf9aac2e39f 100644 (file)
@@ -1641,8 +1641,8 @@ ves_icall_get_attributes (MonoReflectionType *type)
        return klass->flags;
 }
 
-ICALL_EXPORT MonoReflectionMarshal*
-ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal (MonoReflectionField *field)
+ICALL_EXPORT MonoReflectionMarshalAsAttribute*
+ves_icall_System_Reflection_FieldInfo_get_marshal_info (MonoReflectionField *field)
 {
        MonoClass *klass = field->field->parent;
        MonoMarshalType *info;
@@ -1659,7 +1659,7 @@ ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal (MonoReflectionField *
                        if (!info->fields [i].mspec)
                                return NULL;
                        else
-                               return mono_reflection_marshal_from_marshal_spec (field->object.vtable->domain, klass, info->fields [i].mspec);
+                               return mono_reflection_marshal_as_attribute_from_marshal_spec (field->object.vtable->domain, klass, info->fields [i].mspec);
                }
        }
 
@@ -1749,11 +1749,11 @@ ves_icall_get_parameter_info (MonoMethod *method, MonoReflectionMethod *member)
        return mono_param_get_objects_internal (domain, method, member->reftype ? mono_class_from_mono_type (member->reftype->type) : NULL);
 }
 
-ICALL_EXPORT MonoReflectionMarshal*
+ICALL_EXPORT MonoReflectionMarshalAsAttribute*
 ves_icall_System_MonoMethodInfo_get_retval_marshal (MonoMethod *method)
 {
        MonoDomain *domain = mono_domain_get (); 
-       MonoReflectionMarshal* res = NULL;
+       MonoReflectionMarshalAsAttribute* res = NULL;
        MonoMarshalSpec **mspecs;
        int i;
 
@@ -1761,7 +1761,7 @@ ves_icall_System_MonoMethodInfo_get_retval_marshal (MonoMethod *method)
        mono_method_get_marshal_info (method, mspecs);
 
        if (mspecs [0])
-               res = mono_reflection_marshal_from_marshal_spec (domain, method->klass, mspecs [0]);
+               res = mono_reflection_marshal_as_attribute_from_marshal_spec (domain, method->klass, mspecs [0]);
                
        for (i = mono_method_signature (method)->param_count; i >= 0; i--)
                if (mspecs [i])
index e51f5de87640151bd3a26841afcc40cb929e9ed5..d83c59afe16bbff3cd9001356cbf9e136491ff4c 100644 (file)
@@ -1413,7 +1413,7 @@ MonoArray  *mono_reflection_sighelper_get_signature_local (MonoReflectionSigHelp
 
 MonoArray  *mono_reflection_sighelper_get_signature_field (MonoReflectionSigHelper *sig) MONO_INTERNAL;
 
-MonoReflectionMarshal* mono_reflection_marshal_from_marshal_spec (MonoDomain *domain, MonoClass *klass, MonoMarshalSpec *spec) MONO_INTERNAL;
+MonoReflectionMarshalAsAttribute* mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, MonoClass *klass, MonoMarshalSpec *spec) MONO_INTERNAL;
 
 gpointer
 mono_reflection_lookup_dynamic_token (MonoImage *image, guint32 token, gboolean valid_token, MonoClass **handle_class, MonoGenericContext *context) MONO_INTERNAL;
index 79e285b43cf8708bd4a90454eee3b164a9c61513..0c3d2364822f6823828307a9b66db80e72c149dd 100644 (file)
@@ -6862,7 +6862,7 @@ mono_param_get_objects_internal (MonoDomain *domain, MonoMethod *method, MonoCla
                }
 
                if (mspecs [i + 1])
-                       MONO_OBJECT_SETREF (param, MarshalAsImpl, (MonoObject*)mono_reflection_marshal_from_marshal_spec (domain, method->klass, mspecs [i + 1]));
+                       MONO_OBJECT_SETREF (param, MarshalAsImpl, (MonoObject*)mono_reflection_marshal_as_attribute_from_marshal_spec (domain, method->klass, mspecs [i + 1]));
                
                mono_array_setref (res, i, param);
        }
@@ -10019,45 +10019,46 @@ mono_marshal_spec_from_builder (MonoImage *image, MonoAssembly *assembly,
 }
 #endif /* !DISABLE_REFLECTION_EMIT */
 
-MonoReflectionMarshal*
-mono_reflection_marshal_from_marshal_spec (MonoDomain *domain, MonoClass *klass,
+MonoReflectionMarshalAsAttribute*
+mono_reflection_marshal_as_attribute_from_marshal_spec (MonoDomain *domain, MonoClass *klass,
                                                                                   MonoMarshalSpec *spec)
 {
-       static MonoClass *System_Reflection_Emit_UnmanagedMarshalClass;
-       MonoReflectionMarshal *minfo;
+       static MonoClass *System_Reflection_Emit_MarshalAsAttribute;
+       MonoReflectionMarshalAsAttribute *minfo;
        MonoType *mtype;
 
-       if (!System_Reflection_Emit_UnmanagedMarshalClass) {
-               System_Reflection_Emit_UnmanagedMarshalClass = mono_class_from_name (
-                  mono_defaults.corlib, "System.Reflection.Emit", "UnmanagedMarshal");
-               g_assert (System_Reflection_Emit_UnmanagedMarshalClass);
+       if (!System_Reflection_Emit_MarshalAsAttribute) {
+               System_Reflection_Emit_MarshalAsAttribute = mono_class_from_name (
+                  mono_defaults.corlib, "System.Runtime.InteropServices", "MarshalAsAttribute");
+               g_assert (System_Reflection_Emit_MarshalAsAttribute);
        }
 
-       minfo = (MonoReflectionMarshal*)mono_object_new (domain, System_Reflection_Emit_UnmanagedMarshalClass);
-       minfo->type = spec->native;
+       minfo = (MonoReflectionMarshalAsAttribute*)mono_object_new (domain, System_Reflection_Emit_MarshalAsAttribute);
+       minfo->utype = spec->native;
 
-       switch (minfo->type) {
+       switch (minfo->utype) {
        case MONO_NATIVE_LPARRAY:
-               minfo->eltype = spec->data.array_data.elem_type;
-               minfo->count = spec->data.array_data.num_elem;
-               minfo->param_num = spec->data.array_data.param_num;
+               minfo->array_subtype = spec->data.array_data.elem_type;
+               minfo->size_const = spec->data.array_data.num_elem;
+               if (spec->data.array_data.param_num != -1)
+                       minfo->size_param_index = spec->data.array_data.param_num;
                break;
 
        case MONO_NATIVE_BYVALTSTR:
        case MONO_NATIVE_BYVALARRAY:
-               minfo->count = spec->data.array_data.num_elem;
+               minfo->size_const = spec->data.array_data.num_elem;
                break;
 
        case MONO_NATIVE_CUSTOM:
                if (spec->data.custom_data.custom_name) {
                        mtype = mono_reflection_type_from_name (spec->data.custom_data.custom_name, klass->image);
                        if (mtype)
-                               MONO_OBJECT_SETREF (minfo, marshaltyperef, mono_type_get_object (domain, mtype));
+                               MONO_OBJECT_SETREF (minfo, marshal_type_ref, mono_type_get_object (domain, mtype));
 
-                       MONO_OBJECT_SETREF (minfo, marshaltype, mono_string_new (domain, spec->data.custom_data.custom_name));
+                       MONO_OBJECT_SETREF (minfo, marshal_type, mono_string_new (domain, spec->data.custom_data.custom_name));
                }
                if (spec->data.custom_data.cookie)
-                       MONO_OBJECT_SETREF (minfo, mcookie, mono_string_new (domain, spec->data.custom_data.cookie));
+                       MONO_OBJECT_SETREF (minfo, marshal_cookie, mono_string_new (domain, spec->data.custom_data.cookie));
                break;
 
        default: