Add support for the processorArchitecture field in assembly names. Fixes #655096.
[mono.git] / mono / metadata / icall.c
index a6cfdfd93ceab12ccbd79d5d694976b3ce7624d7..a14e5ad867a3c37c460269037f951ea181860e85 100644 (file)
@@ -1171,13 +1171,13 @@ mono_type_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
 }
 
 static gint32
-ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj)
+ves_icall_ModuleBuilder_getToken (MonoReflectionModuleBuilder *mb, MonoObject *obj, gboolean create_open_instance)
 {
        MONO_ARCH_SAVE_REGS;
        
        MONO_CHECK_ARG_NULL (obj);
        
-       return mono_image_create_token (mb->dynamic_image, obj, TRUE, TRUE);
+       return mono_image_create_token (mb->dynamic_image, obj, create_open_instance, TRUE);
 }
 
 static gint32
@@ -1694,18 +1694,24 @@ ves_icall_System_Reflection_FieldInfo_GetTypeModifiers (MonoReflectionField *fie
        return type_array_from_modifiers (field->field->parent->image, type, optional);
 }
 
+static int
+vell_icall_get_method_attributes (MonoMethod *method)
+{
+       return method->flags;
+}
+
 static void
 ves_icall_get_method_info (MonoMethod *method, MonoMethodInfo *info)
 {
+       MonoError error;
        MonoDomain *domain = mono_domain_get ();
        MonoMethodSignature* sig;
        MONO_ARCH_SAVE_REGS;
 
-       sig = mono_method_signature (method);
-       if (!sig) {
-               g_assert (mono_loader_get_last_error ());
-               mono_raise_exception (mono_loader_error_prepare_exception (mono_loader_get_last_error ()));
-       }
+       sig = mono_method_signature_checked (method, &error);
+       if (!mono_error_ok (&error))
+               mono_error_raise_exception (&error);
+
 
        MONO_STRUCT_SETREF (info, parent, mono_type_get_object (domain, &method->klass->byval_arg));
        MONO_STRUCT_SETREF (info, ret, mono_type_get_object (domain, sig->ret));
@@ -1793,7 +1799,9 @@ ves_icall_MonoField_GetValueInternal (MonoReflectionField *field, MonoObject *ob
 static void
 ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *obj, MonoObject *value)
 {
+       MonoError error;
        MonoClassField *cf = field->field;
+       MonoType *type;
        gchar *v;
 
        MONO_ARCH_SAVE_REGS;
@@ -1805,9 +1813,13 @@ ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *ob
        if (mono_security_get_mode () == MONO_SECURITY_MODE_CORE_CLR)
                mono_security_core_clr_ensure_reflection_access_field (cf);
 
+       type = mono_field_get_type_checked (cf, &error);
+       if (!mono_error_ok (&error))
+               mono_error_raise_exception (&error);
+
        v = (gchar *) value;
-       if (!cf->type->byref) {
-               switch (cf->type->type) {
+       if (!type->byref) {
+               switch (type->type) {
                case MONO_TYPE_U1:
                case MONO_TYPE_I1:
                case MONO_TYPE_BOOLEAN:
@@ -1835,11 +1847,11 @@ ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *ob
                        /* Do nothing */
                        break;
                case MONO_TYPE_GENERICINST: {
-                       MonoGenericClass *gclass = cf->type->data.generic_class;
+                       MonoGenericClass *gclass = type->data.generic_class;
                        g_assert (!gclass->context.class_inst->is_open);
 
-                       if (mono_class_is_nullable (mono_class_from_mono_type (cf->type))) {
-                               MonoClass *nklass = mono_class_from_mono_type (cf->type);
+                       if (mono_class_is_nullable (mono_class_from_mono_type (type))) {
+                               MonoClass *nklass = mono_class_from_mono_type (type);
                                MonoObject *nullable;
 
                                /* 
@@ -1860,12 +1872,12 @@ ves_icall_MonoField_SetValueInternal (MonoReflectionField *field, MonoObject *ob
                }
                default:
                        g_error ("type 0x%x not handled in "
-                                "ves_icall_FieldInfo_SetValueInternal", cf->type->type);
+                                "ves_icall_FieldInfo_SetValueInternal", type->type);
                        return;
                }
        }
 
-       if (cf->type->attrs & FIELD_ATTRIBUTE_STATIC) {
+       if (type->attrs & FIELD_ATTRIBUTE_STATIC) {
                MonoVTable *vtable = mono_class_vtable_full (mono_object_domain (field), cf->parent, TRUE);
                if (!vtable->initialized)
                        mono_runtime_class_init (vtable);
@@ -2322,7 +2334,6 @@ ves_icall_MonoType_GetArrayRank (MonoReflectionType *type)
                mono_raise_exception (mono_get_exception_argument ("type", "Type must be an array type"));
 
        class = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (class);
 
        return class->rank;
 }
@@ -2383,7 +2394,6 @@ ves_icall_Type_GetGenericTypeDefinition_impl (MonoReflectionType *type)
                return NULL;
 
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
 
        if (klass->generic_container) {
                return type; /* check this one */
@@ -3271,7 +3281,6 @@ ves_icall_Type_GetField (MonoReflectionType *type, MonoString *name, guint32 bfl
        int (*compare_func) (const char *s1, const char *s2) = NULL;
        domain = ((MonoObject *)type)->vtable->domain;
        klass = startklass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
 
        if (!name)
                mono_raise_exception (mono_get_exception_argument_null ("name"));
@@ -3285,17 +3294,16 @@ handle_parent:
                mono_raise_exception (mono_class_get_exception_for_failure (klass));
 
        iter = NULL;
-       while ((field = mono_class_get_fields (klass, &iter))) {
+       while ((field = mono_class_get_fields_lazy (klass, &iter))) {
+               guint32 flags = mono_field_get_flags (field);
                match = 0;
 
-               if (field->type == NULL)
-                       continue;
-               if (mono_field_is_deleted (field))
+               if (mono_field_is_deleted_with_flags (field, flags))
                        continue;
-               if ((field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
+               if ((flags & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) == FIELD_ATTRIBUTE_PUBLIC) {
                        if (bflags & BFLAGS_Public)
                                match++;
-               } else if ((klass == startklass) || (field->type->attrs & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) != FIELD_ATTRIBUTE_PRIVATE) {
+               } else if ((klass == startklass) || (flags & FIELD_ATTRIBUTE_FIELD_ACCESS_MASK) != FIELD_ATTRIBUTE_PRIVATE) {
                        if (bflags & BFLAGS_NonPublic) {
                                match++;
                        }
@@ -3303,7 +3311,7 @@ handle_parent:
                if (!match)
                        continue;
                match = 0;
-               if (field->type->attrs & FIELD_ATTRIBUTE_STATIC) {
+               if (flags & FIELD_ATTRIBUTE_STATIC) {
                        if (bflags & BFLAGS_Static)
                                if ((bflags & BFLAGS_FlattenHierarchy) || (klass == startklass))
                                        match++;
@@ -4929,6 +4937,7 @@ fill_reflection_assembly_name (MonoDomain *domain, MonoReflectionAssemblyName *a
        aname->revision = name->revision;
        aname->hashalg = name->hash_alg;
        aname->versioncompat = 1; /* SameMachine (default) */
+       aname->processor_architecture = name->arch;
 
        if (by_default_version)
                MONO_OBJECT_SETREF (aname, version, create_version (domain, name->major, name->minor, name->build, name->revision));
@@ -5779,7 +5788,6 @@ ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
        MONO_ARCH_SAVE_REGS;
 
        klass = mono_class_from_mono_type (type->type);
-       mono_class_init_or_throw (klass);
        check_for_invalid_type (klass);
 
        if (rank == 0) //single dimentional array