Merge pull request #1404 from woodsb02/mono-route
[mono.git] / mono / metadata / icall.c
index 763b2f638bff16a7463b9ef207bf0ce2e33a2706..48eb780b944c1ff25a581301940af5ac116ff2d6 100644 (file)
@@ -45,6 +45,7 @@
 #include <mono/metadata/exception.h>
 #include <mono/metadata/file-io.h>
 #include <mono/metadata/console-io.h>
+#include <mono/metadata/mono-route.h>
 #include <mono/metadata/socket-io.h>
 #include <mono/metadata/mono-endian.h>
 #include <mono/metadata/tokentype.h>
@@ -1898,14 +1899,23 @@ ves_icall_MonoField_GetRawConstantValue (MonoReflectionField *this)
                mono_raise_exception (mono_get_exception_invalid_operation (NULL));
 
        if (image_is_dynamic (field->parent->image)) {
-               /* FIXME: */
-               g_assert_not_reached ();
+               MonoClass *klass = field->parent;
+               int fidx = field - klass->fields;
+
+               g_assert (fidx >= 0 && fidx < klass->field.count);
+               g_assert (klass->ext);
+               g_assert (klass->ext->field_def_values);
+               def_type = klass->ext->field_def_values [fidx].def_type;
+               def_value = klass->ext->field_def_values [fidx].data;
+               if (def_type == MONO_TYPE_END)
+                       mono_raise_exception (mono_get_exception_invalid_operation (NULL));
+       } else {
+               def_value = mono_class_get_field_default_value (field, &def_type);
+               /* FIXME, maybe we should try to raise TLE if field->parent is broken */
+               if (!def_value)
+                       mono_raise_exception (mono_get_exception_invalid_operation (NULL));
        }
 
-       def_value = mono_class_get_field_default_value (field, &def_type);
-       if (!def_value) /*FIXME, maybe we should try to raise TLE if field->parent is broken */
-               mono_raise_exception (mono_get_exception_invalid_operation (NULL));
-
        /*FIXME unify this with reflection.c:mono_get_object_from_blob*/
        switch (def_type) {
        case MONO_TYPE_U1:
@@ -2843,6 +2853,18 @@ ves_icall_InternalInvoke (MonoReflectionMethod *method, MonoObject *this, MonoAr
                for (i = 0; i < pcount; ++i)
                        lengths [i] = *(int32_t*) ((char*)mono_array_get (params, gpointer, i) + sizeof (MonoObject));
 
+               if (m->klass->rank == 1 && sig->param_count == 2 && m->klass->element_class->rank) {
+                       /* This is a ctor for jagged arrays. MS creates an array of arrays. */
+                       MonoArray *arr = mono_array_new_full (mono_object_domain (params), m->klass, lengths, NULL);
+
+                       for (i = 0; i < mono_array_length (arr); ++i) {
+                               MonoArray *subarray = mono_array_new_full (mono_object_domain (params), m->klass->element_class, &lengths [1], NULL);
+
+                               mono_array_setref_fast (arr, i, subarray);
+                       }
+                       return (MonoObject*)arr;
+               }
+
                if (m->klass->rank == pcount) {
                        /* Only lengths provided. */
                        lower_bounds = NULL;
@@ -2992,10 +3014,12 @@ static guint64
 read_enum_value (char *mem, int type)
 {
        switch (type) {
+       case MONO_TYPE_BOOLEAN:
        case MONO_TYPE_U1:
                return *(guint8*)mem;
        case MONO_TYPE_I1:
                return *(gint8*)mem;
+       case MONO_TYPE_CHAR:
        case MONO_TYPE_U2:
                return *(guint16*)mem;
        case MONO_TYPE_I2:
@@ -3071,7 +3095,7 @@ ves_icall_System_Enum_ToObject (MonoReflectionType *enumType, MonoObject *value)
 
        if (!enumc->enumtype)
                mono_raise_exception (mono_get_exception_argument ("enumType", "Type provided must be an Enum."));
-       if (!((objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_I1 && objc->byval_arg.type <= MONO_TYPE_U8)))
+       if (!((objc->enumtype) || (objc->byval_arg.type >= MONO_TYPE_BOOLEAN && objc->byval_arg.type <= MONO_TYPE_U8)))
                mono_raise_exception (mono_get_exception_argument ("value", "The value passed in must be an enum base or an underlying type for an enum, such as an Int32."));
 
        etype = mono_class_enum_basetype (enumc);
@@ -5559,19 +5583,20 @@ ves_icall_System_Reflection_Module_ResolveStringToken (MonoImage *image, guint32
 }
 
 ICALL_EXPORT MonoClassField*
-ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32 token, MonoArray *type_args, MonoArray *method_args, MonoResolveTokenError *error)
+ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32 token, MonoArray *type_args, MonoArray *method_args, MonoResolveTokenError *resolve_error)
 {
+       MonoError error;
        MonoClass *klass;
        int table = mono_metadata_token_table (token);
        int index = mono_metadata_token_index (token);
        MonoGenericContext context;
        MonoClassField *field;
 
-       *error = ResolveTokenError_Other;
+       *resolve_error = ResolveTokenError_Other;
 
        /* Validate token */
        if ((table != MONO_TABLE_FIELD) && (table != MONO_TABLE_MEMBERREF)) {
-               *error = ResolveTokenError_BadTable;
+               *resolve_error = ResolveTokenError_BadTable;
                return NULL;
        }
 
@@ -5580,7 +5605,7 @@ ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32
                        return mono_lookup_dynamic_token_class (image, token, FALSE, NULL, NULL);
 
                if (mono_memberref_is_method (image, token)) {
-                       *error = ResolveTokenError_BadTable;
+                       *resolve_error = ResolveTokenError_BadTable;
                        return NULL;
                }
 
@@ -5589,19 +5614,17 @@ ves_icall_System_Reflection_Module_ResolveFieldToken (MonoImage *image, guint32
        }
 
        if ((index <= 0) || (index > image->tables [table].rows)) {
-               *error = ResolveTokenError_OutOfRange;
+               *resolve_error = ResolveTokenError_OutOfRange;
                return NULL;
        }
        if ((table == MONO_TABLE_MEMBERREF) && (mono_memberref_is_method (image, token))) {
-               *error = ResolveTokenError_BadTable;
+               *resolve_error = ResolveTokenError_BadTable;
                return NULL;
        }
 
        init_generic_context_from_args (&context, type_args, method_args);
-       field = mono_field_from_token (image, token, &klass, &context);
-
-       if (mono_loader_get_last_error ())
-               mono_raise_exception (mono_loader_error_prepare_exception (mono_loader_get_last_error ()));
+       field = mono_field_from_token_checked (image, token, &klass, &context, &error);
+       mono_error_raise_exception (&error);
        
        return field;
 }