Skip to content

Commit

Permalink
[mono] Implement getting the type modifiers for DynamicMethod paramet…
Browse files Browse the repository at this point in the history
…ers (#38646)

* [mono] Implement getting the type modifiers for DynamicMethod parameters

Fixes #36271

* Remove unused parameter from type_array_from_modifiers()
  • Loading branch information
alexischr authored Jul 1, 2020
1 parent f6c6503 commit bbc9a56
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
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

0 comments on commit bbc9a56

Please sign in to comment.