if (method->signature)
mono_metadata_free_inflated_signature (method->signature);
+ if (method->wrapper_type)
+ g_free (((MonoMethodWrapper*)method)->method_data);
+
g_free (method);
}
gboolean is_open;
int i;
int size = MONO_SIZEOF_GENERIC_INST + type_argc * sizeof (MonoType *);
- CollectData data;
- MonoImageSet *set;
for (i = 0; i < type_argc; ++i)
if (mono_class_is_open_constructed_type (type_argv [i]))
ginst->type_argc = type_argc;
memcpy (ginst->type_argv, type_argv, type_argc * sizeof (MonoType *));
+ return mono_metadata_get_canonical_generic_inst (ginst);
+}
+
+
+/**
+ * mono_metadata_get_canonical_generic_inst:
+ * @candidate: an arbitrary generic instantiation
+ *
+ * Returns the canonical generic instantiation that represents the given
+ * candidate by identifying the image set for the candidate instantiation and
+ * finding the instance in the image set or adding a copy of the given instance
+ * to the image set.
+ *
+ * The returned MonoGenericInst has its own copy of the list of types. The list
+ * passed in the argument can be freed, modified or disposed of.
+ *
+ */
+MonoGenericInst *
+mono_metadata_get_canonical_generic_inst (MonoGenericInst *candidate)
+{
+ CollectData data;
+ int type_argc = candidate->type_argc;
+ gboolean is_open = candidate->is_open;
+ MonoImageSet *set;
+
collect_data_init (&data);
- collect_ginst_images (ginst, &data);
+ collect_ginst_images (candidate, &data);
set = get_image_set (data.images, data.nimages);
mono_image_set_lock (set);
- ginst = (MonoGenericInst *)g_hash_table_lookup (set->ginst_cache, ginst);
+ MonoGenericInst *ginst = (MonoGenericInst *)g_hash_table_lookup (set->ginst_cache, candidate);
if (!ginst) {
+ int size = MONO_SIZEOF_GENERIC_INST + type_argc * sizeof (MonoType *);
ginst = (MonoGenericInst *)mono_image_set_alloc0 (set, size);
#ifndef MONO_SMALL_CONFIG
ginst->id = ++next_generic_inst_id;
ginst->is_open = is_open;
ginst->type_argc = type_argc;
- for (i = 0; i < type_argc; ++i)
- ginst->type_argv [i] = mono_metadata_type_dup (NULL, type_argv [i]);
+ for (int i = 0; i < type_argc; ++i)
+ ginst->type_argv [i] = mono_metadata_type_dup (NULL, candidate->type_argv [i]);
g_hash_table_insert (set->ginst_cache, ginst, ginst);
}
static gboolean
mono_metadata_is_type_builder_generic_type_definition (MonoClass *container_class, MonoGenericInst *inst, gboolean is_dynamic)
{
- MonoGenericContainer *container = container_class->generic_container;
+ MonoGenericContainer *container = mono_class_get_generic_container (container_class);
if (!is_dynamic || container_class->wastypebuilder || container->type_argc != inst->type_argc)
return FALSE;
MonoImageSet *set;
CollectData data;
+ g_assert (mono_class_get_generic_container (container_class)->type_argc == inst->type_argc);
+
memset (&helper, 0, sizeof(helper)); // act like g_new0
helper.container_class = container_class;
helper.context.class_inst = inst;
gclass->context.class_inst = inst;
gclass->context.method_inst = NULL;
gclass->owner = set;
- if (inst == container_class->generic_container->context.class_inst && !is_tb_open)
+ if (inst == mono_class_get_generic_container (container_class)->context.class_inst && !is_tb_open)
gclass->cached_class = container_class;
g_hash_table_insert (set->gclass_cache, gclass, gclass);
return FALSE;
gklass = mono_class_from_mono_type (gtype);
- if (!gklass->generic_container) {
+ if (!mono_class_is_gtd (gklass)) {
mono_error_set_bad_image (error, m, "Generic instance with non-generic definition");
return FALSE;
}
_mono_metadata_generic_class_container_equal (const MonoGenericClass *g1, MonoClass *c2, gboolean signature_only)
{
MonoGenericInst *i1 = g1->context.class_inst;
- MonoGenericInst *i2 = c2->generic_container->context.class_inst;
+ MonoGenericInst *i2 = mono_class_get_generic_container (c2)->context.class_inst;
if (!mono_metadata_class_equal (g1->container_class, c2, signature_only))
return FALSE;
{
if (c1 == c2)
return TRUE;
- if (c1->generic_class && c2->generic_class)
- return _mono_metadata_generic_class_equal (c1->generic_class, c2->generic_class, signature_only);
- if (c1->generic_class && c2->generic_container)
- return _mono_metadata_generic_class_container_equal (c1->generic_class, c2, signature_only);
- if (c1->generic_container && c2->generic_class)
- return _mono_metadata_generic_class_container_equal (c2->generic_class, c1, signature_only);
+ if (mono_class_is_ginst (c1) && mono_class_is_ginst (c2))
+ return _mono_metadata_generic_class_equal (mono_class_get_generic_class (c1), mono_class_get_generic_class (c2), signature_only);
+ if (mono_class_is_ginst (c1) && mono_class_is_gtd (c2))
+ return _mono_metadata_generic_class_container_equal (mono_class_get_generic_class (c1), c2, signature_only);
+ if (mono_class_is_gtd (c1) && mono_class_is_ginst (c2))
+ return _mono_metadata_generic_class_container_equal (mono_class_get_generic_class (c2), c1, signature_only);
if ((c1->byval_arg.type == MONO_TYPE_VAR) && (c2->byval_arg.type == MONO_TYPE_VAR))
return mono_metadata_generic_param_equal_internal (
c1->byval_arg.data.generic_param, c2->byval_arg.data.generic_param, signature_only);
case MONO_NATIVE_TBSTR:
*conv = MONO_MARSHAL_CONV_STR_TBSTR;
return MONO_NATIVE_TBSTR;
+ case MONO_NATIVE_UTF8STR:
+ *conv = MONO_MARSHAL_CONV_STR_UTF8STR;
+ return MONO_NATIVE_UTF8STR;
case MONO_NATIVE_BYVALTSTR:
if (unicode)
*conv = MONO_MARSHAL_CONV_STR_BYVALWSTR;
MonoClass *gtd;
int offset;
- if (!field->parent->generic_class)
+ if (!mono_class_is_ginst (field->parent))
return field;
- gtd = field->parent->generic_class->container_class;
+ gtd = mono_class_get_generic_class (field->parent)->container_class;
offset = field - field->parent->fields;
return gtd->fields + offset;
}
MonoClass *gtd;
int offset;
- if (!event->parent->generic_class)
+ if (!mono_class_is_ginst (event->parent))
return event;
- gtd = event->parent->generic_class->container_class;
- offset = event - event->parent->ext->events;
- return gtd->ext->events + offset;
+ gtd = mono_class_get_generic_class (event->parent)->container_class;
+ offset = event - mono_class_get_event_info (event->parent)->events;
+ return mono_class_get_event_info (gtd)->events + offset;
}
/*
MonoProperty*
mono_metadata_get_corresponding_property_from_generic_type_definition (MonoProperty *property)
{
+ MonoClassPropertyInfo *info;
MonoClass *gtd;
int offset;
- if (!property->parent->generic_class)
+ if (!mono_class_is_ginst (property->parent))
return property;
- gtd = property->parent->generic_class->container_class;
- offset = property - property->parent->ext->properties;
- return gtd->ext->properties + offset;
+ info = mono_class_get_property_info (property->parent);
+ gtd = mono_class_get_generic_class (property->parent)->container_class;
+ offset = property - info->properties;
+ return mono_class_get_property_info (gtd)->properties + offset;
}
MonoWrapperCaches*