[runtime] Use MonoError for mono_module_get_types
authorLudovic Henry <ludovic@xamarin.com>
Fri, 12 Feb 2016 15:49:51 +0000 (15:49 +0000)
committerLudovic Henry <ludovic@xamarin.com>
Fri, 12 Feb 2016 16:26:46 +0000 (16:26 +0000)
mono/metadata/icall.c

index 690797ca895870d255b9a31bb49bc1a0b2f8aa71..dbf46a1a1dd54b9d491fb96e7deae7d50af86e5a 100644 (file)
@@ -5383,15 +5383,16 @@ mono_module_type_is_visible (MonoTableInfo *tdef, MonoImage *image, int type)
 }
 
 static MonoArray*
-mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **exceptions, MonoBoolean exportedOnly)
+mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **exceptions, MonoBoolean exportedOnly, MonoError *error)
 {
-       MonoError error;
        MonoReflectionType *rt;
        MonoArray *res;
        MonoClass *klass;
        MonoTableInfo *tdef = &image->tables [MONO_TABLE_TYPEDEF];
        int i, count;
 
+       mono_error_init (error);
+
        /* we start the count from 1 because we skip the special type <Module> */
        if (exportedOnly) {
                count = 0;
@@ -5407,17 +5408,17 @@ mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **excepti
        count = 0;
        for (i = 1; i < tdef->rows; ++i) {
                if (!exportedOnly || mono_module_type_is_visible (tdef, image, i + 1)) {
-                       klass = mono_class_get_checked (image, (i + 1) | MONO_TOKEN_TYPE_DEF, &error);
+                       klass = mono_class_get_checked (image, (i + 1) | MONO_TOKEN_TYPE_DEF, error);
                        mono_loader_assert_no_error (); /* Plug any leaks */
-                       g_assert (mono_error_ok (&error));
+                       mono_error_assert_ok (error);
                        
                        if (klass) {
-                               rt = mono_type_get_object_checked (domain, &klass->byval_arg, &error);
-                               mono_error_raise_exception (&error); /* FIXME don't raise here */
+                               rt = mono_type_get_object_checked (domain, &klass->byval_arg, error);
+                               return_val_if_nok (error, NULL);
 
                                mono_array_setref (res, count, rt);
                        } else {
-                               MonoException *ex = mono_error_convert_to_exception (&error);
+                               MonoException *ex = mono_error_convert_to_exception (error);
                                mono_array_setref (*exceptions, count, ex);
                        }
                        count++;
@@ -5430,6 +5431,7 @@ mono_module_get_types (MonoDomain *domain, MonoImage *image, MonoArray **excepti
 ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly, MonoBoolean exportedOnly)
 {
+       MonoError error;
        MonoArray *res = NULL;
        MonoArray *exceptions = NULL;
        MonoImage *image = NULL;
@@ -5443,7 +5445,8 @@ ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly,
        g_assert (!assembly_is_dynamic (assembly->assembly));
        image = assembly->assembly->image;
        table = &image->tables [MONO_TABLE_FILE];
-       res = mono_module_get_types (domain, image, &exceptions, exportedOnly);
+       res = mono_module_get_types (domain, image, &exceptions, exportedOnly, &error);
+       mono_error_raise_exception (&error);
 
        /* Append data from all modules in the assembly */
        for (i = 0; i < table->rows; ++i) {
@@ -5451,7 +5454,11 @@ ves_icall_System_Reflection_Assembly_GetTypes (MonoReflectionAssembly *assembly,
                        MonoImage *loaded_image = mono_assembly_load_module (image->assembly, i + 1);
                        if (loaded_image) {
                                MonoArray *ex2;
-                               MonoArray *res2 = mono_module_get_types (domain, loaded_image, &ex2, exportedOnly);
+                               MonoArray *res2;
+
+                               res2 = mono_module_get_types (domain, loaded_image, &ex2, exportedOnly, &error);
+                               mono_error_raise_exception (&error);
+
                                /* Append the new types to the end of the array */
                                if (mono_array_length (res2) > 0) {
                                        guint32 len1, len2;
@@ -5641,13 +5648,18 @@ ves_icall_System_Reflection_Module_GetMDStreamVersion (MonoImage *image)
 ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Module_InternalGetTypes (MonoReflectionModule *module)
 {
+       MonoError error;
        MonoArray *exceptions;
        int i;
 
        if (!module->image)
                return mono_array_new (mono_object_domain (module), mono_defaults.monotype_class, 0);
        else {
-               MonoArray *res = mono_module_get_types (mono_object_domain (module), module->image, &exceptions, FALSE);
+               MonoArray *res;
+
+               res = mono_module_get_types (mono_object_domain (module), module->image, &exceptions, FALSE, &error);
+               mono_error_raise_exception (&error);
+
                for (i = 0; i < mono_array_length (exceptions); ++i) {
                        MonoException *ex = mono_array_get (exceptions, MonoException *, i);
                        if (ex) {