[reflection] Use MonoError for mono_module_get_object
authorAleksey Kliger <aleksey@xamarin.com>
Fri, 29 Jan 2016 17:15:50 +0000 (12:15 -0500)
committerAleksey Kliger <aleksey@xamarin.com>
Wed, 3 Feb 2016 22:02:54 +0000 (17:02 -0500)
Mark mono_module_get_object external only.
Runtime should use mono_module_get_object_checked.

mono/metadata/icall.c
mono/metadata/reflection-internals.h
mono/metadata/reflection.c
mono/metadata/reflection.h

index 94e66c8097190720bb7810773743169fcd2c3f3c..09075aabfb221fcf0c059ba59bf2d9d6b3c1cf94 100644 (file)
@@ -2406,8 +2406,13 @@ ves_icall_type_iscomobject (MonoReflectionType *type)
 ICALL_EXPORT MonoReflectionModule*
 ves_icall_MonoType_get_Module (MonoReflectionType *type)
 {
+       MonoError error;
+       MonoReflectionModule *result = NULL;
        MonoClass *klass = mono_class_from_mono_type (type->type);
-       return mono_module_get_object (mono_object_domain (type), klass->image);
+       result = mono_module_get_object_checked (mono_object_domain (type), klass->image, &error);
+       if (!mono_error_ok (&error))
+               mono_error_set_pending_exception (&error);
+       return result;
 }
 
 ICALL_EXPORT MonoReflectionAssembly*
@@ -4520,7 +4525,12 @@ leave:
 ICALL_EXPORT MonoReflectionModule*
 ves_icall_System_Reflection_Assembly_GetManifestModuleInternal (MonoReflectionAssembly *assembly) 
 {
-       return mono_module_get_object (mono_object_domain (assembly), assembly->assembly->image);
+       MonoError error;
+       MonoReflectionModule *result = NULL;
+       result = mono_module_get_object_checked (mono_object_domain (assembly), assembly->assembly->image, &error);
+       if (!mono_error_ok (&error))
+               mono_error_set_pending_exception (&error);
+       return result;
 }
 
 ICALL_EXPORT MonoArray*
@@ -4673,6 +4683,7 @@ g_concat_dir_and_file (const char *dir, const char *file)
 ICALL_EXPORT void *
 ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflectionAssembly *assembly, MonoString *name, gint32 *size, MonoReflectionModule **ref_module) 
 {
+       MonoError error;
        char *n = mono_string_to_utf8 (name);
        MonoTableInfo *table = &assembly->assembly->image->tables [MONO_TABLE_MANIFESTRESOURCE];
        guint32 i;
@@ -4707,7 +4718,10 @@ ves_icall_System_Reflection_Assembly_GetManifestResourceInternal (MonoReflection
        else
                module = assembly->assembly->image;
 
-       mono_gc_wbarrier_generic_store (ref_module, (MonoObject*) mono_module_get_object (mono_domain_get (), module));
+       
+       MonoReflectionModule *rm = mono_module_get_object_checked (mono_domain_get (), module, &error);
+       mono_error_raise_exception (&error);
+       mono_gc_wbarrier_generic_store (ref_module, (MonoObject*) rm);
 
        return (void*)mono_image_get_resource (module, cols [MONO_MANIFEST_OFFSET], (guint32*)size);
 }
@@ -4827,6 +4841,7 @@ ves_icall_System_Reflection_Assembly_GetFilesInternal (MonoReflectionAssembly *a
 ICALL_EXPORT MonoArray*
 ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly *assembly)
 {
+       MonoError error;
        MonoDomain *domain = mono_domain_get();
        MonoArray *res;
        MonoClass *klass;
@@ -4854,11 +4869,15 @@ ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly
        klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "Module");
        res = mono_array_new (domain, klass, 1 + real_module_count + file_count);
 
-       mono_array_setref (res, 0, mono_module_get_object (domain, image));
+       MonoReflectionModule *image_obj = mono_module_get_object_checked (domain, image, &error);
+       mono_error_raise_exception (&error);
+       mono_array_setref (res, 0, image_obj);
        j = 1;
        for (i = 0; i < module_count; ++i)
                if (modules [i]) {
-                       mono_array_setref (res, j, mono_module_get_object (domain, modules[i]));
+                       MonoReflectionModule *rm = mono_module_get_object_checked (domain, modules[i], &error);
+                       mono_error_raise_exception (&error);
+                       mono_array_setref (res, j, rm);
                        ++j;
                }
 
@@ -4873,7 +4892,9 @@ ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly
                                mono_set_pending_exception (mono_get_exception_file_not_found2 (NULL, fname));
                                return NULL;
                        }
