diff --git a/mono/metadata/ChangeLog b/mono/metadata/ChangeLog index 53aebe5f22a83..b0cba3ae43e02 100644 --- a/mono/metadata/ChangeLog +++ b/mono/metadata/ChangeLog @@ -1,3 +1,8 @@ +2004-08-16 Martin Baulig + + * metadata.c (do_mono_metadata_parse_generic_inst): Store the + MonoGenericInst, not the MonoType in the `generic_inst_cache'. + 2004-08-14 Martin Baulig * class.c (dup_type): Also copy the `byref' field. diff --git a/mono/metadata/class.c b/mono/metadata/class.c index 99284d3e12f32..58ef207d01cae 100644 --- a/mono/metadata/class.c +++ b/mono/metadata/class.c @@ -276,7 +276,7 @@ inflate_generic_type (MonoType *type, MonoGenericContext *context) } case MONO_TYPE_GENERICINST: { MonoGenericInst *oginst = type->data.generic_inst; - MonoGenericInst *nginst; + MonoGenericInst *nginst, *cached; MonoType *nt; int i; @@ -301,13 +301,16 @@ inflate_generic_type (MonoType *type, MonoGenericContext *context) nginst->context->ginst = nginst; mono_loader_lock (); - nt = g_hash_table_lookup (oginst->klass->image->generic_inst_cache, nginst); + cached = g_hash_table_lookup (oginst->klass->image->generic_inst_cache, nginst); - if (nt) { + if (cached) { g_free (nginst->type_argv); g_free (nginst); mono_loader_unlock (); - return dup_type (nt, type); + + nt = dup_type (type, type); + nt->data.generic_inst = cached; + return nt; } nginst->dynamic_info = NULL; @@ -322,7 +325,7 @@ inflate_generic_type (MonoType *type, MonoGenericContext *context) nt = dup_type (type, type); nt->data.generic_inst = nginst; - g_hash_table_insert (oginst->klass->image->generic_inst_cache, nginst, nt); + g_hash_table_insert (oginst->klass->image->generic_inst_cache, nginst, nginst); mono_loader_unlock (); return nt; } diff --git a/mono/metadata/metadata.c b/mono/metadata/metadata.c index 88699f3e89066..bde55c46b55a8 100644 --- a/mono/metadata/metadata.c +++ b/mono/metadata/metadata.c @@ -1446,7 +1446,7 @@ static void do_mono_metadata_parse_generic_inst (MonoType *type, MonoImage *m, const char *ptr, const char **rptr) { MonoGenericInst *ginst = g_new0 (MonoGenericInst, 1); - MonoType *cached; + MonoGenericInst *cached; int i, count; type->data.generic_inst = ginst; @@ -1502,14 +1502,10 @@ do_mono_metadata_parse_generic_inst (MonoType *type, MonoImage *m, const char *p g_free (ginst->type_argv); g_free (ginst); - type->data.generic_inst = cached->data.generic_inst; + type->data.generic_inst = cached; return; } else { - cached = g_new0 (MonoType, 1); - cached->type = MONO_TYPE_GENERICINST; - cached->data.generic_inst = ginst; - - g_hash_table_insert (m->generic_inst_cache, ginst, cached); + g_hash_table_insert (m->generic_inst_cache, ginst, ginst); mono_stats.generic_instance_count++; mono_stats.generics_metadata_size += sizeof (MonoGenericInst) + diff --git a/mono/metadata/reflection.c b/mono/metadata/reflection.c index 5de8f8a16a977..5412c78cc4294 100644 --- a/mono/metadata/reflection.c +++ b/mono/metadata/reflection.c @@ -7221,7 +7221,7 @@ do_mono_reflection_bind_generic_parameters (MonoReflectionType *type, int type_a { MonoClass *klass; MonoReflectionTypeBuilder *tb = NULL; - MonoGenericInst *ginst; + MonoGenericInst *ginst, *cached; MonoDomain *domain; MonoType *geninst; int icount, i; @@ -7268,20 +7268,22 @@ do_mono_reflection_bind_generic_parameters (MonoReflectionType *type, int type_a ginst->generic_type = kginst->generic_type; } - geninst = g_hash_table_lookup (klass->image->generic_inst_cache, ginst); - if (geninst) { + geninst = g_new0 (MonoType, 1); + geninst->type = MONO_TYPE_GENERICINST; + + cached = g_hash_table_lookup (klass->image->generic_inst_cache, ginst); + if (cached) { g_free (ginst); mono_loader_unlock (); + geninst->data.generic_inst = cached; return geninst; } + geninst->data.generic_inst = ginst; + ginst->context = g_new0 (MonoGenericContext, 1); ginst->context->ginst = ginst; - geninst = g_new0 (MonoType, 1); - geninst->type = MONO_TYPE_GENERICINST; - geninst->data.generic_inst = ginst; - if (!strcmp (((MonoObject *) type)->vtable->klass->name, "TypeBuilder")) { tb = (MonoReflectionTypeBuilder *) type; @@ -7316,7 +7318,7 @@ do_mono_reflection_bind_generic_parameters (MonoReflectionType *type, int type_a mono_class_create_generic (ginst); - g_hash_table_insert (klass->image->generic_inst_cache, ginst, geninst); + g_hash_table_insert (klass->image->generic_inst_cache, ginst, ginst); mono_loader_unlock ();