First set of licensing changes
[mono.git] / mono / mini / mini-generic-sharing.c
index 4f54bd69d95ddadbfcca4ad56e8e4fddeb7665b8..43137b6885f17f91e4af5484838516e57b304302 100644 (file)
@@ -6,6 +6,7 @@
  *
  * Copyright 2007-2011 Novell, Inc (http://www.novell.com)
  * Copyright 2011 Xamarin, Inc (http://www.xamarin.com)
+ * Licensed under the MIT license. See LICENSE file in the project root for full license information.
  */
 
 #include <config.h>
@@ -551,7 +552,9 @@ inflate_info (MonoRuntimeGenericContextInfoTemplate *oti, MonoGenericContext *co
        case MONO_RGCTX_INFO_METHOD_DELEGATE_CODE: {
                MonoMethod *method = (MonoMethod *)data;
                MonoMethod *inflated_method;
-               MonoType *inflated_type = mono_class_inflate_generic_type (&method->klass->byval_arg, context);
+               MonoType *inflated_type = mono_class_inflate_generic_type_checked (&method->klass->byval_arg, context, &error);
+               mono_error_assert_ok (&error); /* FIXME don't swallow the error */
+
                MonoClass *inflated_class = mono_class_from_mono_type (inflated_type);
 
                mono_metadata_free_type (inflated_type);
@@ -602,7 +605,9 @@ inflate_info (MonoRuntimeGenericContextInfoTemplate *oti, MonoGenericContext *co
                MonoJumpInfoGSharedVtCall *info = (MonoJumpInfoGSharedVtCall *)data;
                MonoMethod *method = info->method;
                MonoMethod *inflated_method;
-               MonoType *inflated_type = mono_class_inflate_generic_type (&method->klass->byval_arg, context);
+               MonoType *inflated_type = mono_class_inflate_generic_type_checked (&method->klass->byval_arg, context, &error);
+               mono_error_assert_ok (&error); /* FIXME don't swallow the error */
+
                MonoClass *inflated_class = mono_class_from_mono_type (inflated_type);
                MonoJumpInfoGSharedVtCall *res;
                MonoDomain *domain = mono_domain_get ();
@@ -635,8 +640,11 @@ inflate_info (MonoRuntimeGenericContextInfoTemplate *oti, MonoGenericContext *co
 
        case MONO_RGCTX_INFO_CLASS_FIELD:
        case MONO_RGCTX_INFO_FIELD_OFFSET: {
+               MonoError error;
                MonoClassField *field = (MonoClassField *)data;
-               MonoType *inflated_type = mono_class_inflate_generic_type (&field->parent->byval_arg, context);
+               MonoType *inflated_type = mono_class_inflate_generic_type_checked (&field->parent->byval_arg, context, &error);
+               mono_error_assert_ok (&error); /* FIXME don't swallow the error */
+
                MonoClass *inflated_class = mono_class_from_mono_type (inflated_type);
                int i = field - field->parent->fields;
                gpointer dummy = NULL;
@@ -668,7 +676,9 @@ inflate_info (MonoRuntimeGenericContextInfoTemplate *oti, MonoGenericContext *co
 
                // FIXME: Temporary
                res = (MonoJumpInfoVirtMethod *)mono_domain_alloc0 (domain, sizeof (MonoJumpInfoVirtMethod));
-               t = mono_class_inflate_generic_type (&info->klass->byval_arg, context);
+               t = mono_class_inflate_generic_type_checked (&info->klass->byval_arg, context, &error);
+               mono_error_assert_ok (&error); /* FIXME don't swallow the error */
+
                res->klass = mono_class_from_mono_type (t);
                mono_metadata_free_type (t);
 
@@ -1077,6 +1087,7 @@ get_wrapper_shared_type (MonoType *t)
        case MONO_TYPE_PTR:
                return &mono_defaults.int_class->byval_arg;
        case MONO_TYPE_GENERICINST: {
+               MonoError error;
                MonoClass *klass;
                MonoGenericContext ctx;
                MonoGenericContext *orig_ctx;
@@ -1106,7 +1117,8 @@ get_wrapper_shared_type (MonoType *t)
                                args [i] = get_wrapper_shared_type (inst->type_argv [i]);
                        ctx.method_inst = mono_metadata_get_generic_inst (inst->type_argc, args);
                }
-               klass = mono_class_inflate_generic_class (klass->generic_class->container_class, &ctx);
+               klass = mono_class_inflate_generic_class_checked (klass->generic_class->container_class, &ctx, &error);
+               mono_error_assert_ok (&error); /* FIXME don't swallow the error */
                return &klass->byval_arg;
        }
 #if SIZEOF_VOID_P == 8
@@ -2474,11 +2486,6 @@ mono_method_lookup_rgctx (MonoVTable *class_vtable, MonoGenericInst *method_inst
        return mrgctx;
 }
 
-
-static gboolean
-generic_inst_is_sharable (MonoGenericInst *inst, gboolean allow_type_vars,
-                                                 gboolean allow_partial);
-
 static gboolean
 type_is_sharable (MonoType *type, gboolean allow_type_vars, gboolean allow_partial)
 {
@@ -2499,9 +2506,9 @@ type_is_sharable (MonoType *type, gboolean allow_type_vars, gboolean allow_parti
        if (allow_partial && !type->byref && type->type == MONO_TYPE_GENERICINST && MONO_TYPE_ISSTRUCT (type)) {
                MonoGenericClass *gclass = type->data.generic_class;
 
-               if (gclass->context.class_inst && !generic_inst_is_sharable (gclass->context.class_inst, allow_type_vars, allow_partial))
+               if (gclass->context.class_inst && !mini_generic_inst_is_sharable (gclass->context.class_inst, allow_type_vars, allow_partial))
                        return FALSE;
-               if (gclass->context.method_inst && !generic_inst_is_sharable (gclass->context.method_inst, allow_type_vars, allow_partial))
+               if (gclass->context.method_inst && !mini_generic_inst_is_sharable (gclass->context.method_inst, allow_type_vars, allow_partial))
                        return FALSE;
                if (mono_class_is_nullable (mono_class_from_mono_type (type)))
                        return FALSE;
@@ -2511,8 +2518,8 @@ type_is_sharable (MonoType *type, gboolean allow_type_vars, gboolean allow_parti
        return FALSE;
 }
 
-static gboolean
-generic_inst_is_sharable (MonoGenericInst *inst, gboolean allow_type_vars,
+gboolean
+mini_generic_inst_is_sharable (MonoGenericInst *inst, gboolean allow_type_vars,
                                                  gboolean allow_partial)
 {
        int i;
@@ -2561,10 +2568,10 @@ mono_generic_context_is_sharable_full (MonoGenericContext *context,
 {
        g_assert (context->class_inst || context->method_inst);
 
-       if (context->class_inst && !generic_inst_is_sharable (context->class_inst, allow_type_vars, allow_partial))
+       if (context->class_inst && !mini_generic_inst_is_sharable (context->class_inst, allow_type_vars, allow_partial))
                return FALSE;
 
-       if (context->method_inst && !generic_inst_is_sharable (context->method_inst, allow_type_vars, allow_partial))
+       if (context->method_inst && !mini_generic_inst_is_sharable (context->method_inst, allow_type_vars, allow_partial))
                return FALSE;
 
        return TRUE;
@@ -2652,6 +2659,7 @@ is_async_state_machine_class (MonoClass *klass)
 static G_GNUC_UNUSED gboolean
 is_async_method (MonoMethod *method)
 {
+       MonoError error;
        MonoCustomAttrInfo *cattr;
        MonoMethodSignature *sig;
        gboolean res = FALSE;
@@ -2667,7 +2675,11 @@ is_async_method (MonoMethod *method)
                                (sig->ret->type == MONO_TYPE_CLASS && !strcmp (sig->ret->data.generic_class->container_class->name, "Task")) ||
                                (sig->ret->type == MONO_TYPE_GENERICINST && !strcmp (sig->ret->data.generic_class->container_class->name, "Task`1")))) {
                //printf ("X: %s\n", mono_method_full_name (method, TRUE));
-               cattr = mono_custom_attrs_from_method (method);
+               cattr = mono_custom_attrs_from_method_checked (method, &error);
+               if (!is_ok (&error)) {
+                       mono_error_cleanup (&error); /* FIXME don't swallow the error? */
+                       return FALSE;
+               }
                if (cattr) {
                        if (mono_custom_attrs_has_attr (cattr, attr_class))
                                res = TRUE;
@@ -2847,7 +2859,6 @@ mono_method_construct_object_context (MonoMethod *method)
 }
 
 static gboolean gshared_supported;
-static gboolean gsharedvt_supported;
 
 void
 mono_set_generic_sharing_supported (gboolean supported)
@@ -2855,11 +2866,6 @@ mono_set_generic_sharing_supported (gboolean supported)
        gshared_supported = supported;
 }
 
-void
-mono_set_generic_sharing_vt_supported (gboolean supported)
-{
-       gsharedvt_supported = supported;
-}
 
 void
 mono_set_partial_sharing_supported (gboolean supported)
@@ -3307,6 +3313,7 @@ get_shared_type (MonoType *t, MonoType *type)
        MonoTypeEnum ttype;
 
        if (!type->byref && type->type == MONO_TYPE_GENERICINST && MONO_TYPE_ISSTRUCT (type)) {
+               MonoError error;
                MonoGenericClass *gclass = type->data.generic_class;
                MonoGenericContext context;
                MonoClass *k;
@@ -3317,7 +3324,8 @@ get_shared_type (MonoType *t, MonoType *type)
                if (gclass->context.method_inst)
                        context.method_inst = get_shared_inst (gclass->context.method_inst, gclass->container_class->generic_container->context.method_inst, NULL, FALSE, FALSE, TRUE);
 
-               k = mono_class_inflate_generic_class (gclass->container_class, &context);
+               k = mono_class_inflate_generic_class_checked (gclass->container_class, &context, &error);
+               mono_error_assert_ok (&error); /* FIXME don't swallow the error */
 
                return mini_get_shared_gparam (t, &k->byval_arg);
        } else if (MONO_TYPE_ISSTRUCT (type)) {
@@ -3367,7 +3375,7 @@ get_shared_inst (MonoGenericInst *inst, MonoGenericInst *shared_inst, MonoGeneri
                if (all_vt || gsharedvt) {
                        type_argv [i] = get_gsharedvt_type (shared_inst->type_argv [i]);
                } else {
-                       /* These types match the ones in generic_inst_is_sharable () */
+                       /* These types match the ones in mini_generic_inst_is_sharable () */
                        type_argv [i] = get_shared_type (shared_inst->type_argv [i], inst->type_argv [i]);
                }
        }
@@ -3510,47 +3518,3 @@ mini_get_rgctx_entry_slot (MonoJumpInfoRgctxEntry *entry)
 
        return slot;
 }
-
-#if defined(ENABLE_GSHAREDVT)
-
-#include "../../../mono-extensions/mono/mini/mini-generic-sharing-gsharedvt.c"
-
-#else
-
-gboolean
-mini_is_gsharedvt_type (MonoType *t)
-{
-       return FALSE;
-}
-
-gboolean
-mini_is_gsharedvt_klass (MonoClass *klass)
-{
-       return FALSE;
-}
-
-gboolean
-mini_is_gsharedvt_signature (MonoMethodSignature *sig)
-{
-       return FALSE;
-}
-
-gboolean
-mini_is_gsharedvt_variable_type (MonoType *t)
-{
-       return FALSE;
-}
-
-gboolean
-mini_is_gsharedvt_sharable_method (MonoMethod *method)
-{
-       return FALSE;
-}
-
-gboolean
-mini_is_gsharedvt_variable_signature (MonoMethodSignature *sig)
-{
-       return FALSE;
-}
-
-#endif /* !MONOTOUCH */