Merge pull request #1909 from esdrubal/reflection
[mono.git] / mono / metadata / icall.c
index 6ac14185a1b611f007ed9488ef245e6c9dcdb8ba..6ab999ba126cb69b9da05f76c2ad1ba78591dc3a 100644 (file)
@@ -37,7 +37,6 @@
 #include <mono/metadata/object.h>
 #include <mono/metadata/threads.h>
 #include <mono/metadata/threads-types.h>
-#include <mono/metadata/threadpool.h>
 #include <mono/metadata/threadpool-ms.h>
 #include <mono/metadata/threadpool-ms-io.h>
 #include <mono/metadata/monitor.h>
@@ -66,7 +65,6 @@
 #include <mono/metadata/profiler-private.h>
 #include <mono/metadata/locales.h>
 #include <mono/metadata/filewatcher.h>
-#include <mono/metadata/char-conversions.h>
 #include <mono/metadata/security.h>
 #include <mono/metadata/mono-config.h>
 #include <mono/metadata/cil-coff.h>
@@ -81,7 +79,6 @@
 #include <mono/metadata/file-mmap.h>
 #include <mono/metadata/seq-points-data.h>
 #include <mono/io-layer/io-layer.h>
-#include <mono/utils/strtod.h>
 #include <mono/utils/monobitset.h>
 #include <mono/utils/mono-time.h>
 #include <mono/utils/mono-proclib.h>
@@ -99,6 +96,7 @@
 #include <shlobj.h>
 #endif
 #include "decimal-ms.h"
+#include "number-ms.h"
 
 extern MonoString* ves_icall_System_Environment_GetOSVersionString (void);
 
@@ -120,28 +118,6 @@ mono_class_init_or_throw (MonoClass *klass)
                mono_raise_exception (mono_class_get_exception_for_failure (klass));
 }
 
-/*
- * We expect a pointer to a char, not a string
- */
-ICALL_EXPORT gboolean
-mono_double_ParseImpl (char *ptr, double *result)
-{
-       gchar *endptr = NULL;
-       *result = 0.0;
-
-       if (*ptr){
-               /* mono_strtod () is not thread-safe */
-               mono_mutex_lock (&mono_strtod_mutex);
-               *result = mono_strtod (ptr, &endptr);
-               mono_mutex_unlock (&mono_strtod_mutex);
-       }
-
-       if (!*ptr || (endptr && *endptr))
-               return FALSE;
-       
-       return TRUE;
-}
-
 ICALL_EXPORT MonoObject *
 ves_icall_System_Array_GetValueImpl (MonoObject *this, guint32 pos)
 {
@@ -1185,6 +1161,18 @@ ves_icall_ModuleBuilder_RegisterToken (MonoReflectionModuleBuilder *mb, MonoObje
        mono_image_register_token (mb->dynamic_image, token, obj);
 }
 
+ICALL_EXPORT MonoObject*
+ves_icall_ModuleBuilder_GetRegisteredToken (MonoReflectionModuleBuilder *mb, guint32 token)
+{
+       gpointer obj;
+
+       mono_loader_lock ();
+       obj = mono_g_hash_table_lookup (mb->dynamic_image->tokens, GUINT_TO_POINTER (token));
+       mono_loader_unlock ();
+
+       return obj;
+}
+
 static gboolean
 get_caller (MonoMethod *m, gint32 no, gint32 ilo, gboolean managed, gpointer data)
 {
@@ -2048,6 +2036,14 @@ fill_iface_array (gpointer key, gpointer value, gpointer user_data)
                mono_metadata_free_type (inflated);
 }
 
+static guint
+get_interfaces_hash (gconstpointer v1)
+{
+       MonoClass *k = (MonoClass*)v1;
+
+       return k->type_token;
+}
+
 ICALL_EXPORT MonoArray*
 ves_icall_Type_GetInterfaces (MonoReflectionType* type)
 {
@@ -2057,7 +2053,7 @@ ves_icall_Type_GetInterfaces (MonoReflectionType* type)
        FillIfaceArrayData data = { 0 };
        int len;
 
-       GHashTable *iface_hash = g_hash_table_new (NULL, NULL);
+       GHashTable *iface_hash = g_hash_table_new (get_interfaces_hash, NULL);
 
        if (class->generic_class && class->generic_class->context.class_inst->is_open) {
                data.context = mono_class_get_context (class);
@@ -2505,8 +2501,6 @@ ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type,
         return NULL;
 }
 
-
-
 ICALL_EXPORT MonoReflectionMethod *
 ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *ref_type)
 {
@@ -2525,6 +2519,20 @@ ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *ref_type)
        return mono_method_get_object (mono_object_domain (ref_type), method, method->klass);
 }
 
