Merge pull request #3647 from BrzVlad/fix-sgen-internal-alloc
[mono.git] / mono / metadata / metadata.c
index d278a7487ee68a8d59dce5902675362b2200dd39..f9e2bc514889b5f1fb78f1898467f7bbc2408ce1 100644 (file)
@@ -1822,7 +1822,7 @@ mono_metadata_get_param_attrs (MonoImage *m, int def, int param_count)
 /*
  * mono_metadata_parse_signature:
  * @image: metadata context
- * @toke: metadata token
+ * @token: metadata token
  *
  * Decode a method signature stored in the STANDALONESIG table
  *
@@ -1833,15 +1833,34 @@ mono_metadata_parse_signature (MonoImage *image, guint32 token)
 {
        MonoError error;
        MonoMethodSignature *ret;
+       ret = mono_metadata_parse_signature_checked (image, token, &error);
+       mono_error_cleanup (&error);
+       return ret;
+}
+
+/*
+ * mono_metadata_parse_signature_checked:
+ * @image: metadata context
+ * @token: metadata token
+ * @error: set on error
+ *
+ * Decode a method signature stored in the STANDALONESIG table
+ *
+ * Returns: a MonoMethodSignature describing the signature. On failure
+ * returns NULL and sets @error.
+ */
+MonoMethodSignature*
+mono_metadata_parse_signature_checked (MonoImage *image, guint32 token, MonoError *error)
+{
+
+       mono_error_init (error);
        MonoTableInfo *tables = image->tables;
        guint32 idx = mono_metadata_token_index (token);
        guint32 sig;
        const char *ptr;
 
        if (image_is_dynamic (image)) {
-               ret = (MonoMethodSignature *)mono_lookup_dynamic_token (image, token, NULL, &error);
-               mono_error_raise_exception (&error); /* FIXME don't raise here */
-               return ret;
+               return (MonoMethodSignature *)mono_lookup_dynamic_token (image, token, NULL, error);
        }
 
        g_assert (mono_metadata_token_table(token) == MONO_TABLE_STANDALONESIG);
@@ -1851,9 +1870,7 @@ mono_metadata_parse_signature (MonoImage *image, guint32 token)
        ptr = mono_metadata_blob_heap (image, sig);
        mono_metadata_decode_blob_size (ptr, &ptr);
 
-       ret = mono_metadata_parse_method_signature_full (image, NULL, 0, ptr, NULL, &error);
-       mono_error_cleanup (&error); /*FIXME don't swallow the error message*/
-       return ret;
+       return mono_metadata_parse_method_signature_full (image, NULL, 0, ptr, NULL, error);
 }
 
 /*
@@ -2772,6 +2789,9 @@ free_inflated_method (MonoMethodInflated *imethod)
        if (method->signature)
                mono_metadata_free_inflated_signature (method->signature);
 
+       if (method->wrapper_type)
+               g_free (((MonoMethodWrapper*)method)->method_data);
+
        g_free (method);
 }
 
@@ -2789,8 +2809,6 @@ static void
 free_generic_class (MonoGenericClass *gclass)
 {
        /* The gclass itself is allocated from the image set mempool */
-       if (gclass->is_dynamic)
-               mono_reflection_free_dynamic_generic_class (gclass);
        if (gclass->cached_class && gclass->cached_class->interface_id)
                mono_unload_interface_id (gclass->cached_class);
 }
@@ -2967,13 +2985,9 @@ mono_metadata_lookup_generic_class (MonoClass *container_class, MonoGenericInst
                return gclass;
        }
 
-       if (is_dynamic) {
-               MonoDynamicGenericClass *dgclass = mono_image_set_new0 (set, MonoDynamicGenericClass, 1);
-               gclass = &dgclass->generic_class;
+       gclass = mono_image_set_new0 (set, MonoGenericClass, 1);
+       if (is_dynamic)
                gclass->is_dynamic = 1;
-       } else {
-               gclass = mono_image_set_new0 (set, MonoGenericClass, 1);
-       }
 
        gclass->is_tb_open = is_tb_open;
        gclass->container_class = container_class;
@@ -6052,6 +6066,21 @@ mono_guid_to_string (const guint8 *guid)
                                guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]);
 }
 
+/**
+ * mono_guid_to_string_minimal:
+ *
+ * Converts a 16 byte Microsoft GUID to lower case no '-' representation..
+ */
+char *
+mono_guid_to_string_minimal (const guint8 *guid)
+{
+       return g_strdup_printf ("%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x%02x",
+                               guid[3], guid[2], guid[1], guid[0],
+                               guid[5], guid[4],
+                               guid[7], guid[6],
+                               guid[8], guid[9],
+                               guid[10], guid[11], guid[12], guid[13], guid[14], guid[15]);
+}
 static gboolean
 get_constraints (MonoImage *image, int owner, MonoClass ***constraints, MonoGenericContainer *container, MonoError *error)
 {
@@ -6427,6 +6456,12 @@ mono_type_is_reference (MonoType *type)
                !mono_metadata_generic_class_is_valuetype (type->data.generic_class))));
 }
 
+mono_bool
+mono_type_is_generic_parameter (MonoType *type)
+{
+       return !type->byref && (type->type == MONO_TYPE_VAR || type->type == MONO_TYPE_MVAR);
+}
+
 /**
  * mono_signature_get_return_type:
  * @sig: the method signature inspected