[reflection] Use handles for several more icalls (#4098)
[mono.git] / mono / metadata / metadata.c
index e8a19188a757201581b562a6ce7309af31b420d5..2fdcb1f6bffea82af0322bf60f7c5f755385ca1b 100644 (file)
@@ -2891,8 +2891,6 @@ mono_metadata_get_generic_inst (int type_argc, MonoType **type_argv)
        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]))
@@ -2905,9 +2903,34 @@ mono_metadata_get_generic_inst (int type_argc, MonoType **type_argv)
        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);
 
@@ -2915,8 +2938,9 @@ mono_metadata_get_generic_inst (int type_argc, MonoType **type_argv)
 
        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;
@@ -2924,8 +2948,8 @@ mono_metadata_get_generic_inst (int type_argc, MonoType **type_argv)
                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);
        }
@@ -5815,7 +5839,7 @@ handle_enum:
                                *conv = MONO_MARSHAL_CONV_STR_TBSTR;
                                return MONO_NATIVE_TBSTR;
                        case MONO_NATIVE_UTF8STR:
-                               *conv = MONO_MARSHAL_CONV_STR_LPTSTR;
+                               *conv = MONO_MARSHAL_CONV_STR_UTF8STR;
                                return MONO_NATIVE_UTF8STR;
                        case MONO_NATIVE_BYVALTSTR:
                                if (unicode)
@@ -6634,8 +6658,8 @@ mono_metadata_get_corresponding_event_from_generic_type_definition (MonoEvent *e
                return event;
 
        gtd = mono_class_get_generic_class (event->parent)->container_class;
-       offset = event - mono_class_get_ext (event->parent)->events;
-       return mono_class_get_ext (gtd)->events + offset;
+       offset = event - mono_class_get_event_info (event->parent)->events;
+       return mono_class_get_event_info (gtd)->events + offset;
 }
 
 /*
@@ -6645,15 +6669,17 @@ mono_metadata_get_corresponding_event_from_generic_type_definition (MonoEvent *e
 MonoProperty*
 mono_metadata_get_corresponding_property_from_generic_type_definition (MonoProperty *property)
 {
+       MonoClassPropertyInfo *info;
        MonoClass *gtd;
        int offset;
 
        if (!mono_class_is_ginst (property->parent))
                return property;
 
+       info = mono_class_get_property_info (property->parent);
        gtd = mono_class_get_generic_class (property->parent)->container_class;
-       offset = property - mono_class_get_ext (property->parent)->properties;
-       return mono_class_get_ext (gtd)->properties + offset;
+       offset = property - info->properties;
+       return mono_class_get_property_info (gtd)->properties + offset;
 }
 
 MonoWrapperCaches*