Merge pull request #1696 from esdrubal/tzrefactor
[mono.git] / mono / metadata / icall.c
index 594a9367803a3ba4b5f116a8dbdd4cf38e764d18..6ac14185a1b611f007ed9488ef245e6c9dcdb8ba 100644 (file)
@@ -2525,14 +2525,12 @@ ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *ref_type)
        return mono_method_get_object (mono_object_domain (ref_type), method, method->klass);
 }
 
-ICALL_EXPORT MonoReflectionDllImportAttribute*
-ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
+ICALL_EXPORT void
+ves_icall_MonoMethod_GetPInvoke (MonoReflectionMethod *method, int* flags, MonoString** entry_point, MonoString** dll_name)
 {
-       static MonoClass *DllImportAttributeClass = NULL;
        MonoDomain *domain = mono_domain_get ();
-       MonoReflectionDllImportAttribute *attr;
-       MonoImage *image = method->klass->image;
-       MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)method;
+       MonoImage *image = method->method->klass->image;
+       MonoMethodPInvoke *piinfo = (MonoMethodPInvoke *)method->method;
        MonoTableInfo *tables = image->tables;
        MonoTableInfo *im = &tables [MONO_TABLE_IMPLMAP];
        MonoTableInfo *mr = &tables [MONO_TABLE_MODULEREF];
@@ -2540,22 +2538,10 @@ ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
        guint32 scope_token;
        const char *import = NULL;
        const char *scope = NULL;
-       guint32 flags;
-
-       if (!(method->flags & METHOD_ATTRIBUTE_PINVOKE_IMPL))
-               return NULL;
 
-       if (!DllImportAttributeClass) {
-               DllImportAttributeClass = 
-                       mono_class_from_name (mono_defaults.corlib,
-                                                                 "System.Runtime.InteropServices", "DllImportAttribute");
-               g_assert (DllImportAttributeClass);
-       }
-                                                                                                               
-       if (image_is_dynamic (method->klass->image)) {
+       if (image_is_dynamic (image)) {
                MonoReflectionMethodAux *method_aux = 
-                       g_hash_table_lookup (
-                                                                         ((MonoDynamicImage*)method->klass->image)->method_aux_hash, method);
+                       g_hash_table_lookup (((MonoDynamicImage*)image)->method_aux_hash, method->method);
                if (method_aux) {
                        import = method_aux->dllentry;
                        scope = method_aux->dll;
@@ -2563,7 +2549,7 @@ ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
 
                if (!import || !scope) {
                        mono_set_pending_exception (mono_get_exception_argument ("method", "System.Reflection.Emit method with invalid pinvoke information"));
-                       return NULL;
+                       return;
                }
        }
        else {
@@ -2576,23 +2562,10 @@ ves_icall_MonoMethod_GetDllImportAttribute (MonoMethod *method)
                        scope = mono_metadata_string_heap (image, scope_token);
                }
        }
-       flags = piinfo->piflags;
        
-       attr = (MonoReflectionDllImportAttribute*)mono_object_new (domain, DllImportAttributeClass);
-
-       MONO_OBJECT_SETREF (attr, dll, mono_string_new (domain, scope));
-       MONO_OBJECT_SETREF (attr, entry_point, mono_string_new (domain, import));
-       attr->call_conv = (flags & 0x700) >> 8;
-       attr->charset = ((flags & 0x6) >> 1) + 1;
-       if (attr->charset == 1)
-               attr->charset = 2;
-       attr->exact_spelling = (flags & 0x1) != 0;
-       attr->set_last_error = (flags & 0x40) != 0;
-       attr->best_fit_mapping = (flags & 0x30) == 0x10;
-       attr->throw_on_unmappable = (flags & 0x3000) == 0x1000;
-       attr->preserve_sig = FALSE;
-
-       return attr;
+       *flags = piinfo->piflags;
+       *entry_point = mono_string_new (domain, import);
+       *dll_name = mono_string_new (domain, scope);
 }
 
 ICALL_EXPORT MonoReflectionMethod *
@@ -2790,15 +2763,19 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
 
                if (m->klass->rank == pcount) {
                        /* Only lengths provided. */
-                       lower_bounds = NULL;
+                       return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, NULL);
                } else {
                        g_assert (pcount == (m->klass->rank * 2));
-                       /* lower bounds are first. */
-                       lower_bounds = (intptr_t*)lengths;
-                       lengths += m->klass->rank;
-               }
+                       /* The arguments are lower-bound-length pairs */
+                       lower_bounds = g_alloca (sizeof (intptr_t) * pcount);
 
-               return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
+                       for (i = 0; i < pcount / 2; ++i) {
+                               lower_bounds [i] = *(int32_t*) ((char*)mono_array_get (params, gpointer, (i * 2)) + sizeof (MonoObject));
+                               lengths [i] = *(int32_t*) ((char*)mono_array_get (params, gpointer, (i * 2) + 1) + sizeof (MonoObject));
+                       }
+
+                       return (MonoObject*)mono_array_new_full (mono_object_domain (params), m->klass, lengths, lower_bounds);
+               }
        }
        return mono_runtime_invoke_array (m, obj, params, NULL);
 }
@@ -6217,6 +6194,12 @@ ves_icall_System_Environment_BroadcastSettingChange (void)
 #endif
 }
 
+ICALL_EXPORT gint32
+ves_icall_System_Runtime_Versioning_VersioningHelper_GetRuntimeId (void)
+{
+       return 9;
+}
+
 ICALL_EXPORT void
 ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this, 
                                         MonoReflectionMethod *method,