Sat Jan 8 19:03:26 CET 2005 Paolo Molaro <lupus@ximian.com>
[mono.git] / mono / metadata / image.c
index a1ad71dabd6847818d4af96af21d1886366585cd..19aee1acc578ca983a9d281a294282c591a40404 100644 (file)
@@ -475,14 +475,13 @@ load_modules (MonoImage *image, MonoImageOpenStatus *status)
        MonoTableInfo *t;
        int i;
        char *base_dir;
-       MonoImage **modules;
 
        if (image->modules)
                return;
 
        t = &image->tables [MONO_TABLE_MODULEREF];
        image->modules = g_new0 (MonoImage *, t->rows);
-       image->module_count = 0;
+       image->module_count = t->rows;
        base_dir = g_path_get_dirname (image->name);
        for (i = 0; i < t->rows; i++){
                char *module_ref;
@@ -492,9 +491,8 @@ load_modules (MonoImage *image, MonoImageOpenStatus *status)
                mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
                name = mono_metadata_string_heap (image, cols [MONO_MODULEREF_NAME]);
                module_ref = g_build_filename (base_dir, name, NULL);
-               image->modules [image->module_count] = mono_image_open (module_ref, status);
-               if (image->modules [image->module_count]) {
-                       image->module_count ++;
+               image->modules [i] = mono_image_open (module_ref, status);
+               if (image->modules [i]) {
                        /* g_print ("loaded module %s from %s (%p)\n", module_ref, image->name, image->assembly); */
                }
                /* 
@@ -609,14 +607,11 @@ mono_image_init (MonoImage *image)
        image->native_wrapper_cache = g_hash_table_new (NULL, NULL);
        image->remoting_invoke_cache = g_hash_table_new (NULL, NULL);
        image->synchronized_cache = g_hash_table_new (NULL, NULL);
+       image->unbox_wrapper_cache = g_hash_table_new (NULL, NULL);
 
        image->typespec_cache = g_hash_table_new (NULL, NULL);
        image->memberref_signatures = g_hash_table_new (NULL, NULL);
        image->helper_signatures = g_hash_table_new (g_str_hash, g_str_equal);
-
-       image->generic_inst_cache =
-               g_hash_table_new ((GHashFunc)mono_metadata_generic_inst_hash,
-                                 (GCompareFunc)mono_metadata_generic_inst_equal);
 }
 
 static MonoImage *
@@ -927,7 +922,7 @@ mono_image_open (const char *fname, MonoImageOpenStatus *status)
                return image2;
        }
        g_hash_table_insert (loaded_images_hash, image->name, image);
-       if (image->assembly_name)
+       if (image->assembly_name && (g_hash_table_lookup (loaded_images_hash, image->assembly_name) == NULL))
                g_hash_table_insert (loaded_images_hash, (char *) image->assembly_name, image); 
        g_hash_table_insert (loaded_images_guid_hash, image->guid, image);
        LeaveCriticalSection (&images_mutex);
@@ -947,6 +942,12 @@ free_mr_signatures (gpointer key, gpointer val, gpointer user_data)
        mono_metadata_free_method_signature ((MonoMethodSignature*)val);
 }
 
+static void
+free_remoting_wrappers (gpointer key, gpointer val, gpointer user_data)
+{
+       g_free (val);
+}
+
 /**
  * mono_image_addref:
  * @image: The image file we wish to add a reference to
@@ -982,12 +983,12 @@ mono_image_close (MonoImage *image)
        if (image == image2) {
                /* This is not true if we are called from mono_image_open () */
                g_hash_table_remove (loaded_images_hash, image->name);
-               if (image->assembly_name)
-                       g_hash_table_remove (loaded_images_hash, (char *) image->assembly_name);        
                g_hash_table_remove (loaded_images_guid_hash, image->guid);
                /* Multiple images might have the same guid */
                build_guid_table ();
-       }       
+       }
+       if (image->assembly_name && (g_hash_table_lookup (loaded_images_hash, image->assembly_name) == image))
+               g_hash_table_remove (loaded_images_hash, (char *) image->assembly_name);        
        LeaveCriticalSection (&images_mutex);
 
        if (image->f)
@@ -1009,6 +1010,7 @@ mono_image_close (MonoImage *image)
                g_free (image->raw_data);
        }
        g_free (image->name);
+       g_free (image->guid);
        g_free (image->files);
 
        g_hash_table_destroy (image->method_cache);
@@ -1022,10 +1024,12 @@ mono_image_close (MonoImage *image)
        g_hash_table_destroy (image->delegate_begin_invoke_cache);
        g_hash_table_destroy (image->delegate_end_invoke_cache);
        g_hash_table_destroy (image->delegate_invoke_cache);
+       g_hash_table_foreach (image->remoting_invoke_cache, free_remoting_wrappers, NULL);
        g_hash_table_destroy (image->remoting_invoke_cache);
        g_hash_table_destroy (image->runtime_invoke_cache);
+       g_hash_table_destroy (image->synchronized_cache);
+       g_hash_table_destroy (image->unbox_wrapper_cache);
        g_hash_table_destroy (image->typespec_cache);
-       g_hash_table_destroy (image->generic_inst_cache);
        g_hash_table_foreach (image->memberref_signatures, free_mr_signatures, NULL);
        g_hash_table_destroy (image->memberref_signatures);
        g_hash_table_foreach (image->helper_signatures, free_mr_signatures, NULL);
@@ -1357,7 +1361,7 @@ mono_image_get_table_rows (MonoImage *image, int table_id)
 }
 
 int
-mono_table_info_get_rows (MonoTableInfo *table)
+mono_table_info_get_rows (const MonoTableInfo *table)
 {
        return table->rows;
 }
@@ -1374,4 +1378,12 @@ mono_image_is_dynamic (MonoImage *image)
        return image->dynamic;
 }
 
-
+gboolean
+mono_image_has_authenticode_entry (MonoImage *image)
+{
+       MonoCLIImageInfo *iinfo = image->image_info;
+       MonoDotNetHeader *header = &iinfo->cli_header;
+       MonoPEDirEntry *de = &header->datadir.pe_certificate_table;
+       // the Authenticode "pre" (non ASN.1) header is 8 bytes long
+       return ((de->rva != 0) && (de->size > 8));
+}