From 5f6941c396ef9ea5d21964aa3113593c7b6215b9 Mon Sep 17 00:00:00 2001 From: Rodrigo Kumpera Date: Mon, 5 Nov 2012 14:13:57 -0500 Subject: [PATCH] Remove SRE.UnmanagedMarshal dependency from System.Reflection. * 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. --- .../System.Reflection.Emit/UnmanagedMarshal.cs | 17 ---------- mcs/class/corlib/System.Reflection/FieldInfo.cs | 7 ++-- mcs/class/corlib/System.Reflection/MonoMethod.cs | 2 +- .../corlib/System.Reflection/ParameterInfo.cs | 7 ++-- mcs/class/corlib/System/Environment.cs | 2 +- mono/metadata/appdomain.c | 2 +- mono/metadata/icall-def.h | 2 +- mono/metadata/icall.c | 12 +++---- mono/metadata/object-internals.h | 2 +- mono/metadata/object.c | 8 +++-- mono/metadata/reflection.c | 39 +++++++++++----------- 11 files changed, 43 insertions(+), 57 deletions(-) diff --git a/mcs/class/corlib/System.Reflection.Emit/UnmanagedMarshal.cs b/mcs/class/corlib/System.Reflection.Emit/UnmanagedMarshal.cs index cbe2fe71dff..a14b61e4452 100644 --- a/mcs/class/corlib/System.Reflection.Emit/UnmanagedMarshal.cs +++ b/mcs/class/corlib/System.Reflection.Emit/UnmanagedMarshal.cs @@ -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; - } } } diff --git a/mcs/class/corlib/System.Reflection/FieldInfo.cs b/mcs/class/corlib/System.Reflection/FieldInfo.cs index 57b0d9cbd26..845cd2d935b 100644 --- a/mcs/class/corlib/System.Reflection/FieldInfo.cs +++ b/mcs/class/corlib/System.Reflection/FieldInfo.cs @@ -27,7 +27,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; @@ -190,7 +189,7 @@ namespace System.Reflection { } [MethodImplAttribute(MethodImplOptions.InternalCall)] - private extern UnmanagedMarshal GetUnmanagedMarshal (); + private extern MarshalAsAttribute get_marshal_info (); internal object[] GetPseudoCustomAttributes () { @@ -202,7 +201,7 @@ namespace System.Reflection { if (DeclaringType.IsExplicitLayout) count ++; - UnmanagedMarshal marshalAs = UMarshal; + MarshalAsAttribute marshalAs = get_marshal_info (); if (marshalAs != null) count ++; @@ -216,7 +215,7 @@ namespace System.Reflection { if (DeclaringType.IsExplicitLayout) attrs [count ++] = new FieldOffsetAttribute (GetFieldOffset ()); if (marshalAs != null) - attrs [count ++] = marshalAs.ToMarshalAsAttribute (); + attrs [count ++] = marshalAs; return attrs; } diff --git a/mcs/class/corlib/System.Reflection/MonoMethod.cs b/mcs/class/corlib/System.Reflection/MonoMethod.cs index b1079d6be18..d2ba6cde4a1 100644 --- a/mcs/class/corlib/System.Reflection/MonoMethod.cs +++ b/mcs/class/corlib/System.Reflection/MonoMethod.cs @@ -98,7 +98,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) { diff --git a/mcs/class/corlib/System.Reflection/ParameterInfo.cs b/mcs/class/corlib/System.Reflection/ParameterInfo.cs index 6de8aeb01af..f7c873c2108 100644 --- a/mcs/class/corlib/System.Reflection/ParameterInfo.cs +++ b/mcs/class/corlib/System.Reflection/ParameterInfo.cs @@ -44,8 +44,7 @@ namespace System.Reflection protected string NameImpl; protected int PositionImpl; protected ParameterAttributes AttrsImpl; - private UnmanagedMarshal marshalAs; - //ParameterInfo parent; + private MarshalAsAttribute marshalAs; protected ParameterInfo () { } @@ -89,7 +88,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 = ""; @@ -239,7 +238,7 @@ namespace System.Reflection attrs [count ++] = new OutAttribute (); if (marshalAs != null) - attrs [count ++] = marshalAs.ToMarshalAsAttribute (); + attrs [count ++] = marshalAs.Copy (); return attrs; } diff --git a/mcs/class/corlib/System/Environment.cs b/mcs/class/corlib/System/Environment.cs index f0c433207e4..d9f4c66216c 100644 --- a/mcs/class/corlib/System/Environment.cs +++ b/mcs/class/corlib/System/Environment.cs @@ -55,7 +55,7 @@ namespace System { * of icalls, do not require an increment. */ #pragma warning disable 169 - private const int mono_corlib_version = 105 + 0x0210; + private const int mono_corlib_version = 108 + 0x0210; #pragma warning restore 169 [ComVisible (true)] diff --git a/mono/metadata/appdomain.c b/mono/metadata/appdomain.c index 65f227e13bb..4ff26fc0ecc 100644 --- a/mono/metadata/appdomain.c +++ b/mono/metadata/appdomain.c @@ -73,7 +73,7 @@ * Changes which are already detected at runtime, like the addition * of icalls, do not require an increment. */ -#define MONO_CORLIB_VERSION 105 + 0x0210 +#define MONO_CORLIB_VERSION 108 + 0x0210 typedef struct { diff --git a/mono/metadata/icall-def.h b/mono/metadata/icall-def.h index 6c48c0b1636..324b8305471 100644 --- a/mono/metadata/icall-def.h +++ b/mono/metadata/icall-def.h @@ -570,7 +570,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) diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index 29a1922fbb2..cff4d622c73 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -1640,8 +1640,8 @@ ves_icall_get_attributes (MonoReflectionType *type) return klass->flags; } -static MonoReflectionMarshal* -ves_icall_System_Reflection_FieldInfo_GetUnmanagedMarshal (MonoReflectionField *field) +static MonoReflectionMarshalAsAttribute* +ves_icall_System_Reflection_FieldInfo_get_marshal_info (MonoReflectionField *field) { MonoClass *klass = field->field->parent; MonoMarshalType *info; @@ -1658,7 +1658,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); } } @@ -1748,11 +1748,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); } -static MonoReflectionMarshal* +static 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; @@ -1760,7 +1760,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]) diff --git a/mono/metadata/object-internals.h b/mono/metadata/object-internals.h index 65e2995b39e..61c83e82933 100644 --- a/mono/metadata/object-internals.h +++ b/mono/metadata/object-internals.h @@ -1397,7 +1397,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; diff --git a/mono/metadata/object.c b/mono/metadata/object.c index 1e397200754..435bf26f942 100644 --- a/mono/metadata/object.c +++ b/mono/metadata/object.c @@ -5927,8 +5927,12 @@ mono_print_unhandled_exception (MonoObject *exc) message = mono_exception_get_native_backtrace ((MonoException*)exc); free_message = TRUE; } else { - str = mono_object_to_string (exc, NULL); - if (str) { + MonoObject *inner_ex = NULL; + str = mono_object_to_string (exc, &inner_ex); + if (inner_ex) { + message = g_strdup_printf ("recursive exception handling %s:%s", mono_object_get_class (exc)->name_space, mono_object_get_class (exc)->name); + free_message = TRUE; + } if (str) { message = mono_string_to_utf8_checked (str, &error); if (!mono_error_ok (&error)) { mono_error_cleanup (&error); diff --git a/mono/metadata/reflection.c b/mono/metadata/reflection.c index f0b26cf80c6..6190de45c1f 100644 --- a/mono/metadata/reflection.c +++ b/mono/metadata/reflection.c @@ -6834,7 +6834,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); } @@ -9991,45 +9991,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: -- 2.11.4.GIT