From: Marek Safar Date: Thu, 9 Apr 2015 09:37:33 +0000 (+0200) Subject: [corlib] GetGenericArguments from reference sources X-Git-Url: http://wien.tomnetworks.com/gitweb/?a=commitdiff_plain;h=9965afbe2fdee75c5e17153dfd54e30fdc8ae1c8;p=mono.git [corlib] GetGenericArguments from reference sources --- diff --git a/external/referencesource b/external/referencesource index a8bf9ebd8c7..7d6aea73bb4 160000 --- a/external/referencesource +++ b/external/referencesource @@ -1 +1 @@ -Subproject commit a8bf9ebd8c7d32a6ae0c74f8c379cad26eb38c7e +Subproject commit 7d6aea73bb44fa0e3fa51221106571b51a3425e5 diff --git a/mcs/class/corlib/ReferenceSources/RuntimeType.cs b/mcs/class/corlib/ReferenceSources/RuntimeType.cs index 3557e77817c..a2673c34886 100644 --- a/mcs/class/corlib/ReferenceSources/RuntimeType.cs +++ b/mcs/class/corlib/ReferenceSources/RuntimeType.cs @@ -394,44 +394,6 @@ namespace System return constraints; } - public override Type MakeGenericType (params Type[] typeArguments) - { - if (IsUserType) - throw new NotSupportedException (); - if (!IsGenericTypeDefinition) - throw new InvalidOperationException ("not a generic type definition"); - if (typeArguments == null) - throw new ArgumentNullException ("typeArguments"); - if (GetGenericArguments().Length != typeArguments.Length) - throw new ArgumentException (String.Format ("The type or method has {0} generic parameter(s) but {1} generic argument(s) where provided. A generic argument must be provided for each generic parameter.", GetGenericArguments ().Length, typeArguments.Length), "typeArguments"); - - bool hasUserType = false; - - Type[] systemTypes = new Type[typeArguments.Length]; - for (int i = 0; i < typeArguments.Length; ++i) { - Type t = typeArguments [i]; - if (t == null) - throw new ArgumentNullException ("typeArguments"); - - if (!(t is MonoType)) - hasUserType = true; - systemTypes [i] = t; - } - - if (hasUserType) { -#if FULL_AOT_RUNTIME - throw new NotSupportedException ("User types are not supported under full aot"); -#else - return new MonoGenericClass (this, typeArguments); -#endif - } - - Type res = MakeGenericType (this, systemTypes); - if (res == null) - throw new TypeLoadException (); - return res; - } - [MethodImplAttribute(MethodImplOptions.InternalCall)] static extern Type MakeGenericType (Type gt, Type [] types); @@ -612,7 +574,7 @@ namespace System internal extern string getFullName(bool full_name, bool assembly_qualified); [MethodImplAttribute(MethodImplOptions.InternalCall)] - public extern override Type [] GetGenericArguments (); + extern Type[] GetGenericArgumentsInternal (bool runtimeArray); [MethodImplAttribute(MethodImplOptions.InternalCall)] extern GenericParameterAttributes GetGenericParameterAttributes (); diff --git a/mcs/class/corlib/ReferenceSources/TypeBuilderInstantiation.cs b/mcs/class/corlib/ReferenceSources/TypeBuilderInstantiation.cs new file mode 100644 index 00000000000..9e826646321 --- /dev/null +++ b/mcs/class/corlib/ReferenceSources/TypeBuilderInstantiation.cs @@ -0,0 +1,14 @@ +namespace System.Reflection.Emit +{ + abstract class TypeBuilderInstantiation : TypeInfo + { + internal static Type MakeGenericType (Type type, Type[] typeArguments) + { +#if FULL_AOT_RUNTIME + throw new NotSupportedException ("User types are not supported under full aot"); +#else + return new MonoGenericClass (type, typeArguments); +#endif + } + } +} \ No newline at end of file diff --git a/mcs/class/corlib/System/Environment.cs b/mcs/class/corlib/System/Environment.cs index ddbd37a5e27..96c8dd3da62 100644 --- a/mcs/class/corlib/System/Environment.cs +++ b/mcs/class/corlib/System/Environment.cs @@ -57,7 +57,7 @@ namespace System { * of icalls, do not require an increment. */ #pragma warning disable 169 - private const int mono_corlib_version = 125; + private const int mono_corlib_version = 126; #pragma warning restore 169 [ComVisible (true)] diff --git a/mcs/class/corlib/corlib.dll.sources b/mcs/class/corlib/corlib.dll.sources index 571c3573788..4aef1fb9ff7 100644 --- a/mcs/class/corlib/corlib.dll.sources +++ b/mcs/class/corlib/corlib.dll.sources @@ -1130,6 +1130,7 @@ ReferenceSources/MonoRuntimeWorkItem.cs ReferenceSources/MethodBase.cs ReferenceSources/RuntimeHandles.cs ReferenceSources/CompareInfo.cs +ReferenceSources/TypeBuilderInstantiation.cs ../../../external/referencesource/mscorlib/system/__filters.cs ../../../external/referencesource/mscorlib/system/__hresults.cs diff --git a/mono/metadata/appdomain.c b/mono/metadata/appdomain.c index b959cb96b04..b7bf90d203c 100644 --- a/mono/metadata/appdomain.c +++ b/mono/metadata/appdomain.c @@ -78,7 +78,7 @@ * Changes which are already detected at runtime, like the addition * of icalls, do not require an increment. */ -#define MONO_CORLIB_VERSION 125 +#define MONO_CORLIB_VERSION 126 typedef struct { diff --git a/mono/metadata/class-internals.h b/mono/metadata/class-internals.h index 36080792d10..f69a2e7685a 100644 --- a/mono/metadata/class-internals.h +++ b/mono/metadata/class-internals.h @@ -1091,6 +1091,7 @@ typedef struct { MonoClass *methodhandle_class; MonoClass *systemtype_class; MonoClass *monotype_class; + MonoClass *runtimetype_class; MonoClass *exception_class; MonoClass *threadabortexception_class; MonoClass *thread_class; diff --git a/mono/metadata/domain.c b/mono/metadata/domain.c index 801d58e4162..6bd4f86a1b4 100755 --- a/mono/metadata/domain.c +++ b/mono/metadata/domain.c @@ -716,6 +716,10 @@ mono_init_internal (const char *filename, const char *exe_filename, const char * mono_defaults.corlib, "System", "MonoType"); g_assert (mono_defaults.monotype_class != 0); + mono_defaults.runtimetype_class = mono_class_from_name ( + mono_defaults.corlib, "System", "RuntimeType"); + g_assert (mono_defaults.runtimetype_class != 0); + mono_defaults.exception_class = mono_class_from_name ( mono_defaults.corlib, "System", "Exception"); g_assert (mono_defaults.exception_class != 0); diff --git a/mono/metadata/icall-def.h b/mono/metadata/icall-def.h index 87bb85e5664..e7e661190d1 100644 --- a/mono/metadata/icall-def.h +++ b/mono/metadata/icall-def.h @@ -733,7 +733,7 @@ ICALL(RT_1, "CreateInstanceInternal", ves_icall_System_Activator_CreateInstanceI ICALL(RT_2, "GetConstructors_internal", ves_icall_Type_GetConstructors_internal) ICALL(RT_3, "GetEvents_internal", ves_icall_Type_GetEvents_internal) ICALL(RT_5, "GetFields_internal", ves_icall_Type_GetFields_internal) -ICALL(RT_6, "GetGenericArguments", ves_icall_MonoType_GetGenericArguments) +ICALL(RT_6, "GetGenericArgumentsInternal", ves_icall_MonoType_GetGenericArguments) ICALL(RT_7, "GetGenericParameterAttributes", ves_icall_Type_GetGenericParameterAttributes) ICALL(RT_8, "GetGenericParameterConstraints_impl", ves_icall_Type_GetGenericParameterConstraints) ICALL(RT_9, "GetGenericParameterPosition", ves_icall_Type_GetGenericParameterPosition) diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index 8f0f4dfbdab..1132dbfeb0f 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -2293,31 +2293,38 @@ ves_icall_MonoType_GetArrayRank (MonoReflectionType *type) return class->rank; } +static MonoArray* +create_type_array (MonoDomain *domain, MonoBoolean runtimeTypeArray, int count) +{ + MonoArray *res; + res = mono_array_new (domain, runtimeTypeArray ? mono_defaults.runtimetype_class : mono_defaults.systemtype_class, count); + return res; +} + ICALL_EXPORT MonoArray* -ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type) +ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type, MonoBoolean runtimeTypeArray) { MonoArray *res; MonoClass *klass, *pklass; MonoDomain *domain = mono_object_domain (type); - MonoVTable *array_vtable = mono_class_vtable_full (domain, mono_array_class_get_cached (mono_defaults.systemtype_class, 1), TRUE); int i; klass = mono_class_from_mono_type (type->type); if (klass->generic_container) { MonoGenericContainer *container = klass->generic_container; - res = mono_array_new_specific (array_vtable, container->type_argc); + res = create_type_array (domain, runtimeTypeArray, container->type_argc); for (i = 0; i < container->type_argc; ++i) { pklass = mono_class_from_generic_parameter (mono_generic_container_get_param (container, i), klass->image, FALSE); mono_array_setref (res, i, mono_type_get_object (domain, &pklass->byval_arg)); } } else if (klass->generic_class) { MonoGenericInst *inst = klass->generic_class->context.class_inst; - res = mono_array_new_specific (array_vtable, inst->type_argc); + res = create_type_array (domain, runtimeTypeArray, inst->type_argc); for (i = 0; i < inst->type_argc; ++i) mono_array_setref (res, i, mono_type_get_object (domain, inst->type_argv [i])); } else { - res = mono_array_new_specific (array_vtable, 0); + res = NULL; } return res; }