Author: zoltan
Date: 2007-04-24 12:47:28 -0400 (Tue, 24 Apr 2007)
New Revision: 76203
Modified:
trunk/mono/mono/metadata/ChangeLog
trunk/mono/mono/metadata/assembly.c
trunk/mono/mono/metadata/class.c
trunk/mono/mono/metadata/icall-def.h
trunk/mono/mono/metadata/image.c
trunk/mono/mono/metadata/image.h
trunk/mono/mono/metadata/metadata-internals.h
trunk/mono/mono/metadata/object-internals.h
trunk/mono/mono/metadata/reflection.c
Log:
2007-04-24 Zoltan Varga <[EMAIL PROTECTED]>
* image.c (mono_image_load_module): New API function to load a module
reference.
* image.c (load_modules): Load modules lazily. Fixes #80812.
* class.c (mono_class_from_typeref): Use mono_image_load_module.
* reflection.c (mono_image_load_module_dynamic): Copy
image->modules_loaded too.
* object-internals.h reflection.c icall-def.h (mono_image_load_module):
Rename this
to mono_image_load_module_dynamic.
Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog 2007-04-24 16:41:45 UTC (rev 76202)
+++ trunk/mono/mono/metadata/ChangeLog 2007-04-24 16:47:28 UTC (rev 76203)
@@ -1,3 +1,16 @@
+2007-04-24 Zoltan Varga <[EMAIL PROTECTED]>
+
+ * image.c (mono_image_load_module): New API function to load a module
reference.
+
+ * image.c (load_modules): Load modules lazily. Fixes #80812.
+
+ * class.c (mono_class_from_typeref): Use mono_image_load_module.
+
+ * reflection.c (mono_image_load_module_dynamic): Copy
image->modules_loaded too.
+
+ * object-internals.h reflection.c icall-def.h (mono_image_load_module):
Rename this
+ to mono_image_load_module_dynamic.
+
2007-04-23 Jonathan Chambers <[EMAIL PROTECTED]>
* marshal.c: Fix calling convention for CCW on non-windows
Modified: trunk/mono/mono/metadata/assembly.c
===================================================================
--- trunk/mono/mono/metadata/assembly.c 2007-04-24 16:41:45 UTC (rev 76202)
+++ trunk/mono/mono/metadata/assembly.c 2007-04-24 16:47:28 UTC (rev 76203)
@@ -855,6 +855,8 @@
* it inside a critical section.
*/
mono_assemblies_lock ();
+ if (!image->references)
+ mono_assembly_load_references (image, &status);
reference = image->references [index];
mono_assemblies_unlock ();
if (reference)
@@ -932,21 +934,12 @@
mono_assembly_load_references (MonoImage *image, MonoImageOpenStatus *status)
{
MonoTableInfo *t;
- int i;
*status = MONO_IMAGE_OK;
t = &image->tables [MONO_TABLE_ASSEMBLYREF];
image->references = g_new0 (MonoAssembly *, t->rows + 1);
-
- /* resolve assembly references for modules */
- for (i = 0; i < image->module_count; i++){
- if (image->modules [i]) {
- image->modules [i]->assembly = image->assembly;
- mono_assembly_load_references (image->modules [i],
status);
- }
- }
}
typedef struct AssemblyLoadHook AssemblyLoadHook;
Modified: trunk/mono/mono/metadata/class.c
===================================================================
--- trunk/mono/mono/metadata/class.c 2007-04-24 16:41:45 UTC (rev 76202)
+++ trunk/mono/mono/metadata/class.c 2007-04-24 16:47:28 UTC (rev 76203)
@@ -65,7 +65,7 @@
guint32 idx;
const char *name, *nspace;
MonoClass *res;
- MonoAssembly **references;
+ MonoImage *module;
mono_metadata_decode_row (t, (type_token&0xffffff)-1, cols,
MONO_TYPEREF_SIZE);
@@ -80,8 +80,9 @@
/* a typedef in disguise */
return mono_class_from_name (image, nspace, name);
case MONO_RESOLTION_SCOPE_MODULEREF:
- if (image->modules [idx-1])
- return mono_class_from_name (image->modules [idx - 1],
nspace, name);
+ module = mono_image_load_module (image, idx);
+ if (module)
+ return mono_class_from_name (module, nspace, name);
else {
char *msg = g_strdup_printf ("%s%s%s", nspace, nspace
[0] ? "." : "", name);
char *human_name;
@@ -125,15 +126,12 @@
break;
}
- references = image->references;
- if (!references [idx - 1])
+ if (!image->references || !image->references [idx - 1])
mono_assembly_load_reference (image, idx - 1);
- /* If this assert fails, it probably means that you haven't installed
an assembly load/search hook */
- g_assert (references == image->references);
- g_assert (references [idx - 1]);
+ g_assert (image->references [idx - 1]);
/* If the assembly did not load, register this as a type load exception
*/
- if (references [idx - 1] == REFERENCE_MISSING){
+ if (image->references [idx - 1] == REFERENCE_MISSING){
MonoAssemblyName aname;
char *human_name;
@@ -145,7 +143,7 @@
return NULL;
}
- return mono_class_from_name (references [idx - 1]->image, nspace, name);
+ return mono_class_from_name (image->references [idx - 1]->image,
nspace, name);
}
static inline MonoType*
Modified: trunk/mono/mono/metadata/icall-def.h
===================================================================
--- trunk/mono/mono/metadata/icall-def.h 2007-04-24 16:41:45 UTC (rev
76202)
+++ trunk/mono/mono/metadata/icall-def.h 2007-04-24 16:47:28 UTC (rev
76203)
@@ -423,7 +423,7 @@
ICALL(ASSEMN_1, "ParseName",
ves_icall_System_Reflection_AssemblyName_ParseName)
ICALL_TYPE(ASSEMB, "System.Reflection.Emit.AssemblyBuilder", ASSEMB_1)
-ICALL(ASSEMB_1, "InternalAddModule", mono_image_load_module)
+ICALL(ASSEMB_1, "InternalAddModule", mono_image_load_module_dynamic)
ICALL(ASSEMB_2, "basic_init", mono_image_basic_init)
ICALL_TYPE(CATTRB, "System.Reflection.Emit.CustomAttributeBuilder", CATTRB_1)
Modified: trunk/mono/mono/metadata/image.c
===================================================================
--- trunk/mono/mono/metadata/image.c 2007-04-24 16:41:45 UTC (rev 76202)
+++ trunk/mono/mono/metadata/image.c 2007-04-24 16:47:28 UTC (rev 76203)
@@ -472,17 +472,39 @@
}
static void
-load_modules (MonoImage *image, MonoImageOpenStatus *status)
+load_modules (MonoImage *image)
{
MonoTableInfo *t;
+
+ if (image->modules)
+ return;
+
+ t = &image->tables [MONO_TABLE_MODULEREF];
+ image->modules = g_new0 (MonoImage *, t->rows);
+ image->modules_loaded = g_new0 (gboolean, t->rows);
+ image->module_count = t->rows;
+}
+
+/**
+ * mono_image_load_module:
+ *
+ * Load the module with the one-based index IDX from IMAGE and return it.
Return NULL if
+ * it cannot be loaded.
+ */
+MonoImage*
+mono_image_load_module (MonoImage *image, int idx)
+{
+ MonoTableInfo *t;
MonoTableInfo *file_table;
int i;
char *base_dir;
gboolean refonly = image->ref_only;
GList *list_iter, *valid_modules = NULL;
+ MonoImageOpenStatus status;
- if (image->modules)
- return;
+ g_assert (idx <= image->module_count);
+ if (image->modules_loaded [idx - 1])
+ return image->modules [idx - 1];
file_table = &image->tables [MONO_TABLE_FILE];
for (i = 0; i < file_table->rows; i++) {
@@ -494,17 +516,16 @@
}
t = &image->tables [MONO_TABLE_MODULEREF];
- image->modules = g_new0 (MonoImage *, t->rows);
- image->module_count = t->rows;
base_dir = g_path_get_dirname (image->name);
- for (i = 0; i < t->rows; i++){
+
+ {
char *module_ref;
const char *name;
guint32 cols [MONO_MODULEREF_SIZE];
/* if there is no file table, we try to load the module... */
int valid = file_table->rows == 0;
- mono_metadata_decode_row (t, i, cols, MONO_MODULEREF_SIZE);
+ mono_metadata_decode_row (t, idx - 1, cols,
MONO_MODULEREF_SIZE);
name = mono_metadata_string_heap (image, cols
[MONO_MODULEREF_NAME]);
for (list_iter = valid_modules; list_iter; list_iter =
list_iter->next) {
/* be safe with string dups, but we could just compare
string indexes */
@@ -513,24 +534,24 @@
break;
}
}
- if (!valid)
- continue;
- module_ref = g_build_filename (base_dir, name, NULL);
- image->modules [i] = mono_image_open_full (module_ref, status,
refonly);
- if (image->modules [i]) {
- mono_image_addref (image->modules [i]);
- /* g_print ("loaded module %s from %s (%p)\n",
module_ref, image->name, image->assembly); */
+ if (valid) {
+ module_ref = g_build_filename (base_dir, name, NULL);
+ image->modules [idx - 1] = mono_image_open_full
(module_ref, &status, refonly);
+ if (image->modules [idx - 1]) {
+ mono_image_addref (image->modules [idx - 1]);
+ image->modules [idx - 1]->assembly =
image->assembly;
+ /* g_print ("loaded module %s from %s (%p)\n",
module_ref, image->name, image->assembly); */
+ }
+ g_free (module_ref);
}
- /*
- * FIXME: We should probably do lazy-loading of modules.
- */
- if (status)
- *status = MONO_IMAGE_OK;
- g_free (module_ref);
}
+ image->modules_loaded [idx - 1] = TRUE;
+
g_free (base_dir);
g_list_free (valid_modules);
+
+ return image->modules [idx - 1];
}
static void
@@ -745,7 +766,7 @@
mono_metadata_decode_row_col (&image->tables
[MONO_TABLE_MODULE],
0, MONO_MODULE_NAME));
- load_modules (image, status);
+ load_modules (image);
done:
if (status)
Modified: trunk/mono/mono/metadata/image.h
===================================================================
--- trunk/mono/mono/metadata/image.h 2007-04-24 16:41:45 UTC (rev 76202)
+++ trunk/mono/mono/metadata/image.h 2007-04-24 16:47:28 UTC (rev 76203)
@@ -63,6 +63,8 @@
const char *mono_image_get_resource (MonoImage *image, guint32 offset,
guint32 *size);
MonoImage* mono_image_load_file_for_image (MonoImage *image, int fileidx);
+MonoImage* mono_image_load_module (MonoImage *image, int idx);
+
const char* mono_image_get_name (MonoImage *image);
const char* mono_image_get_filename (MonoImage *image);
const char * mono_image_get_guid (MonoImage *image);
Modified: trunk/mono/mono/metadata/metadata-internals.h
===================================================================
--- trunk/mono/mono/metadata/metadata-internals.h 2007-04-24 16:41:45 UTC
(rev 76202)
+++ trunk/mono/mono/metadata/metadata-internals.h 2007-04-24 16:47:28 UTC
(rev 76203)
@@ -126,6 +126,7 @@
MonoImage **modules;
guint32 module_count;
+ gboolean *modules_loaded;
MonoImage **files;
Modified: trunk/mono/mono/metadata/object-internals.h
===================================================================
--- trunk/mono/mono/metadata/object-internals.h 2007-04-24 16:41:45 UTC (rev
76202)
+++ trunk/mono/mono/metadata/object-internals.h 2007-04-24 16:47:28 UTC (rev
76203)
@@ -1051,7 +1051,7 @@
void mono_image_create_pefile (MonoReflectionModuleBuilder *module,
HANDLE file) MONO_INTERNAL;
void mono_image_basic_init (MonoReflectionAssemblyBuilder *assembly)
MONO_INTERNAL;
-MonoReflectionModule * mono_image_load_module (MonoReflectionAssemblyBuilder
*assembly, MonoString *file_name) MONO_INTERNAL;
+MonoReflectionModule * mono_image_load_module_dynamic
(MonoReflectionAssemblyBuilder *assembly, MonoString *file_name) MONO_INTERNAL;
guint32 mono_image_insert_string (MonoReflectionModuleBuilder *module,
MonoString *str) MONO_INTERNAL;
guint32 mono_image_create_token (MonoDynamicImage *assembly, MonoObject
*obj, gboolean create_methodspec) MONO_INTERNAL;
guint32 mono_image_create_method_token (MonoDynamicImage *assembly,
MonoObject *obj, MonoArray *opt_param_types) MONO_INTERNAL;
Modified: trunk/mono/mono/metadata/reflection.c
===================================================================
--- trunk/mono/mono/metadata/reflection.c 2007-04-24 16:41:45 UTC (rev
76202)
+++ trunk/mono/mono/metadata/reflection.c 2007-04-24 16:47:28 UTC (rev
76203)
@@ -4999,7 +4999,7 @@
}
MonoReflectionModule *
-mono_image_load_module (MonoReflectionAssemblyBuilder *ab, MonoString
*fileName)
+mono_image_load_module_dynamic (MonoReflectionAssemblyBuilder *ab, MonoString
*fileName)
{
char *name;
MonoImage *image;
@@ -5007,6 +5007,7 @@
MonoDynamicAssembly *assembly;
guint32 module_count;
MonoImage **new_modules;
+ gboolean *new_modules_loaded;
name = mono_string_to_utf8 (fileName);
@@ -5028,14 +5029,19 @@
module_count = image->assembly->image->module_count;
new_modules = g_new0 (MonoImage *, module_count + 1);
+ new_modules_loaded = g_new0 (gboolean, module_count + 1);
- if (image->assembly->image->modules)
+ if (image->assembly->image->modules) {
memcpy (new_modules, image->assembly->image->modules,
module_count * sizeof (MonoImage *));
+ memcpy (new_modules_loaded,
image->assembly->image->modules_loaded, module_count * sizeof (gboolean));
+ }
new_modules [module_count] = image;
+ new_modules_loaded [module_count] = TRUE;
mono_image_addref (image);
g_free (image->assembly->image->modules);
image->assembly->image->modules = new_modules;
+ image->assembly->image->modules_loaded = new_modules_loaded;
image->assembly->image->module_count ++;
mono_assembly_load_references (image, &status);
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches