Author: kumpera
Date: 2007-10-04 16:42:54 -0400 (Thu, 04 Oct 2007)
New Revision: 86912
Modified:
trunk/mono/mono/metadata/ChangeLog
trunk/mono/mono/metadata/reflection.c
Log:
2007-10-04 Rodrigo Kumpera <[EMAIL PROTECTED]>
* reflection.c: Fix the encoding of generic type definition for
TypeBuilders.
* reflection.c (mono_image_typedef_or_ref_full: do the same thing as
mono_image_typedef_or_ref but allows to specify if typespec lookups
should
be made. Typespec check is done prior to typeref cache lookup.
* reflection.c (mono_image_typedef_or_ref): now just delegate to
mono_image_typedef_or_ref_full.
* reflection.c (encode_generic_class): encode the generic class
directly instead of calling encode_type.
* reflection.c (encode_type): encode the generic type definition
MonoClass as a generic instantiation.
* reflection.c (create_typespec): cache typespec tokens in
the assembly->typespec cache. Don't create typespec for a generic
instance MonoClass. Create typespec for the generic type defintion.
* reflection.c (create_generic_typespec): encode the generic
class directly instead of calling encode_type.
* reflection.c (mono_image_create_token): encode the generic
type definition not using a typespec for MonoType instances.
Modified: trunk/mono/mono/metadata/ChangeLog
===================================================================
--- trunk/mono/mono/metadata/ChangeLog 2007-10-04 20:26:54 UTC (rev 86911)
+++ trunk/mono/mono/metadata/ChangeLog 2007-10-04 20:42:54 UTC (rev 86912)
@@ -1,3 +1,32 @@
+2007-10-04 Rodrigo Kumpera <[EMAIL PROTECTED]>
+
+ * reflection.c: Fix the encoding of generic type definition for
+ TypeBuilders.
+
+ * reflection.c (mono_image_typedef_or_ref_full: do the same thing as
+ mono_image_typedef_or_ref but allows to specify if typespec lookups
should
+ be made. Typespec check is done prior to typeref cache lookup.
+
+ * reflection.c (mono_image_typedef_or_ref): now just delegate to
+ mono_image_typedef_or_ref_full.
+
+ * reflection.c (encode_generic_class): encode the generic class
+ directly instead of calling encode_type.
+
+ * reflection.c (encode_type): encode the generic type definition
+ MonoClass as a generic instantiation.
+
+ * reflection.c (create_typespec): cache typespec tokens in
+ the assembly->typespec cache. Don't create typespec for a generic
+ instance MonoClass. Create typespec for the generic type defintion.
+
+ * reflection.c (create_generic_typespec): encode the generic
+ class directly instead of calling encode_type.
+
+ * reflection.c (mono_image_create_token): encode the generic
+ type definition not using a typespec for MonoType instances.
+
+
2007-10-04 Raja R Harinath <[EMAIL PROTECTED]>
Fix #328812
Modified: trunk/mono/mono/metadata/reflection.c
===================================================================
--- trunk/mono/mono/metadata/reflection.c 2007-10-04 20:26:54 UTC (rev
86911)
+++ trunk/mono/mono/metadata/reflection.c 2007-10-04 20:42:54 UTC (rev
86912)
@@ -134,6 +134,7 @@
static void reflection_methodbuilder_from_method_builder
(ReflectionMethodBuilder *rmb, MonoReflectionMethodBuilder *mb);
static void reflection_methodbuilder_from_ctor_builder
(ReflectionMethodBuilder *rmb, MonoReflectionCtorBuilder *mb);
static guint32 mono_image_typedef_or_ref (MonoDynamicImage *assembly, MonoType
*type);
+static guint32 mono_image_typedef_or_ref_full (MonoDynamicImage *assembly,
MonoType *type, gboolean try_typespec);
static guint32 mono_image_get_methodref_token (MonoDynamicImage *assembly,
MonoMethod *method);
static guint32 mono_image_get_methodbuilder_token (MonoDynamicImage *assembly,
MonoReflectionMethodBuilder *mb);
static guint32 mono_image_get_ctorbuilder_token (MonoDynamicImage *assembly,
MonoReflectionCtorBuilder *cb);
@@ -580,13 +581,17 @@
{
int i;
MonoGenericInst *class_inst;
+ MonoClass *klass;
g_assert (gclass);
class_inst = gclass->context.class_inst;
sigbuffer_add_value (buf, MONO_TYPE_GENERICINST);
- encode_type (assembly, &gclass->container_class->byval_arg, buf);
+ klass = gclass->container_class;
+ sigbuffer_add_value (buf, klass->byval_arg.type);
+ sigbuffer_add_value (buf, mono_image_typedef_or_ref_full (assembly,
&klass->byval_arg, FALSE));
+
sigbuffer_add_value (buf, class_inst->type_argc);
for (i = 0; i < class_inst->type_argc; ++i)
encode_type (assembly, class_inst->type_argv [i], buf);
@@ -636,16 +641,22 @@
case MONO_TYPE_VALUETYPE:
case MONO_TYPE_CLASS: {
MonoClass *k = mono_class_from_mono_type (type);
- /*
- * Make sure we use the correct type.
- */
- sigbuffer_add_value (buf, k->byval_arg.type);
- /*
- * ensure only non-byref gets passed to
mono_image_typedef_or_ref(),
- * otherwise two typerefs could point to the same type, leading
to
- * verification errors.
- */
- sigbuffer_add_value (buf, mono_image_typedef_or_ref (assembly,
&k->byval_arg));
+
+ if (k->generic_container) {
+ MonoGenericClass *gclass =
mono_metadata_lookup_generic_class (k,
k->generic_container->context.class_inst, TRUE);
+ encode_generic_class (assembly, gclass, buf);
+ } else {
+ /*
+ * Make sure we use the correct type.
+ */
+ sigbuffer_add_value (buf, k->byval_arg.type);
+ /*
+ * ensure only non-byref gets passed to
mono_image_typedef_or_ref(),
+ * otherwise two typerefs could point to the same type,
leading to
+ * verification errors.
+ */
+ sigbuffer_add_value (buf, mono_image_typedef_or_ref
(assembly, &k->byval_arg));
+ }
break;
}
case MONO_TYPE_ARRAY:
@@ -2150,6 +2161,9 @@
guint32 token;
SigBuffer buf;
+ if ((token = GPOINTER_TO_UINT (g_hash_table_lookup (assembly->typespec,
type))))
+ return token;
+
sigbuffer_init (&buf, 32);
switch (type->type) {
case MONO_TYPE_FNPTR:
@@ -2164,11 +2178,11 @@
case MONO_TYPE_CLASS:
case MONO_TYPE_VALUETYPE: {
MonoClass *k = mono_class_from_mono_type (type);
- if (!k || !k->generic_class) {
+ if (!k || !k->generic_container) {
sigbuffer_free (&buf);
return 0;
}
- encode_generic_class (assembly, k->generic_class, &buf);
+ encode_type (assembly, type, &buf);
break;
}
default:
@@ -2186,28 +2200,25 @@
sigbuffer_free (&buf);
token = MONO_TYPEDEFORREF_TYPESPEC | (table->next_idx <<
MONO_TYPEDEFORREF_BITS);
- g_hash_table_insert (assembly->typeref, type, GUINT_TO_POINTER(token));
+ g_hash_table_insert (assembly->typespec, type, GUINT_TO_POINTER(token));
table->next_idx ++;
return token;
}
-/*
- * Despite the name, we handle also TypeSpec (with the above helper).
- */
static guint32
-mono_image_typedef_or_ref (MonoDynamicImage *assembly, MonoType *type)
+mono_image_typedef_or_ref_full (MonoDynamicImage *assembly, MonoType *type,
gboolean try_typespec)
{
MonoDynamicTable *table;
guint32 *values;
guint32 token, scope, enclosing;
MonoClass *klass;
+ /* if the type requires a typespec, we must try that first*/
+ if (try_typespec && (token = create_typespec (assembly, type)))
+ return token;
token = GPOINTER_TO_UINT (g_hash_table_lookup (assembly->typeref,
type));
if (token)
return token;
- token = create_typespec (assembly, type);
- if (token)
- return token;
klass = my_mono_class_from_mono_type (type);
if (!klass)
klass = mono_class_from_mono_type (type);
@@ -2224,7 +2235,7 @@
}
if (klass->nested_in) {
- enclosing = mono_image_typedef_or_ref (assembly,
&klass->nested_in->byval_arg);
+ enclosing = mono_image_typedef_or_ref_full (assembly,
&klass->nested_in->byval_arg, FALSE);
/* get the typeref idx of the enclosing type */
enclosing >>= MONO_TYPEDEFORREF_BITS;
scope = (enclosing << MONO_RESOLTION_SCOPE_BITS) |
MONO_RESOLTION_SCOPE_TYPEREF;
@@ -2247,6 +2258,15 @@
}
/*
+ * Despite the name, we handle also TypeSpec (with the above helper).
+ */
+static guint32
+mono_image_typedef_or_ref (MonoDynamicImage *assembly, MonoType *type)
+{
+ return mono_image_typedef_or_ref_full (assembly, type, TRUE);
+}
+
+/*
* Insert a memberef row into the metadata: the token that point to the
memberref
* is returned. Caching is done in the caller
(mono_image_get_methodref_token() or
* mono_image_get_fieldref_token()).
@@ -2532,7 +2552,9 @@
klass = mono_class_from_mono_type (tb->type.type);
sigbuffer_add_value (&buf, MONO_TYPE_GENERICINST);
- encode_type (assembly, &klass->byval_arg, &buf);
+ g_assert (klass->generic_container);
+ sigbuffer_add_value (&buf, klass->byval_arg.type);
+ sigbuffer_add_value (&buf, mono_image_typedef_or_ref_full (assembly,
&klass->byval_arg, FALSE));
count = mono_array_length (tb->generic_params);
sigbuffer_add_value (&buf, count);
@@ -4180,10 +4202,14 @@
} else if (strcmp (klass->name, "TypeBuilder") == 0) {
MonoReflectionTypeBuilder *tb = (MonoReflectionTypeBuilder
*)obj;
token = tb->table_idx | MONO_TOKEN_TYPE_DEF;
- } else if (strcmp (klass->name, "MonoType") == 0 ||
- strcmp (klass->name, "GenericTypeParameterBuilder") == 0) {
+ } else if (strcmp (klass->name, "MonoType") == 0) {
MonoReflectionType *tb = (MonoReflectionType *)obj;
+ MonoClass *mc = mono_class_from_mono_type (tb->type);
token = mono_metadata_token_from_dor (
+ mono_image_typedef_or_ref_full (assembly, tb->type,
mc->generic_container == NULL));
+ } else if (strcmp (klass->name, "GenericTypeParameterBuilder") == 0) {
+ MonoReflectionType *tb = (MonoReflectionType *)obj;
+ token = mono_metadata_token_from_dor (
mono_image_typedef_or_ref (assembly, tb->type));
} else if (strcmp (klass->name, "MonoGenericClass") == 0) {
MonoReflectionType *tb = (MonoReflectionType *)obj;
_______________________________________________
Mono-patches maillist - [email protected]
http://lists.ximian.com/mailman/listinfo/mono-patches