Merge System/MonoType.cs into ReferenceSources/RuntimeType.cs, use th… (#3045)
[mono.git] / mono / metadata / icall.c
index b134243ca3d939d77df5bcea4535da3e3fe54668..aac703ffb7bc55b0e804ad27509ea6f049ed9588 100644 (file)
@@ -1211,7 +1211,7 @@ ves_icall_System_Object_GetType (MonoObject *obj)
 }
 
 ICALL_EXPORT void
-ves_icall_MonoType_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
+ves_icall_RuntimeType_type_from_obj (MonoReflectionType *mtype, MonoObject *obj)
 {
        mtype->type = &obj->vtable->klass->byval_arg;
        g_assert (mtype->type->type);
@@ -2152,12 +2152,16 @@ ves_icall_MonoField_GetRawConstantValue (MonoReflectionField *rfield)
                        return NULL;
                }
                v = ((gchar *) o) + sizeof (MonoObject);
-               mono_get_constant_value_from_blob (domain, def_type, def_value, v);
+               mono_get_constant_value_from_blob (domain, def_type, def_value, v, &error);
+               if (mono_error_set_pending_exception (&error))
+                       return NULL;
                break;
        }
        case MONO_TYPE_STRING:
        case MONO_TYPE_CLASS:
-               mono_get_constant_value_from_blob (domain, def_type, def_value, &o);
+               mono_get_constant_value_from_blob (domain, def_type, def_value, &o, &error);
+               if (mono_error_set_pending_exception (&error))
+                       return NULL;
                break;
        default:
                g_assert_not_reached ();
@@ -2397,7 +2401,7 @@ get_interfaces_hash (gconstpointer v1)
 }
 
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetInterfaces (MonoReflectionType* type)
+ves_icall_RuntimeType_GetInterfaces (MonoReflectionType* type)
 {
        MonoError error;
        MonoClass *klass = mono_class_from_mono_type (type->type);
@@ -2427,12 +2431,17 @@ ves_icall_Type_GetInterfaces (MonoReflectionType* type)
        len = g_hash_table_size (iface_hash);
        if (len == 0) {
                g_hash_table_destroy (iface_hash);
-               if (!data.domain->empty_types)
-                       data.domain->empty_types = mono_array_new_cached (data.domain, mono_defaults.monotype_class, 0);
+               if (!data.domain->empty_types) {
+                       data.domain->empty_types = mono_array_new_cached (data.domain, mono_defaults.runtimetype_class, 0, &error);
+                       if (!is_ok (&error))
+                               goto fail;
+               }
                return data.domain->empty_types;
        }
 
-       data.iface_array = mono_array_new_cached (data.domain, mono_defaults.monotype_class, len);
+       data.iface_array = mono_array_new_cached (data.domain, mono_defaults.runtimetype_class, len, &error);
+       if (!is_ok (&error))
+               goto fail;
        g_hash_table_foreach (iface_hash, fill_iface_array, &data);
        if (!mono_error_ok (&error))
                goto fail;
@@ -2447,7 +2456,7 @@ fail:
 }
 
 ICALL_EXPORT void
-ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
+ves_icall_RuntimeType_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType *iface, MonoArray **targets, MonoArray **methods)
 {
        gboolean variance_used;
        MonoClass *klass = mono_class_from_mono_type (type->type);
@@ -2498,7 +2507,7 @@ ves_icall_Type_GetInterfaceMapData (MonoReflectionType *type, MonoReflectionType
 }
 
 ICALL_EXPORT void
-ves_icall_Type_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 *size)
+ves_icall_RuntimeType_GetPacking (MonoReflectionType *type, guint32 *packing, guint32 *size)
 {
        MonoError error;
        MonoClass *klass = mono_class_from_mono_type (type->type);
@@ -2632,7 +2641,7 @@ ves_icall_RuntimeTypeHandle_GetAssembly (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoReflectionType*
-ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
+ves_icall_RuntimeType_get_DeclaringType (MonoReflectionType *type)
 {
        MonoError error;
        MonoReflectionType *ret;
@@ -2661,7 +2670,7 @@ ves_icall_MonoType_get_DeclaringType (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoString*
-ves_icall_MonoType_get_Name (MonoReflectionType *type)
+ves_icall_RuntimeType_get_Name (MonoReflectionType *type)
 {
        MonoDomain *domain = mono_domain_get (); 
        MonoClass *klass = mono_class_from_mono_type (type->type);
@@ -2679,7 +2688,7 @@ ves_icall_MonoType_get_Name (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoString*
-ves_icall_MonoType_get_Namespace (MonoReflectionType *type)
+ves_icall_RuntimeType_get_Namespace (MonoReflectionType *type)
 {
        MonoDomain *domain = mono_domain_get (); 
        MonoClass *klass = mono_class_from_mono_type (type->type);
@@ -2715,7 +2724,7 @@ create_type_array (MonoDomain *domain, MonoBoolean runtimeTypeArray, int count,
 }
 
 ICALL_EXPORT MonoArray*
-ves_icall_MonoType_GetGenericArguments (MonoReflectionType *type, MonoBoolean runtimeTypeArray)
+ves_icall_RuntimeType_GetGenericArguments (MonoReflectionType *type, MonoBoolean runtimeTypeArray)
 {
        MonoError error;
        MonoReflectionType *rt;
@@ -2807,7 +2816,7 @@ ves_icall_RuntimeTypeHandle_GetGenericTypeDefinition_impl (MonoReflectionType *t
 }
 
 ICALL_EXPORT MonoReflectionType*
-ves_icall_Type_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
+ves_icall_RuntimeType_MakeGenericType (MonoReflectionType *type, MonoArray *type_array)
 {
        MonoError error;
        MonoReflectionType *ret;
@@ -2865,7 +2874,7 @@ ves_icall_RuntimeTypeHandle_HasInstantiation (MonoReflectionType *type)
 }
 
 ICALL_EXPORT gint32
-ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
+ves_icall_RuntimeType_GetGenericParameterPosition (MonoReflectionType *type)
 {
        if (!IS_MONOTYPE (type))
                return -1;
@@ -2876,7 +2885,7 @@ ves_icall_Type_GetGenericParameterPosition (MonoReflectionType *type)
 }
 
 ICALL_EXPORT GenericParameterAttributes
-ves_icall_Type_GetGenericParameterAttributes (MonoReflectionType *type)
+ves_icall_RuntimeType_GetGenericParameterAttributes (MonoReflectionType *type)
 {
        g_assert (IS_MONOTYPE (type));
        g_assert (is_generic_parameter (type->type));
@@ -2884,7 +2893,7 @@ ves_icall_Type_GetGenericParameterAttributes (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoArray *
-ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type)
+ves_icall_RuntimeType_GetGenericParameterConstraints (MonoReflectionType *type)
 {
        MonoError error;
        MonoReflectionType *rt;
@@ -2901,7 +2910,7 @@ ves_icall_Type_GetGenericParameterConstraints (MonoReflectionType *type)
        for (count = 0, ptr = param_info->constraints; ptr && *ptr; ptr++, count++)
                ;
 
-       res = mono_array_new_checked (domain, mono_defaults.monotype_class, count, &error);
+       res = mono_array_new_checked (domain, mono_defaults.runtimetype_class, count, &error);
        if (mono_error_set_pending_exception (&error))
                return NULL;
        for (i = 0; i < count; i++) {
@@ -2936,7 +2945,7 @@ ves_icall_EnumBuilder_setup_enum_type (MonoReflectionType *enumtype,
 }
 
 ICALL_EXPORT MonoReflectionMethod*
-ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type, 
+ves_icall_RuntimeType_GetCorrespondingInflatedMethod (MonoReflectionType *type, 
                                                    MonoReflectionMethod* generic)
 {
        MonoDomain *domain; 
@@ -2966,7 +2975,7 @@ ves_icall_MonoType_GetCorrespondingInflatedMethod (MonoReflectionType *type,
 }
 
 ICALL_EXPORT MonoReflectionMethod *
-ves_icall_MonoType_get_DeclaringMethod (MonoReflectionType *ref_type)
+ves_icall_RuntimeType_get_DeclaringMethod (MonoReflectionType *ref_type)
 {
        MonoMethod *method;
        MonoType *type = ref_type->type;
@@ -3304,7 +3313,9 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this_arg, Mo
                        return (MonoObject*)arr;
                }
        }
-       return mono_runtime_invoke_array (m, obj, params, NULL);
+       MonoObject *result = mono_runtime_invoke_array_checked (m, obj, params, &error);
+       mono_error_set_pending_exception (&error);
+       return result;
 }
 
 #ifndef DISABLE_REMOTING
@@ -3426,7 +3437,9 @@ ves_icall_InternalExecute (MonoReflectionMethod *method, MonoObject *this_arg, M
 
        /* This can be called only on MBR objects, so no need to unbox for valuetypes. */
        g_assert (!method->method->klass->valuetype);
-       result = mono_runtime_invoke_array (method->method, this_arg, params, NULL);
+       result = mono_runtime_invoke_array_checked (method->method, this_arg, params, &error);
+       if (mono_error_set_pending_exception (&error))
+               return NULL;
 
        for (i = 0, j = 0; i < mono_array_length (params); i++) {
                if (sig->params [i]->byref) {
@@ -3481,7 +3494,8 @@ write_enum_value (char *mem, int type, guint64 value)
                break;
        }
        case MONO_TYPE_U2:
-       case MONO_TYPE_I2: {
+       case MONO_TYPE_I2:
+       case MONO_TYPE_CHAR: {
                guint16 *p = (guint16 *)mem;
                *p = value;
                break;
@@ -3762,7 +3776,7 @@ enum {
 };
 
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetFields_internal (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoReflectionType *reftype)
+ves_icall_RuntimeType_GetFields_internal (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoError error;
        MonoDomain *domain; 
@@ -3842,7 +3856,9 @@ handle_parent:
        if (!(bflags & BFLAGS_DeclaredOnly) && (klass = klass->parent))
                goto handle_parent;
 
-       res = mono_array_new_cached (domain, mono_defaults.field_info_class, mono_ptr_array_size (tmp_array));
+       res = mono_array_new_cached (domain, mono_defaults.field_info_class, mono_ptr_array_size (tmp_array), &error);
+       if (!is_ok (&error))
+               goto fail;
 
        for (i = 0; i < mono_ptr_array_size (tmp_array); ++i)
                mono_array_setref (res, i, mono_ptr_array_get (tmp_array, i));
@@ -3987,7 +4003,7 @@ loader_error:
 }
 
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
+ves_icall_RuntimeType_GetMethodsByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
 {
        static MonoClass *MethodInfo_array;
        MonoError error;
@@ -4055,11 +4071,11 @@ failure:
 }
 
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
+ves_icall_RuntimeType_GetConstructors_internal (MonoReflectionType *type, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoDomain *domain; 
        MonoClass *startklass, *klass, *refklass;
-       MonoArray *res;
+       MonoArray *res = NULL;
        MonoMethod *method;
        MonoObject *member;
        int i, match;
@@ -4067,18 +4083,23 @@ ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflag
        MonoPtrArray tmp_array;
        MonoError error;
        
+       domain = ((MonoObject *)type)->vtable->domain;
+       if (type->type->byref) {
+               res = mono_array_new_cached (domain, mono_defaults.method_info_class, 0, &error);
+               mono_error_set_pending_exception (&error);
+               return res;
+       }
+
        mono_ptr_array_init (tmp_array, 4, MONO_ROOT_SOURCE_REFLECTION, "temporary reflection constructors list"); /*FIXME, guestimating*/
 
-       domain = ((MonoObject *)type)->vtable->domain;
-       if (type->type->byref)
-               return mono_array_new_cached (domain, mono_defaults.method_info_class, 0);
+
        klass = startklass = mono_class_from_mono_type (type->type);
        refklass = mono_class_from_mono_type (reftype->type);
 
        mono_class_setup_methods (klass);
        if (mono_class_has_failure (klass)) {
                mono_set_pending_exception (mono_class_get_exception_for_failure (klass));
-               return NULL;
+               goto leave;
        }
 
        iter = NULL;
@@ -4108,19 +4129,20 @@ ves_icall_Type_GetConstructors_internal (MonoReflectionType *type, guint32 bflag
                if (!match)
                        continue;
                member = (MonoObject*)mono_method_get_object_checked (domain, method, refklass, &error);
-               if (!mono_error_ok (&error)) {
-                       mono_error_set_pending_exception (&error);
-                       return NULL;
-               }
+               if (mono_error_set_pending_exception (&error))
+                       goto leave;
 
                mono_ptr_array_append (tmp_array, member);
        }
 
-       res = mono_array_new_cached (domain, mono_class_get_constructor_info_class (), mono_ptr_array_size (tmp_array));
+       res = mono_array_new_cached (domain, mono_class_get_constructor_info_class (), mono_ptr_array_size (tmp_array), &error);
+       if (mono_error_set_pending_exception (&error))
+               goto leave;
 
        for (i = 0; i < mono_ptr_array_size (tmp_array); ++i)
                mono_array_setref (res, i, mono_ptr_array_get (tmp_array, i));
 
+leave:
        mono_ptr_array_destroy (tmp_array);
 
        return res;
@@ -4185,7 +4207,7 @@ property_accessor_nonpublic (MonoMethod* accessor, gboolean start_klass)
 }
 
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
+ves_icall_RuntimeType_GetPropertiesByName (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoBoolean ignore_case, MonoReflectionType *reftype)
 {
        MonoError error;
        MonoDomain *domain; 
@@ -4203,11 +4225,15 @@ ves_icall_Type_GetPropertiesByName (MonoReflectionType *type, MonoString *name,
 
        mono_error_init (&error);
        
+       domain = ((MonoObject *)type)->vtable->domain;
+       if (type->type->byref) {
+               res = mono_array_new_cached (domain, mono_class_get_property_info_class (), 0, &error);
+               mono_error_set_pending_exception (&error);
+               return res;
+       }
+
        mono_ptr_array_init (tmp_array, 8, MONO_ROOT_SOURCE_REFLECTION, "temporary reflection properties list"); /*This the average for ASP.NET types*/
 
-       domain = ((MonoObject *)type)->vtable->domain;
-       if (type->type->byref)
-               return mono_array_new_cached (domain, mono_class_get_property_info_class (), 0);
        klass = startklass = mono_class_from_mono_type (type->type);
 
        if (name != NULL) {
@@ -4279,7 +4305,9 @@ handle_parent:
        g_hash_table_destroy (properties);
        g_free (propname);
 
-       res = mono_array_new_cached (domain, mono_class_get_property_info_class (), mono_ptr_array_size (tmp_array));
+       res = mono_array_new_cached (domain, mono_class_get_property_info_class (), mono_ptr_array_size (tmp_array), &error);
+       if (!is_ok (&error))
+               goto failure;
        for (i = 0; i < mono_ptr_array_size (tmp_array); ++i)
                mono_array_setref (res, i, mono_ptr_array_get (tmp_array, i));
 
@@ -4322,7 +4350,7 @@ event_equal (MonoEvent *event1, MonoEvent *event2)
 }
 
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetEvents_internal (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoReflectionType *reftype)
+ves_icall_RuntimeType_GetEvents_internal (MonoReflectionType *type, MonoString *name, guint32 bflags, MonoReflectionType *reftype)
 {
        MonoError error;
        MonoDomain *domain; 
@@ -4339,11 +4367,15 @@ ves_icall_Type_GetEvents_internal (MonoReflectionType *type, MonoString *name, g
 
        mono_error_init (&error);
        
+       domain = mono_object_domain (type);
+       if (type->type->byref) {
+               res = mono_array_new_cached (domain, mono_class_get_event_info_class (), 0, &error);
+               mono_error_set_pending_exception (&error);
+               return res;
+       }
+
        mono_ptr_array_init (tmp_array, 4, MONO_ROOT_SOURCE_REFLECTION, "temporary reflection events list");
 
-       domain = mono_object_domain (type);
-       if (type->type->byref)
-               return mono_array_new_cached (domain, mono_class_get_event_info_class (), 0);
        klass = startklass = mono_class_from_mono_type (type->type);
 
        events = g_hash_table_new (event_hash, (GEqualFunc)event_equal);
@@ -4418,7 +4450,9 @@ handle_parent:
 
        g_hash_table_destroy (events);
 
-       res = mono_array_new_cached (domain, mono_class_get_event_info_class (), mono_ptr_array_size (tmp_array));
+       res = mono_array_new_cached (domain, mono_class_get_event_info_class (), mono_ptr_array_size (tmp_array), &error);
+       if (!is_ok (&error))
+               goto failure;
 
        for (i = 0; i < mono_ptr_array_size (tmp_array); ++i)
                mono_array_setref (res, i, mono_ptr_array_get (tmp_array, i));
@@ -4449,7 +4483,7 @@ failure:
 }
 
 ICALL_EXPORT MonoArray*
-ves_icall_Type_GetNestedTypes (MonoReflectionType *type, MonoString *name, guint32 bflags)
+ves_icall_RuntimeType_GetNestedTypes (MonoReflectionType *type, MonoString *name, guint32 bflags)
 {
        MonoError error;
        MonoReflectionType *rt;
@@ -4466,7 +4500,7 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, MonoString *name, guint
 
        domain = ((MonoObject *)type)->vtable->domain;
        if (type->type->byref) {
-               MonoArray *result = mono_array_new_checked (domain, mono_defaults.monotype_class, 0, &error);
+               MonoArray *result = mono_array_new_cached (domain, mono_defaults.runtimetype_class, 0, &error);
                mono_error_set_pending_exception (&error);
                return result;
        }
@@ -4515,7 +4549,9 @@ ves_icall_Type_GetNestedTypes (MonoReflectionType *type, MonoString *name, guint
                mono_ptr_array_append (tmp_array, (MonoObject*) rt);
        }
 
-       res = mono_array_new_cached (domain, mono_defaults.monotype_class, mono_ptr_array_size (tmp_array));
+       res = mono_array_new_cached (domain, mono_defaults.runtimetype_class, mono_ptr_array_size (tmp_array), &error);
+       if (!is_ok (&error))
+               goto leave;
 
        for (i = 0; i < mono_ptr_array_size (tmp_array); ++i)
                mono_array_setref (res, i, mono_ptr_array_get (tmp_array, i));
@@ -5418,7 +5454,7 @@ ves_icall_System_MonoType_getFullName (MonoReflectionType *object, gboolean full
 }
 
 ICALL_EXPORT int
-vell_icall_MonoType_get_core_clr_security_level (MonoReflectionType *rfield)
+vell_icall_RuntimeType_get_core_clr_security_level (MonoReflectionType *rfield)
 {
        MonoError error;
        MonoClass *klass = mono_class_from_mono_type (rfield->type);
@@ -5707,7 +5743,7 @@ mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **excepti
        } else {
                count = tdef->rows - 1;
        }
-       res = mono_array_new_checked (domain, mono_defaults.monotype_class, count, error);
+       res = mono_array_new_checked (domain, mono_defaults.runtimetype_class, count, error);
        return_val_if_nok (error, NULL);
        *exceptions = mono_array_new_checked (domain, mono_defaults.exception_class, count, error);
        return_val_if_nok (error, NULL);
@@ -5774,14 +5810,14 @@ ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly,
                                        len1 = mono_array_length (res);
                                        len2 = mono_array_length (res2);
 
-                                       res3 = mono_array_new_checked (domain, mono_defaults.monotype_class, len1 + len2, &error);
+                                       res3 = mono_array_new_checked (domain, mono_defaults.runtimetype_class, len1 + len2, &error);
                                        if (mono_error_set_pending_exception (&error))
                                                return NULL;
                                        mono_array_memcpy_refs (res3, 0, res, 0, len1);
                                        mono_array_memcpy_refs (res3, len1, res2, 0, len2);
                                        res = res3;
 
-                                       ex3 = mono_array_new_checked (domain, mono_defaults.monotype_class, len1 + len2, &error);
+                                       ex3 = mono_array_new_checked (domain, mono_defaults.runtimetype_class, len1 + len2, &error);
                                        if (mono_error_set_pending_exception (&error))
                                                return NULL;
                                        mono_array_memcpy_refs (ex3, 0, exceptions, 0, len1);
@@ -5969,7 +6005,7 @@ ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *modul
        int i;
 
        if (!module->image) {
-               MonoArray *arr = mono_array_new_checked (mono_object_domain (module), mono_defaults.monotype_class, 0, &error);
+               MonoArray *arr = mono_array_new_checked (mono_object_domain (module), mono_defaults.runtimetype_class, 0, &error);
                mono_error_set_pending_exception (&error);
                return arr;
        } else {
@@ -6158,7 +6194,9 @@ ves_icall_System_Reflection_Module_ResolveStringToken (MonoImage *image, guint32
 
        /* FIXME: What to do if the index points into the middle of a string ? */
 
-       return mono_ldstr (mono_domain_get (), image, index);
+       MonoString *result = mono_ldstr_checked (mono_domain_get (), image, index, &error);
+       mono_error_set_pending_exception (&error);
+       return result;
 }
 
 ICALL_EXPORT MonoClassField*
@@ -6422,7 +6460,7 @@ check_for_invalid_type (MonoClass *klass, MonoError *error)
 
 }
 ICALL_EXPORT MonoReflectionType *
-ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
+ves_icall_RuntimeType_make_array_type (MonoReflectionType *type, int rank)
 {
        MonoError error;
        MonoReflectionType *ret;
@@ -6444,7 +6482,7 @@ ves_icall_Type_make_array_type (MonoReflectionType *type, int rank)
 }
 
 ICALL_EXPORT MonoReflectionType *
-ves_icall_Type_make_byref_type (MonoReflectionType *type)
+ves_icall_RuntimeType_make_byref_type (MonoReflectionType *type)
 {
        MonoError error;
        MonoReflectionType *ret;
@@ -6466,7 +6504,7 @@ ves_icall_Type_make_byref_type (MonoReflectionType *type)
 }
 
 ICALL_EXPORT MonoReflectionType *
-ves_icall_Type_MakePointerType (MonoReflectionType *type)
+ves_icall_RuntimeType_MakePointerType (MonoReflectionType *type)
 {
        MonoError error;
        MonoReflectionType *ret;
@@ -6527,7 +6565,9 @@ ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, Mon
 
        if (method_is_dynamic (method)) {
                /* Creating a trampoline would leak memory */
-               func = mono_compile_method (method);
+               func = mono_compile_method_checked (method, &error);
+               if (mono_error_set_pending_exception (&error))
+                       return NULL;
        } else {
                if (target && method->flags & METHOD_ATTRIBUTE_VIRTUAL && method->klass != mono_object_class (target))
                        method = mono_object_get_virtual_method (target, method);
@@ -6537,8 +6577,9 @@ ves_icall_System_Delegate_CreateDelegate_internal (MonoReflectionType *type, Mon
                func = mono_create_ftnptr (mono_domain_get (), trampoline);
        }
 
-       mono_delegate_ctor_with_method (delegate, target, func, method);
-
+       mono_delegate_ctor_with_method (delegate, target, func, method, &error);
+       if (mono_error_set_pending_exception (&error))
+               return NULL;
        return delegate;
 }
 
@@ -6692,17 +6733,15 @@ ves_icall_Remoting_RealProxy_GetTransparentProxy (MonoObject *this_obj, MonoStri
        }
 
        tp->custom_type_info = (mono_object_isinst_checked (this_obj, mono_defaults.iremotingtypeinfo_class, &error) != NULL);
-       if (!is_ok (&error)) {
-               mono_error_set_pending_exception (&error);
+       if (mono_error_set_pending_exception (&error))
                return NULL;
-       }
        tp->remote_class = mono_remote_class (domain, class_name, klass, &error);
-       if (!is_ok (&error)) {
-               mono_error_set_pending_exception (&error);
+       if (mono_error_set_pending_exception (&error))
                return NULL;
-       }
 
-       res->vtable = (MonoVTable *)mono_remote_class_vtable (domain, tp->remote_class, rp);
+       res->vtable = (MonoVTable *)mono_remote_class_vtable (domain, tp->remote_class, rp, &error);
+       if (mono_error_set_pending_exception (&error))
+               return NULL;
        return res;
 }
 
@@ -6970,14 +7009,6 @@ ves_icall_System_Environment_GetEnvironmentVariableNames (void)
 #endif
 }
 
-/*
- * If your platform lacks setenv/unsetenv, you must upgrade your glib.
- */
-#if !GLIB_CHECK_VERSION(2,4,0)
-#define g_setenv(a,b,c)   setenv(a,b,c)
-#define g_unsetenv(a) unsetenv(a)
-#endif
-
 ICALL_EXPORT void
 ves_icall_System_Environment_InternalSetEnvironmentVariable (MonoString *name, MonoString *value)
 {
@@ -7141,11 +7172,14 @@ leave:
 ICALL_EXPORT MonoString *
 ves_icall_System_IO_DriveInfo_GetDriveFormat (MonoString *path)
 {
+       MonoError error;
        gunichar2 volume_name [MAX_PATH + 1];
        
        if (GetVolumeInformation (mono_string_chars (path), NULL, 0, NULL, NULL, NULL, volume_name, MAX_PATH + 1) == FALSE)
                return NULL;
-       return mono_string_from_utf16 (volume_name);
+       MonoString *result = mono_string_from_utf16_checked (volume_name, &error);
+       mono_error_set_pending_exception (&error);
+       return result;
 }
 
 ICALL_EXPORT MonoString *
@@ -7250,6 +7284,14 @@ ves_icall_System_Environment_BroadcastSettingChange (void)
 #endif
 }
 
+ICALL_EXPORT
+gint32
+ves_icall_System_Environment_get_TickCount (void)
+{
+       /* this will overflow after ~24 days */
+       return (gint32) (mono_msec_boottime () & 0xffffffff);
+}
+
 ICALL_EXPORT gint32
 ves_icall_System_Runtime_Versioning_VersioningHelper_GetRuntimeId (void)
 {
@@ -7261,7 +7303,9 @@ ves_icall_MonoMethodMessage_InitMessage (MonoMethodMessage *this_obj,
                                         MonoReflectionMethod *method,
                                         MonoArray *out_args)
 {
-       mono_message_init (mono_object_domain (this_obj), this_obj, method, out_args);
+       MonoError error;
+       mono_message_init (mono_object_domain (this_obj), this_obj, method, out_args, &error);
+       mono_error_set_pending_exception (&error);
 }
 
 #ifndef DISABLE_REMOTING
@@ -7446,7 +7490,10 @@ ves_icall_System_IO_DriveInfo_GetDriveType (MonoString *root_path_name)
 ICALL_EXPORT gpointer
 ves_icall_RuntimeMethodHandle_GetFunctionPointer (MonoMethod *method)
 {
-       return mono_compile_method (method);
+       MonoError error;
+       gpointer result = mono_compile_method_checked (method, &error);
+       mono_error_set_pending_exception (&error);
+       return result;
 }
 
 ICALL_EXPORT MonoString *