From f51058395ed516bdd0dcb107388b95cc02f6af72 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 18 Oct 2022 17:15:12 +0200 Subject: [PATCH 1/9] #76881 internal properties in GetRuntimeProperties --- .../tests/RuntimeReflectionExtensionTests.cs | 13 +++++++++++++ src/mono/mono/metadata/icall.c | 4 ++-- 2 files changed, 15 insertions(+), 2 deletions(-) diff --git a/src/libraries/System.Reflection.Extensions/tests/RuntimeReflectionExtensionTests.cs b/src/libraries/System.Reflection.Extensions/tests/RuntimeReflectionExtensionTests.cs index 0dd03017c9e4b3..5b8aa82795c00c 100644 --- a/src/libraries/System.Reflection.Extensions/tests/RuntimeReflectionExtensionTests.cs +++ b/src/libraries/System.Reflection.Extensions/tests/RuntimeReflectionExtensionTests.cs @@ -101,6 +101,9 @@ public void GetRuntimeProperties() Assert.Contains("CanRead", propertyNames); Assert.Contains("CanWrite", propertyNames); Assert.Contains("CanSeek", propertyNames); + + List props = typeof(TestClass).GetRuntimeProperties().ToList(); + Assert.Equal(2, props.Count); } [Fact] @@ -359,6 +362,16 @@ private class TestDerived : TestBase public override void Foo() { throw null; } } + private class TestClassBase + { + internal int TestClassBaseProperty { get; set; } + } + + private class TestClass : TestClassBase + { + internal int TestClassProperty { get; set; } + } + abstract class TestTypeBase : IDisposable { public abstract bool CanRead { get; } diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index c8b16f7f400a68..bef9a0b41f94f6 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -4068,8 +4068,8 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl if (method) flags = method->flags; - if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)) || - (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) { + if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) != METHOD_ATTRIBUTE_PRIVATE)) || + (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) != METHOD_ATTRIBUTE_PRIVATE))) { if (bflags & BFLAGS_Public) match++; } else if (bflags & BFLAGS_NonPublic) { From 4877a658fcbeb8ee0f94c1235f59df562d4ef9eb Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 20 Oct 2022 14:43:27 +0200 Subject: [PATCH 2/9] #76881 remove excluding nonpublic props from base --- src/mono/mono/metadata/icall.c | 10 ++++------ 1 file changed, 4 insertions(+), 6 deletions(-) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index bef9a0b41f94f6..ec40d0110f4c85 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -4067,9 +4067,9 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl guint32 flags = 0; if (method) flags = method->flags; - - if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) != METHOD_ATTRIBUTE_PRIVATE)) || - (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) != METHOD_ATTRIBUTE_PRIVATE))) { + + if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)) || + (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) { if (bflags & BFLAGS_Public) match++; } else if (bflags & BFLAGS_NonPublic) { @@ -4106,9 +4106,7 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl g_hash_table_insert (properties, prop, prop); } if (!(bflags & BFLAGS_DeclaredOnly) && (klass = m_class_get_parent (klass))) { - // BFLAGS_NonPublic should be excluded for base classes - bflags &= ~BFLAGS_NonPublic; - goto handle_parent; + goto handle_parent; } g_hash_table_destroy (properties); From f4f5023ea026a4e236b840be0595b9c6fa53b554 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 20 Oct 2022 15:19:37 +0200 Subject: [PATCH 3/9] #76881 fix whitespace --- src/mono/mono/metadata/icall.c | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index ec40d0110f4c85..771000f5f45b2c 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -4067,8 +4067,8 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl guint32 flags = 0; if (method) flags = method->flags; - - if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)) || + + if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)) || (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) { if (bflags & BFLAGS_Public) match++; From d6324a5dfd1689f83b1c53d49d7f5a390bb85b58 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 20 Oct 2022 15:22:47 +0200 Subject: [PATCH 4/9] #76881 fix whitespace --- src/mono/mono/metadata/icall.c | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 771000f5f45b2c..9e0cd655a03164 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -4068,7 +4068,7 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl if (method) flags = method->flags; - if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)) || + if ((prop->get && ((prop->get->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC)) || (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) { if (bflags & BFLAGS_Public) match++; From 2b27fced4c1e533909d2ae91f6319096b4fb1e82 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 25 Oct 2022 16:54:22 +0200 Subject: [PATCH 5/9] #76881 removed bflags & BFLAGS_NonPublic check --- src/mono/mono/metadata/icall.c | 6 +----- 1 file changed, 1 insertion(+), 5 deletions(-) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 9e0cd655a03164..ee37afe8b87b87 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -4032,8 +4032,6 @@ property_accessor_nonpublic (MonoMethod* accessor, gboolean start_klass) GPtrArray* ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handle, gchar *propname, guint32 bflags, guint32 mlisttype, MonoError *error) { - // Fetch non-public properties as well because they can hide public properties with the same name in base classes - bflags |= BFLAGS_NonPublic; MonoType *type = type_handle.type; if (m_type_is_byref (type)) @@ -4072,11 +4070,9 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) { if (bflags & BFLAGS_Public) match++; - } else if (bflags & BFLAGS_NonPublic) { - if (property_accessor_nonpublic(prop->get, startklass == klass) || + } else if (property_accessor_nonpublic(prop->get, startklass == klass) || property_accessor_nonpublic(prop->set, startklass == klass)) { match++; - } } if (!match) continue; From b7e92bb43a917dcc40c70333a869ff8e05f2faa4 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Wed, 26 Oct 2022 15:02:06 +0200 Subject: [PATCH 6/9] #76881 check in initially TestIcuAppLocal passed --- src/mono/mono/metadata/icall.c | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index ee37afe8b87b87..9ccb8163c54cc9 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -4032,6 +4032,8 @@ property_accessor_nonpublic (MonoMethod* accessor, gboolean start_klass) GPtrArray* ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handle, gchar *propname, guint32 bflags, guint32 mlisttype, MonoError *error) { + // Fetch non-public properties as well because they can hide public properties with the same name in base classes + bflags |= BFLAGS_NonPublic; MonoType *type = type_handle.type; if (m_type_is_byref (type)) @@ -4070,9 +4072,11 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) { if (bflags & BFLAGS_Public) match++; - } else if (property_accessor_nonpublic(prop->get, startklass == klass) || + } else if (bflags & BFLAGS_NonPublic) { + if (property_accessor_nonpublic(prop->get, startklass == klass) || property_accessor_nonpublic(prop->set, startklass == klass)) { match++; + } } if (!match) continue; @@ -4102,7 +4106,9 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl g_hash_table_insert (properties, prop, prop); } if (!(bflags & BFLAGS_DeclaredOnly) && (klass = m_class_get_parent (klass))) { - goto handle_parent; + // BFLAGS_NonPublic should be excluded for base classes + bflags &= ~BFLAGS_NonPublic; + goto handle_parent; } g_hash_table_destroy (properties); From 9109c0ff247db0336716c64743ca475e4fb26b42 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 27 Oct 2022 09:46:00 +0200 Subject: [PATCH 7/9] #76881 removed operations with bflags --- src/mono/mono/metadata/icall.c | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/src/mono/mono/metadata/icall.c b/src/mono/mono/metadata/icall.c index 9ccb8163c54cc9..7ce33a2383f407 100644 --- a/src/mono/mono/metadata/icall.c +++ b/src/mono/mono/metadata/icall.c @@ -4032,8 +4032,6 @@ property_accessor_nonpublic (MonoMethod* accessor, gboolean start_klass) GPtrArray* ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handle, gchar *propname, guint32 bflags, guint32 mlisttype, MonoError *error) { - // Fetch non-public properties as well because they can hide public properties with the same name in base classes - bflags |= BFLAGS_NonPublic; MonoType *type = type_handle.type; if (m_type_is_byref (type)) @@ -4072,11 +4070,9 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl (prop->set && ((prop->set->flags & METHOD_ATTRIBUTE_MEMBER_ACCESS_MASK) == METHOD_ATTRIBUTE_PUBLIC))) { if (bflags & BFLAGS_Public) match++; - } else if (bflags & BFLAGS_NonPublic) { - if (property_accessor_nonpublic(prop->get, startklass == klass) || + } else if (property_accessor_nonpublic(prop->get, startklass == klass) || property_accessor_nonpublic(prop->set, startklass == klass)) { match++; - } } if (!match) continue; @@ -4106,8 +4102,6 @@ ves_icall_RuntimeType_GetPropertiesByName_native (MonoQCallTypeHandle type_handl g_hash_table_insert (properties, prop, prop); } if (!(bflags & BFLAGS_DeclaredOnly) && (klass = m_class_get_parent (klass))) { - // BFLAGS_NonPublic should be excluded for base classes - bflags &= ~BFLAGS_NonPublic; goto handle_parent; } From 1975aace0af30ea75367f0ff06d827ec620a7c9a Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Tue, 1 Nov 2022 14:26:45 +0100 Subject: [PATCH 8/9] #76881 enable System.Reflection tests on android --- src/libraries/tests.proj | 1 - 1 file changed, 1 deletion(-) diff --git a/src/libraries/tests.proj b/src/libraries/tests.proj index f9f9f94a8204e4..dfc547b652280e 100644 --- a/src/libraries/tests.proj +++ b/src/libraries/tests.proj @@ -171,7 +171,6 @@ - From 22d3c2d59ef47c86180b5754347070b0482a94f9 Mon Sep 17 00:00:00 2001 From: Meri Khamoyan Date: Thu, 3 Nov 2022 09:29:45 +0100 Subject: [PATCH 9/9] #76881 disabling failing tests --- src/libraries/System.Reflection/tests/AssemblyTests.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/libraries/System.Reflection/tests/AssemblyTests.cs b/src/libraries/System.Reflection/tests/AssemblyTests.cs index bd86b761db560f..a3808541dcf8d5 100644 --- a/src/libraries/System.Reflection/tests/AssemblyTests.cs +++ b/src/libraries/System.Reflection/tests/AssemblyTests.cs @@ -148,7 +148,7 @@ public void ExportedTypes(Type type, bool expected) [Fact] [SkipOnPlatform(TestPlatforms.Browser, "entry assembly won't be xunit.console on browser")] - [ActiveIssue("https://github.com/dotnet/runtime/issues/36892", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst)] + [ActiveIssue("https://github.com/dotnet/runtime/issues/36892", TestPlatforms.iOS | TestPlatforms.tvOS | TestPlatforms.MacCatalyst | TestPlatforms.Android)] public void GetEntryAssembly() { Assert.NotNull(Assembly.GetEntryAssembly()); @@ -872,6 +872,7 @@ public static void AssemblyGetForwardedTypes() [Fact] [ActiveIssue("https://github.com/dotnet/runtimelab/issues/155", typeof(PlatformDetection), nameof(PlatformDetection.IsNativeAot))] + [ActiveIssue("https://github.com/dotnet/runtimelab/issues/77821", TestPlatforms.Android)] public static void AssemblyGetForwardedTypesLoadFailure() { Assembly a = typeof(TypeInForwardedAssembly).Assembly;