Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -305,7 +305,6 @@ public static IEnumerable<object[]> MakeArrayType_ByRef_TestData()

[Theory]
[MemberData(nameof(MakeArrayType_ByRef_TestData))]
[ActiveIssue("https://github.com/dotnet/runtime/issues/39001", TestRuntimes.Mono)]
public void MakeArrayType_ByRef_ThrowsTypeLoadException(Type t)
{
Assert.Throws<TypeLoadException>(() => t.MakeArrayType());
Expand Down
20 changes: 15 additions & 5 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -6283,15 +6283,25 @@ ves_icall_System_Reflection_RuntimeModule_ResolveSignature (MonoImage *image, gu
}

static void
check_for_invalid_array_type (MonoClass *klass, MonoError *error)
check_for_invalid_array_type (MonoType *type, MonoError *error)
{
gboolean allowed = TRUE;
char *name;

error_init (error);

if (m_class_get_byval_arg (klass)->type != MONO_TYPE_TYPEDBYREF)
return;
if (type->byref)
allowed = FALSE;
else if (type->type == MONO_TYPE_TYPEDBYREF)
allowed = FALSE;

MonoClass *klass = mono_class_from_mono_type_internal (type);

if (m_class_is_byreflike (klass))
allowed = FALSE;

if (allowed)
return;
name = mono_type_get_full_name (klass);
mono_error_set_type_load_name (error, name, g_strdup (""), "");
}
Expand All @@ -6307,9 +6317,9 @@ ves_icall_RuntimeType_make_array_type (MonoReflectionTypeHandle ref_type, int ra
{
MonoType *type = MONO_HANDLE_GETVAL (ref_type, type);

MonoClass *klass = mono_class_from_mono_type_internal (type);
check_for_invalid_array_type (klass, error);
check_for_invalid_array_type (type, error);
return_val_if_nok (error, MONO_HANDLE_CAST (MonoReflectionType, NULL_HANDLE));
MonoClass *klass = mono_class_from_mono_type_internal (type);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I wonder if it is better to pass MonoClass *klass to check_for_invalid_array_type, since line 6298 will always be executed. That way we could save one function call.

Copy link
Member Author

@lambdageek lambdageek Jul 9, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

So the problem is that if you start with a MonoType and then call mono_class_from_mono_type_internal it is not an exact roundtrip. In particular you lose the MonoType:byref bit. Because a MonoClass is not able to represent a byref type. (This is kind of an annoying limitation in Mono but fixing it is probably a ton of work).

I thought about instead returning the klass from check_for_invalid_array_type, but it's kind of a weird incidental return value. In any case mono_class_from_mono_type_internal is pretty quick to call since it's just a switch on a value (MonoType:type) that we already looked at.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha! My original thought was to returning the klass from check_for_invalid_array_type. But since it is not costly, I am okay with current implementation.


MonoClass *aklass;
if (rank == 0) //single dimension array
Expand Down