2005-02-21 Martin Baulig <martin@ximian.com>
authorMartin Baulig <martin@novell.com>
Mon, 21 Feb 2005 17:38:38 +0000 (17:38 -0000)
committerMartin Baulig <martin@novell.com>
Mon, 21 Feb 2005 17:38:38 +0000 (17:38 -0000)
* reflection.c (mono_image_build_metadata): We also need to
"fixup" the MethodImpl table after we computed the final method
indices.  Call fixup_methodimpl() to do that.
(fixup_methodimpl): New private method.

svn path=/trunk/mono/; revision=41007

mono/metadata/ChangeLog
mono/metadata/reflection.c

index 940d2fbb5f56f17b7b759570b9c76045970d4964..8abe17fcaae90aebb53ec44da7e725211abf9b37 100644 (file)
@@ -1,3 +1,9 @@
+2005-02-21  Martin Baulig  <martin@ximian.com>
+
+       * reflection.c (mono_image_build_metadata): We also need to
+       "fixup" the MethodImpl table after we computed the final method
+       indices.  Call fixup_methodimpl() to do that.
+       (fixup_methodimpl): New private method.
 
 Mon Feb 21 16:17:14 CET 2005 Paolo Molaro <lupus@ximian.com>
 
index 5e6f2965b36fcbc429e6ee5230f361217a363737..1982bb2ad8751b107781366458d826f928a091da 100644 (file)
@@ -3612,6 +3612,42 @@ fixup_cattrs (MonoDynamicImage *assembly)
        }
 }
 
+/*
+ * fixup_methodimpl:
+ *
+ * The METHODIMPL table might contain METHODDEF tokens whose final
+ * value is not known when the table is emitted.
+ */
+static void
+fixup_methodimpl (MonoDynamicImage *assembly)
+{
+       MonoDynamicTable *table;
+       guint32 *values;
+       guint32 decl, i, idx, token;
+       MonoObject *method;
+
+       table = &assembly->tables [MONO_TABLE_METHODIMPL];
+
+       for (i = 0; i < table->rows; ++i) {
+               values = table->values + ((i + 1) * MONO_METHODIMPL_SIZE);
+               decl = values [MONO_METHODIMPL_DECLARATION];
+
+               idx = decl >> MONO_METHODDEFORREF_BITS;
+               if ((decl & MONO_METHODDEFORREF_MASK) != MONO_METHODDEFORREF_METHODDEF)
+                       continue;
+
+               token = mono_metadata_make_token (MONO_TABLE_METHOD, idx);
+               method = mono_g_hash_table_lookup (assembly->tokens, GUINT_TO_POINTER (token));
+               g_assert (method);
+
+               if (!strcmp (method->vtable->klass->name, "MethodBuilder")) {
+                       token = mono_image_create_token (assembly, method, FALSE);
+                       idx = mono_metadata_token_index (token);
+                       values [MONO_METHODIMPL_DECLARATION] = (idx << MONO_METHODDEFORREF_BITS) | MONO_METHODDEFORREF_METHODDEF;
+               }
+       }
+}
+
 static void
 assembly_add_resource_manifest (MonoReflectionModuleBuilder *mb, MonoDynamicImage *assembly, MonoReflectionResource *rsrc, guint32 implementation)
 {
@@ -3929,6 +3965,7 @@ mono_image_build_metadata (MonoReflectionModuleBuilder *moduleb)
        /* fixup tokens */
        mono_g_hash_table_foreach (assembly->token_fixups, (GHFunc)fixup_method, assembly);
        fixup_cattrs (assembly);
+       fixup_methodimpl (assembly);
 }
 
 /*