+ICALL_EXPORT MonoBoolean
+ves_icall_System_RuntimeType_IsTypeExportedToWindowsRuntime (void)
+{
+       mono_set_pending_exception (mono_get_exception_not_implemented (NULL));
+       return FALSE;
+}
+
+ICALL_EXPORT MonoBoolean
+ves_icall_System_RuntimeType_IsWindowsRuntimeObjectType (void)
+{
+       mono_set_pending_exception (mono_get_exception_not_implemented (NULL));
+       return FALSE;
+}
+
 ICALL_EXPORT void
 ves_icall_MonoMethod_GetPInvoke (MonoReflectionMethod *method, int* flags, MonoString** entry_point, MonoString** dll_name)
 {
@@ -3987,10 +3995,6 @@ ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *as
        if (type->type == MONO_TYPE_CLASS) {
                MonoClass *klass = mono_type_get_class (type);
 
-               if (mono_security_enabled () && !klass->exception_type)
-                       /* Some security problems are detected during generic vtable construction */
-                       mono_class_setup_vtable (klass);
-
                /* need to report exceptions ? */
                if (throwOnError && klass->exception_type) {
                        /* report SecurityException (or others) that occured when loading the assembly */
@@ -3998,8 +4002,6 @@ ves_icall_System_Reflection_Assembly_InternalGetType (MonoReflectionAssembly *as
                        mono_loader_clear_error ();
                        mono_set_pending_exception (exc);
                        return NULL;
-               } else if (mono_security_enabled () && klass->exception_type == MONO_EXCEPTION_SECURITY_INHERITANCEDEMAND) {
-                       return NULL;
                }
        }
 
@@ -4920,7 +4922,7 @@ mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **excepti
                if (!exportedOnly || mono_module_type_is_visible (tdef, image, i + 1)) {
                        MonoError error;
                        klass = mono_class_get_checked (image, (i + 1) | MONO_TOKEN_TYPE_DEF, &error);
-                       g_assert (!mono_loader_get_last_error ()); /* Plug any leaks */
+                       mono_loader_assert_no_error (); /* Plug any leaks */
                        
                        if (klass) {
                                mono_array_setref (res, count, mono_type_get_object (domain, &klass->byval_arg));
@@ -5606,11 +5608,17 @@ ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, Mon
        return delegate;
 }
 
-ICALL_EXPORT void
-ves_icall_System_Delegate_SetMulticastInvoke (MonoDelegate *this)
+ICALL_EXPORT MonoMulticastDelegate *
+ves_icall_System_Delegate_AllocDelegateLike_internal (MonoDelegate *delegate)
 {
-       /* Reset the invoke impl to the default one */
-       this->invoke_impl = mono_runtime_create_delegate_trampoline (this->object.vtable->klass);
+       MonoMulticastDelegate *ret;
+
+       g_assert (mono_class_has_parent (mono_object_class (delegate), mono_defaults.multicastdelegate_class));
+
+       ret = (MonoMulticastDelegate*) mono_object_new (mono_object_domain (delegate), mono_object_class (delegate));
+       ret->delegate.invoke_impl = mono_runtime_create_delegate_trampoline (mono_object_class (delegate));
+
+       return ret;
 }
 
 /* System.Buffer */
@@ -6397,12 +6405,12 @@ get_bundled_app_config (void)
        MonoDomain *domain;
        MonoString *file;
        gchar *config_file_name, *config_file_path;
-       gsize len;
+       gsize len, config_file_path_length, config_ext_length;
        gchar *module;
 
        domain = mono_domain_get ();
        file = domain->setup->configuration_file;
-       if (!file)
+       if (!file || file->length == 0)
                return NULL;
 
        // Retrieve config file and remove the extension
@@ -6410,7 +6418,13 @@ get_bundled_app_config (void)
        config_file_path = mono_portability_find_file (config_file_name, TRUE);
        if (!config_file_path)
                config_file_path = config_file_name;
-       len = strlen (config_file_path) - strlen (".config");
+
+       config_file_path_length = strlen (config_file_path);
+       config_ext_length = strlen (".config");
+       if (config_file_path_length <= config_ext_length)
+               return NULL;
+
+       len = config_file_path_length - config_ext_length;
        module = g_malloc0 (len + 1);
        memcpy (module, config_file_path, len);
        // Get the config file from the module name
@@ -6821,20 +6835,6 @@ ves_icall_System_NumberFormatter_GetFormatterTables (guint64 const **mantissas,
        *decHexDigits = Formatter_DecHexDigits;
 }
 
-/* These parameters are "readonly" in corlib/System/Globalization/TextInfo.cs */
-ICALL_EXPORT void
-ves_icall_System_Globalization_TextInfo_GetDataTablePointersLite (
-                                           guint16 const **to_lower_data_low,
-                                           guint16 const **to_lower_data_high,
-                                           guint16 const **to_upper_data_low,
-                                           guint16 const **to_upper_data_high)
-{
-       *to_lower_data_low = ToLowerDataLow;
-       *to_lower_data_high = ToLowerDataHigh;
-       *to_upper_data_low = ToUpperDataLow;
-       *to_upper_data_high = ToUpperDataHigh;
-}
-
 /*
  * We return NULL for no modifiers so the corlib code can return Type.EmptyTypes
  * and avoid useless allocations.
@@ -7054,7 +7054,7 @@ ves_icall_System_StackFrame_GetILOffsetFromFile (MonoString *path, guint32 metho
        guint32 il_offset;
        char *path_str = mono_string_to_utf8 (path);
 
-       if (!seq_point_data_get_il_offset (path_str, method_token, method_index, native_offset, &il_offset))
+       if (!mono_seq_point_data_get_il_offset (path_str, method_token, method_index, native_offset, &il_offset))
                il_offset = -1;
 
        g_free (path_str);