From c5d8e417e2531b56dc765e38f3d5cb1156cf4224 Mon Sep 17 00:00:00 2001 From: Aleksey Kliger Date: Tue, 19 Jul 2016 19:22:43 -0400 Subject: [PATCH] [reflection] Marshal name arg of RuntimeType.GetNestedTypes in managed code Also do the name unmangling on the managed side. --- mcs/class/corlib/ReferenceSources/RuntimeType.cs | 10 +++++++--- mono/metadata/icall.c | 16 ++-------------- 2 files changed, 9 insertions(+), 17 deletions(-) diff --git a/mcs/class/corlib/ReferenceSources/RuntimeType.cs b/mcs/class/corlib/ReferenceSources/RuntimeType.cs index 983a429cf3e..8a49451936e 100644 --- a/mcs/class/corlib/ReferenceSources/RuntimeType.cs +++ b/mcs/class/corlib/ReferenceSources/RuntimeType.cs @@ -710,11 +710,15 @@ namespace System public extern override Type[] GetInterfaces(); [MethodImplAttribute(MethodImplOptions.InternalCall)] - extern IntPtr GetNestedTypes_native (string name, BindingFlags bindingAttr); + extern IntPtr GetNestedTypes_native (IntPtr name, BindingFlags bindingAttr); - RuntimeType[] GetNestedTypes_internal (string name, BindingFlags bindingAttr) + RuntimeType[] GetNestedTypes_internal (string displayName, BindingFlags bindingAttr) { - using (var h = new Mono.SafeGPtrArrayHandle (GetNestedTypes_native (name, bindingAttr))) { + string internalName = null; + if (displayName != null) + internalName = TypeIdentifiers.FromDisplay (displayName).InternalName; + using (var namePtr = new Mono.SafeStringMarshal (internalName)) + using (var h = new Mono.SafeGPtrArrayHandle (GetNestedTypes_native (namePtr.Value, bindingAttr))) { int n = h.Length; var a = new RuntimeType [n]; for (int i = 0; i < n; i++) { diff --git a/mono/metadata/icall.c b/mono/metadata/icall.c index 883be7ef758..165cdd39d8f 100644 --- a/mono/metadata/icall.c +++ b/mono/metadata/icall.c @@ -4354,13 +4354,12 @@ failure: } ICALL_EXPORT GPtrArray * -ves_icall_RuntimeType_GetNestedTypes_native (MonoReflectionType *type, MonoString *name, guint32 bflags) +ves_icall_RuntimeType_GetNestedTypes_native (MonoReflectionType *type, char *str, guint32 bflags) { MonoClass *klass; int match; MonoClass *nested; gpointer iter; - char *str = NULL; GPtrArray *res_array; if (type->type->byref) { @@ -4396,23 +4395,12 @@ ves_icall_RuntimeType_GetNestedTypes_native (MonoReflectionType *type, MonoStrin if (!match) continue; - if (name != NULL) { - if (str == NULL) { - str = mono_string_to_utf8_checked (name, &error); - if (!is_ok (&error)) - goto fail; - mono_identifier_unescape_type_name_chars (str); - } - - if (strcmp (nested->name, str)) + if (str != NULL && strcmp (nested->name, str)) continue; - } g_ptr_array_add (res_array, &nested->byval_arg); } - g_free (str); - return res_array; } -- 2.25.1