Skip to content

Commit

Permalink
Merge pull request mono#2567 from lambdageek/monoerror-mono_module_fi…
Browse files Browse the repository at this point in the history
…le_get_object

[reflection] Use MonoError in mono_module_file_get_object
  • Loading branch information
lambdageek committed Feb 6, 2016
2 parents 14fa173 + 8f0ecc7 commit 636c0c9
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 5 deletions.
7 changes: 5 additions & 2 deletions mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -4883,8 +4883,11 @@ ves_icall_System_Reflection_Assembly_GetModulesInternal (MonoReflectionAssembly

for (i = 0; i < file_count; ++i, ++j) {
mono_metadata_decode_row (table, i, cols, MONO_FILE_SIZE);
if (cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA)
mono_array_setref (res, j, mono_module_file_get_object (domain, image, i));
if (cols [MONO_FILE_FLAGS] && FILE_CONTAINS_NO_METADATA) {
MonoReflectionModule *rm = mono_module_file_get_object_checked (domain, image, i, &error);
mono_error_raise_exception (&error);
mono_array_setref (res, j, rm);
}
else {
MonoImage *m = mono_image_load_file_for_image (image, i + 1);
if (!m) {
Expand Down
2 changes: 2 additions & 0 deletions mono/metadata/reflection-internals.h
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ mono_method_get_object_checked (MonoDomain *domain, MonoMethod *method, MonoClas
MonoReflectionModule*
mono_module_get_object_checked (MonoDomain *domain, MonoImage *image, MonoError *error);

MonoReflectionModule*
mono_module_file_get_object_checked (MonoDomain *domain, MonoImage *image, int table_index, MonoError *error);

#endif /* __MONO_METADATA_REFLECTION_INTERNALS_H__ */
18 changes: 15 additions & 3 deletions mono/metadata/reflection.c
Original file line number Diff line number Diff line change
Expand Up @@ -6735,10 +6735,19 @@ mono_module_get_object_checked (MonoDomain *domain, MonoImage *image, MonoError
CACHE_OBJECT (MonoReflectionModule *, image, res, NULL);
}

MonoReflectionModule*
MonoReflectionModule*
mono_module_file_get_object (MonoDomain *domain, MonoImage *image, int table_index)
{
MonoError error;
MonoReflectionModule *result;
result = mono_module_file_get_object_checked (domain, image, table_index, &error);
mono_error_raise_exception (&error);
return result;
}

MonoReflectionModule*
mono_module_file_get_object_checked (MonoDomain *domain, MonoImage *image, int table_index, MonoError *error)
{
static MonoClass *module_type;
MonoReflectionModule *res;
MonoTableInfo *table;
Expand All @@ -6747,15 +6756,18 @@ mono_module_file_get_object (MonoDomain *domain, MonoImage *image, int table_ind
guint32 i, name_idx;
const char *val;

mono_error_init (error);

if (!module_type) {
MonoClass *klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "MonoModule");
if (klass == NULL)
klass = mono_class_from_name (mono_defaults.corlib, "System.Reflection", "Module");
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;

table = &image->tables [MONO_TABLE_FILE];
g_assert (table_index < table->rows);
Expand Down
1 change: 1 addition & 0 deletions mono/metadata/reflection.h
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ 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_RT_EXTERNAL_ONLY
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);
MONO_RT_EXTERNAL_ONLY
Expand Down

0 comments on commit 636c0c9

Please sign in to comment.