Revert until Martin is online to debug
[mono.git] / mono / metadata / appdomain.c
index 46018c42a3c11c7dbdf5d28fef1b970009f11813..6e2e54a3f6e0cbf13de6fb6ab7c4f7987f7fdcd8 100644 (file)
@@ -29,8 +29,9 @@
 #include <mono/metadata/monitor.h>
 #include <mono/metadata/threadpool.h>
 #include <mono/utils/mono-uri.h>
+#include <mono/utils/mono-logger.h>
 
-#define MONO_CORLIB_VERSION 44
+#define MONO_CORLIB_VERSION 53
 
 CRITICAL_SECTION mono_delegate_section;
 
@@ -200,7 +201,11 @@ mono_runtime_cleanup (MonoDomain *domain)
        /* This ends up calling any pending pending (for at most 2 seconds) */
        mono_gc_cleanup ();
 
+       mono_thread_cleanup ();
+
        mono_network_cleanup ();
+
+       mono_marshal_cleanup ();
 }
 
 static MonoDomainFunc quit_function = NULL;
@@ -349,13 +354,15 @@ mono_domain_set (MonoDomain *domain, gboolean force)
 MonoObject *
 ves_icall_System_AppDomain_GetData (MonoAppDomain *ad, MonoString *name)
 {
-       MonoDomain *add = ad->data;
+       MonoDomain *add;
        MonoObject *o;
        char *str;
 
        MONO_ARCH_SAVE_REGS;
 
        g_assert (ad != NULL);
+       add = ad->data;
+       g_assert (add != NULL);
 
        if (name == NULL)
                mono_raise_exception (mono_get_exception_argument_null ("name"));
@@ -397,11 +404,13 @@ ves_icall_System_AppDomain_GetData (MonoAppDomain *ad, MonoString *name)
 void
 ves_icall_System_AppDomain_SetData (MonoAppDomain *ad, MonoString *name, MonoObject *data)
 {
-       MonoDomain *add = ad->data;
+       MonoDomain *add;
 
        MONO_ARCH_SAVE_REGS;
 
        g_assert (ad != NULL);
+       add = ad->data;
+       g_assert (add != NULL);
 
        if (name == NULL)
                mono_raise_exception (mono_get_exception_argument_null ("name"));
@@ -481,7 +490,8 @@ ves_icall_System_AppDomain_createDomain (MonoString *friendly_name, MonoAppDomai
        if (!setup->application_base) {
                /* Inherit from the root domain since MS.NET does this */
                MonoDomain *root = mono_get_root_domain ();
-               setup->application_base = mono_string_new_utf16 (data, mono_string_chars (root->setup->application_base), mono_string_length (root->setup->application_base));
+               if (root->setup->application_base)
+                       MONO_OBJECT_SETREF (setup, application_base, mono_string_new_utf16 (data, mono_string_chars (root->setup->application_base), mono_string_length (root->setup->application_base)));
        }
 
        mono_context_init (data);
@@ -530,7 +540,7 @@ ves_icall_System_AppDomain_GetAssemblies (MonoAppDomain *ad, MonoBoolean refonly
                        continue;
                if (ass->corlib_internal)
                        continue;
-               mono_array_set (res, gpointer, i, mono_assembly_get_object (domain, ass));
+               mono_array_setref (res, i, mono_assembly_get_object (domain, ass));
                ++i;
        }
        mono_domain_assemblies_unlock (domain);
@@ -611,6 +621,7 @@ add_assemblies_to_domain (MonoDomain *domain, MonoAssembly *ass, GHashTable *ht)
                mono_assembly_addref (ass);
                g_hash_table_insert (ht, ass, ass);
                domain->domain_assemblies = g_slist_prepend (domain->domain_assemblies, ass);
+               mono_trace (G_LOG_LEVEL_INFO, MONO_TRACE_ASSEMBLY, "Assembly %s %p added to domain %s, ref_count=%d\n", ass->aname.name, ass, domain->friendly_name, ass->ref_count);
        }
 
        if (ass->image->references) {
@@ -967,13 +978,19 @@ ves_icall_System_Reflection_Assembly_LoadFrom (MonoString *fname, MonoBoolean re
 
        ass = mono_assembly_open_full (filename, &status, refOnly);
        
-       g_free (name);
-
        if (!ass){
-               MonoException *exc = mono_get_exception_file_not_found (fname);
+               MonoException *exc;
+
+               if (status == MONO_IMAGE_IMAGE_INVALID)
+                       exc = mono_get_exception_bad_image_format (name);
+               else
+                       exc = mono_get_exception_file_not_found (fname);
+               g_free (name);
                mono_raise_exception (exc);
        }
 
+       g_free (name);
+
        return mono_assembly_get_object (domain, ass);
 }
 
@@ -1007,7 +1024,7 @@ ves_icall_System_AppDomain_LoadAssemblyRaw (MonoAppDomain *ad,
        }
 
        refass = mono_assembly_get_object (domain, ass);
-       refass->evidence = evidence;
+       MONO_OBJECT_SETREF (refass, evidence, evidence);
        return refass;
 }
 
@@ -1050,7 +1067,7 @@ ves_icall_System_AppDomain_LoadAssembly (MonoAppDomain *ad,  MonoString *assRef,
        if (refass == NULL)
                refass = mono_assembly_get_object (domain, ass);
 
-       refass->evidence = evidence;
+       MONO_OBJECT_SETREF (refass, evidence, evidence);
        return refass;
 }
 
@@ -1123,7 +1140,7 @@ ves_icall_System_AppDomain_ExecuteAssembly (MonoAppDomain *ad, MonoString *file,
                args = (MonoArray *) mono_array_new (ad->data, mono_defaults.string_class, 0);
 
        refass = mono_assembly_get_object (ad->data, assembly);
-       refass->evidence = evidence;
+       MONO_OBJECT_SETREF (refass, evidence, evidence);
 
        res = mono_runtime_exec_main (method, (MonoArray *)args, NULL);