-                       mono_array_setref (res, j, mono_module_get_object (domain, m));
+                       MonoReflectionModule *rm = mono_module_get_object_checked (domain, m, &error);
+                       mono_error_raise_exception (&error);
+                       mono_array_setref (res, j, rm);
                }
        }
 
index bee7702d1299f2aa0090b2e1ff098a2b71906e68..ffdda712f11a7a34c1d5d1c872911ce8a6ff7d71 100644 (file)
@@ -26,4 +26,8 @@ mono_field_get_object_checked (MonoDomain *domain, MonoClass *klass, MonoClassFi
 MonoReflectionMethod*
 mono_method_get_object_checked (MonoDomain *domain, MonoMethod *method, MonoClass *refclass, MonoError *error);
 
+MonoReflectionModule*
+mono_module_get_object_checked (MonoDomain *domain, MonoImage *image, MonoError *error);
+
+
 #endif /* __MONO_METADATA_REFLECTION_INTERNALS_H__ */
index 658d20f8b5b2e81f6767d388d085d998ccd46383..eb7e5cc4cf5c0c764deeeebde0f17b1a14667840 100644 (file)
@@ -6408,6 +6408,8 @@ mono_image_create_pefile (MonoReflectionModuleBuilder *mb, HANDLE file, MonoErro
 MonoReflectionModule *
 mono_image_load_module_dynamic (MonoReflectionAssemblyBuilder *ab, MonoString *fileName)
 {
+       MonoError error;
+       MonoReflectionModule *result = NULL;
        char *name;
        MonoImage *image;
        MonoImageOpenStatus status;
@@ -6457,7 +6459,9 @@ mono_image_load_module_dynamic (MonoReflectionAssemblyBuilder *ab, MonoString *f
                mono_raise_exception (mono_get_exception_file_not_found (fileName));
        }
 
-       return mono_module_get_object (mono_domain_get (), image);
+       result = mono_module_get_object_checked (mono_domain_get (), image, &error);
+       mono_error_raise_exception (&error); /* FIXME don't raise here */
+       return result;
 }
 
 #endif /* DISABLE_REFLECTION_EMIT */
@@ -6678,10 +6682,20 @@ MonoReflectionModule*
 mono_module_get_object   (MonoDomain *domain, MonoImage *image)
 {
        MonoError error;
+       MonoReflectionModule *result;
+       result = mono_module_get_object_checked (domain, image, &error);
+       mono_error_raise_exception (&error);
+       return result;
+}
+
+MonoReflectionModule*
+mono_module_get_object_checked (MonoDomain *domain, MonoImage *image, MonoError *error)
+{
        static MonoClass *module_type;
        MonoReflectionModule *res;
        char* basename;
        
+       mono_error_init (error);
        CHECK_OBJECT (MonoReflectionModule *, image, NULL);
        if (!module_type) {
                MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "MonoModule");
@@ -6690,8 +6704,9 @@ mono_module_get_object   (MonoDomain *domain, MonoImage *image)
                g_assert (klass);
                module_type = klass;
        }
-       res = (MonoReflectionModule *)mono_object_new_checked (domain, module_type, &error);
-       mono_error_raise_exception (&error); /* FIXME don't raise here */
+       res = (MonoReflectionModule *)mono_object_new_checked (domain, module_type, error);
+       if (!res)
+               return NULL;
 
        res->image = image;
        MONO_OBJECT_SETREF (res, assembly, (MonoReflectionAssembly *) mono_assembly_get_object(domain, image->assembly));
index 8da4879fe3c5f0563c0be191e771c4ade6379fb2..0d3de7d734728623f0caa969e1a13936190b0d5a 100644 (file)
@@ -48,6 +48,7 @@ MONO_API MonoType*     mono_reflection_type_from_name (char *name, MonoImage *im
 MONO_API uint32_t      mono_reflection_get_token (MonoObject *obj);
 
 MONO_API MonoReflectionAssembly* mono_assembly_get_object (MonoDomain *domain, MonoAssembly *assembly);
+MONO_RT_EXTERNAL_ONLY
 MONO_API MonoReflectionModule*   mono_module_get_object   (MonoDomain *domain, MonoImage *image);
 MONO_API MonoReflectionModule*   mono_module_file_get_object (MonoDomain *domain, MonoImage *image, int table_index);
 MONO_API MonoReflectionType*     mono_type_get_object     (MonoDomain *domain, MonoType *type);