Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[mono] Implement getting the type modifiers for DynamicMethod parameters #38646

Merged
merged 2 commits into from
Jul 1, 2020
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 @@ -44,14 +44,11 @@ public void DefineParameter_SetsParameterCorrectly()
Assert.Equal(ParameterAttributes.In, parameters[0].Attributes);
Assert.Equal(ParameterAttributes.Out, parameters[1].Attributes);

if (!PlatformDetection.IsMonoRuntime) // [ActiveIssue("https://github.com/dotnet/runtime/issues/36271")]
{
Assert.Empty(parameters[0].GetRequiredCustomModifiers());
Assert.Empty(parameters[1].GetRequiredCustomModifiers());

Assert.Empty(parameters[0].GetOptionalCustomModifiers());
Assert.Empty(parameters[1].GetOptionalCustomModifiers());
}
Assert.Empty(parameters[0].GetRequiredCustomModifiers());
Assert.Empty(parameters[1].GetRequiredCustomModifiers());

Assert.Empty(parameters[0].GetOptionalCustomModifiers());
Assert.Empty(parameters[1].GetOptionalCustomModifiers());
}
}
}
18 changes: 11 additions & 7 deletions src/mono/mono/metadata/icall.c
Original file line number Diff line number Diff line change
Expand Up @@ -171,7 +171,7 @@ static void
array_set_value_impl (MonoArrayHandle arr, MonoObjectHandle value, guint32 pos, gboolean strict_enums, gboolean strict_signs, MonoError *error);

static MonoArrayHandle
type_array_from_modifiers (MonoImage *image, MonoType *type, int optional, MonoError *error);
type_array_from_modifiers (MonoType *type, int optional, MonoError *error);

static inline MonoBoolean
is_generic_parameter (MonoType *type)
Expand Down Expand Up @@ -2291,7 +2291,7 @@ ves_icall_System_Reflection_FieldInfo_GetTypeModifiers (MonoReflectionFieldHandl
MonoType *type = mono_field_get_type_checked (field, error);
return_val_if_nok (error, NULL_HANDLE_ARRAY);

return type_array_from_modifiers (m_class_get_image (field->parent), type, optional, error);
return type_array_from_modifiers (type, optional, error);
}

int
Expand Down Expand Up @@ -8789,7 +8789,7 @@ add_modifier_to_array (MonoDomain *domain, MonoType *type, MonoArrayHandle dest,
* and avoid useless allocations.
*/
static MonoArrayHandle
type_array_from_modifiers (MonoImage *image, MonoType *type, int optional, MonoError *error)
type_array_from_modifiers (MonoType *type, int optional, MonoError *error)
{
int i, count = 0;
MonoDomain *domain = mono_domain_get ();
Expand Down Expand Up @@ -8845,6 +8845,12 @@ ves_icall_RuntimeParameterInfo_GetTypeModifiers (MonoReflectionTypeHandle rt, Mo
if (!(method = prop->get))
method = prop->set;
g_assert (method);
} else if (strcmp (m_class_get_name (member_class), "DynamicMethod") == 0 && strcmp (m_class_get_name_space (member_class), "System.Reflection.Emit") == 0) {
MonoArrayHandle params = MONO_HANDLE_NEW_GET (MonoArray, MONO_HANDLE_CAST (MonoReflectionDynamicMethod, member), parameters);
MonoReflectionTypeHandle t = MONO_HANDLE_NEW (MonoReflectionType, NULL);
MONO_HANDLE_ARRAY_GETREF (t, params, pos);
type = mono_reflection_type_handle_mono_type (t, error);
return type_array_from_modifiers (type, optional, error);
} else {
char *type_name = mono_type_get_full_name (member_class);
mono_error_set_not_supported (error, "Custom modifiers on a ParamInfo with member %s are not supported", type_name);
Expand All @@ -8859,7 +8865,7 @@ ves_icall_RuntimeParameterInfo_GetTypeModifiers (MonoReflectionTypeHandle rt, Mo
else
type = sig->params [pos];

return type_array_from_modifiers (image, type, optional, error);
return type_array_from_modifiers (type, optional, error);
}

static MonoType*
Expand All @@ -8881,13 +8887,11 @@ ves_icall_RuntimePropertyInfo_GetTypeModifiers (MonoReflectionPropertyHandle pro
{
error_init (error);
MonoProperty *prop = MONO_HANDLE_GETVAL (property, property);
MonoClass *klass = MONO_HANDLE_GETVAL (property, klass);
MonoType *type = get_property_type (prop);
MonoImage *image = m_class_get_image (klass);

if (!type)
return NULL_HANDLE_ARRAY;
return type_array_from_modifiers (image, type, optional, error);
return type_array_from_modifiers (type, optional, error);
}

/*
Expand Down