Fix typo.
[mono.git] / mono / metadata / loader.c
index 49bb1a06bf18b4cbf75837441b47ac911bcdfa6d..e0ab7fc1bb2718a0b4bd92cc7a77e62efc274a47 100644 (file)
@@ -246,7 +246,7 @@ find_method (MonoClass *klass, MonoClass *ic, const char* name, MonoMethodSignat
  * token is the method_ref or method_def token used in a call IL instruction.
  */
 MonoMethodSignature*
-mono_method_get_signature (MonoMethod *method, MonoImage *image, guint32 token)
+mono_method_get_signature_full (MonoMethod *method, MonoImage *image, guint32 token, MonoGenericContext *context)
 {
        int table = mono_metadata_token_table (token);
        int idx = mono_metadata_token_index (token);
@@ -279,13 +279,21 @@ mono_method_get_signature (MonoMethod *method, MonoImage *image, guint32 token)
        
                ptr = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
                mono_metadata_decode_blob_size (ptr, &ptr);
-               sig = mono_metadata_parse_method_signature (image, 0, ptr, NULL);
+               sig = mono_metadata_parse_method_signature_full (image, context, 0, ptr, NULL);
                g_hash_table_insert (image->memberref_signatures, GUINT_TO_POINTER (token), sig);
        }
 
+       sig = mono_class_inflate_generic_signature (image, sig, context);
+
        return sig;
 }
 
+MonoMethodSignature*
+mono_method_get_signature (MonoMethod *method, MonoImage *image, guint32 token)
+{
+       return mono_method_get_signature_full (method, image, token, NULL);
+}
+
 static MonoMethod *
 method_from_memberref (MonoImage *image, guint32 idx, MonoGenericContext *context)
 {
@@ -347,7 +355,7 @@ method_from_memberref (MonoImage *image, guint32 idx, MonoGenericContext *contex
 
        ptr = mono_metadata_blob_heap (image, cols [MONO_MEMBERREF_SIGNATURE]);
        mono_metadata_decode_blob_size (ptr, &ptr);
-       sig = mono_metadata_parse_method_signature_full (image, container, 0, ptr, NULL);
+       sig = mono_metadata_parse_method_signature_full (image, (MonoGenericContext *) container, 0, ptr, NULL);
 
        switch (class) {
        case MONO_MEMBERREF_PARENT_TYPEREF:
@@ -457,52 +465,40 @@ method_from_methodspec (MonoImage *image, MonoGenericContext *context, guint32 i
        g_assert (container && container->is_method);
 
        if (context) {
-               if (context->gclass) {
-                       g_assert (context->gclass->container);
-                       container->parent = context->gclass->container;
-               } else
-                       container->parent = context->container;
+               g_assert (context->container);
+               container->parent = context->container;
+               if (container->parent->is_method)
+                       container->parent = container->parent->parent;
        }
 
        gmethod = g_new0 (MonoGenericMethod, 1);
        gmethod->container = container;
-       gmethod->inst = g_new0 (MonoGenericInst, 1);
-       gmethod->inst->type_argc = param_count;
-       gmethod->inst->type_argv = g_new0 (MonoType *, param_count);
-
-       for (i = 0; i < param_count; i++) {
-               MonoType *t = mono_metadata_parse_type_full (
-                       image, container, MONO_PARSE_TYPE, 0, ptr, &ptr);
 
-               if (context)
-                       t = mono_class_inflate_generic_type (t, context);
+       gmethod->inst = mono_metadata_parse_generic_inst (
+               image, (MonoGenericContext *) container, param_count, ptr, &ptr);
 
-               gmethod->inst->type_argv [i] = t;
-
-               if (!gmethod->inst->is_open)
-                       gmethod->inst->is_open = mono_class_is_open_constructed_type (gmethod->inst->type_argv [i]);
-       }
+       if (context)
+               gmethod->inst = mono_metadata_inflate_generic_inst (gmethod->inst, context);
 
        if (!container->method_hash)
                container->method_hash = g_hash_table_new (
-                       mono_metadata_generic_method_hash, mono_metadata_generic_method_equal);
+                       (GHashFunc)mono_metadata_generic_method_hash, (GEqualFunc)mono_metadata_generic_method_equal);
 
        inflated = g_hash_table_lookup (container->method_hash, gmethod);
        if (inflated) {
-               g_free (gmethod->inst->type_argv);
-               g_free (gmethod->inst);
                g_free (gmethod);
-
                return inflated;
        }
 
        if (!context) {
                new_context = g_new0 (MonoGenericContext, 1);
+               new_context->container = container;
                new_context->gmethod = gmethod;
 
                context = new_context;
        } else {
                new_context = g_new0 (MonoGenericContext, 1);
+               new_context->container = container;
                new_context->gmethod = gmethod;
                new_context->gclass = context->gclass;
 
@@ -745,7 +741,7 @@ mono_lookup_pinvoke_call (MonoMethod *method, const char **exc_class, const char
 
                if (exc_class) {
                        *exc_class = "DllNotFoundException";
-                       *exc_arg = orig_scope;
+                       *exc_arg = new_scope;
                }
                return NULL;
        }
@@ -824,11 +820,8 @@ mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass,
        if (table != MONO_TABLE_METHOD) {
                MonoGenericContainer *generic_container = NULL;
                if (context) {
-                       if (context->gclass) {
-                               g_assert (context->gclass->container);
-                               generic_container = context->gclass->container;
-                       } else
-                               generic_container = context->container;
+                       g_assert (context->container);
+                       generic_container = context->container;
                }
                if (table == MONO_TABLE_METHODSPEC)
                        return method_from_methodspec (image, context, idx);
@@ -871,7 +864,8 @@ mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass,
        if (!sig) /* already taken from the methodref */
                sig = mono_metadata_blob_heap (image, cols [4]);
        size = mono_metadata_decode_blob_size (sig, &sig);
-       result->signature = mono_metadata_parse_method_signature_full (image, container, idx, sig, NULL);
+       result->signature = mono_metadata_parse_method_signature_full (
+               image, (MonoGenericContext *) container, idx, sig, NULL);
 
        if (!result->klass) {
                guint32 type = mono_metadata_typedef_from_method (image, token);
@@ -945,7 +939,8 @@ mono_get_method_from_token (MonoImage *image, guint32 token, MonoClass *klass,
                    !(result->iflags & METHOD_IMPL_ATTRIBUTE_RUNTIME) && container) {
                        gpointer loc = mono_image_rva_map (image, cols [0]);
                        g_assert (loc);
-                       ((MonoMethodNormal *) result)->header = mono_metadata_parse_mh_full (image, container, loc);
+                       ((MonoMethodNormal *) result)->header = mono_metadata_parse_mh_full (
+                               image, (MonoGenericContext *) container, loc);
                }
                
                ((MonoMethodNormal *) result)->generic_container = generic_container;
@@ -1339,7 +1334,7 @@ mono_method_get_header (MonoMethod *method)
        
        g_assert (loc);
        
-       mn->header = mono_metadata_parse_mh_full (img, mn->generic_container, loc);
+       mn->header = mono_metadata_parse_mh_full (img, (MonoGenericContext *) mn->generic_container, loc);
        
        mono_loader_unlock ();
        return mn->header;