diff --git a/runtime/coreclr-bridge.m b/runtime/coreclr-bridge.m index 0e20d47b8561..12fb568ab405 100644 --- a/runtime/coreclr-bridge.m +++ b/runtime/coreclr-bridge.m @@ -108,40 +108,24 @@ return method; } -MonoClass * -xamarin_get_nsnumber_class () -{ - xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__); -} - -MonoClass * -xamarin_get_nsvalue_class () -{ - xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__); -} - -MonoClass * -xamarin_get_inativeobject_class () -{ - xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__); -} - -MonoClass * -xamarin_get_nsobject_class () -{ - xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__); -} - -MonoClass * -xamarin_get_nsstring_class () +MonoType * +xamarin_get_nsnumber_type () { - xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__); + // xamarin_bridge_lookup_class returns a MonoClass*, and this method returns a MonoType*, + // but they're interchangeable for CoreCLR (they're all just MonoObject*s), so this is fine. + MonoClass *rv = xamarin_bridge_lookup_class (XamarinLookupTypes_Foundation_NSNumber); + LOG_CORECLR (stderr, "%s () => %p\n", __func__, rv); + return rv; } -MonoClass * -xamarin_get_runtime_class () +MonoType * +xamarin_get_nsvalue_type () { - xamarin_assertion_message ("The method %s it not implemented yet for CoreCLR", __func__); + // xamarin_bridge_lookup_class returns a MonoClass*, and this method returns a MonoType*, + // but they're interchangeable for CoreCLR (they're all just MonoObject*s), so this is fine. + MonoClass *rv = xamarin_bridge_lookup_class (XamarinLookupTypes_Foundation_NSValue); + LOG_CORECLR (stderr, "%s () => %p\n", __func__, rv); + return rv; } void @@ -529,7 +513,7 @@ MonoClass * mono_get_string_class () { - MonoClass *rv = xamarin_bridge_get_string_class (); + MonoClass *rv = xamarin_bridge_lookup_class (XamarinLookupTypes_System_String); LOG_CORECLR (stderr, "%s () => %p.\n", __func__, rv); return rv; } diff --git a/runtime/delegates.t4 b/runtime/delegates.t4 index e57f262f9c13..70bf16a71ccd 100644 --- a/runtime/delegates.t4 +++ b/runtime/delegates.t4 @@ -506,8 +506,10 @@ OnlyCoreCLR = true, }, - new XDelegate ("MonoObject *", "MonoObject *", "xamarin_bridge_get_string_class") { - WrappedManagedFunction = "GetStringClass", + new XDelegate ("MonoClass *", "MonoObject *", "xamarin_bridge_lookup_class", + "enum XamarinLookupTypes", "Runtime.TypeLookup", "type" + ) { + WrappedManagedFunction = "LookupType", OnlyDynamicUsage = false, OnlyCoreCLR = true, }, diff --git a/runtime/monovm-bridge.m b/runtime/monovm-bridge.m index 3bcd08e0afd4..d56a818b389b 100644 --- a/runtime/monovm-bridge.m +++ b/runtime/monovm-bridge.m @@ -172,20 +172,20 @@ return nsobject_class; } -MonoClass * -xamarin_get_nsvalue_class () +MonoType * +xamarin_get_nsvalue_type () { if (nsvalue_class == NULL) xamarin_assertion_message ("Internal consistency error, please file a bug (https://github.com/xamarin/xamarin-macios/issues/new). Additional data: can't get the %s class because it's been linked away.\n", "NSValue"); - return nsvalue_class; + return mono_class_get_type (nsvalue_class); } -MonoClass * -xamarin_get_nsnumber_class () +MonoType * +xamarin_get_nsnumber_type () { if (nsnumber_class == NULL) xamarin_assertion_message ("Internal consistency error, please file a bug (https://github.com/xamarin/xamarin-macios/issues/new). Additional data: can't get the %s class because it's been linked away.\n", "NSNumber"); - return nsnumber_class; + return mono_class_get_type (nsnumber_class); } MonoClass * @@ -324,7 +324,6 @@ // COOP: Reading managed data, must be in UNSAFE mode MONO_ASSERT_GC_UNSAFE; - MonoClass *nsnumber_class = xamarin_get_nsnumber_class (); if (nsnumber_class == NULL) return false; @@ -337,7 +336,6 @@ // COOP: Reading managed data, must be in UNSAFE mode MONO_ASSERT_GC_UNSAFE; - MonoClass *nsvalue_class = xamarin_get_nsvalue_class (); if (nsvalue_class == NULL) return false; diff --git a/runtime/trampolines.m b/runtime/trampolines.m index e2cae774fb1f..b6d5fd86a362 100644 --- a/runtime/trampolines.m +++ b/runtime/trampolines.m @@ -1462,7 +1462,7 @@ func = xamarin_get_nsnumber_converter (baseClass, method, to_managed, exception_gchandle); xamarin_mono_object_release (&baseClass); } else { - MonoType *nsnumberType = mono_class_get_type (xamarin_get_nsnumber_class ()); + MonoType *nsnumberType = xamarin_get_nsnumber_type (); *exception_gchandle = xamarin_create_bindas_exception (mtype, nsnumberType, method); xamarin_mono_object_release (&nsnumberType); goto exception_handling; @@ -1533,7 +1533,7 @@ #endif } else { MonoType *mType = mono_class_get_type (managedType); - MonoType *nsvalueType = mono_class_get_type (xamarin_get_nsvalue_class ()); + MonoType *nsvalueType = xamarin_get_nsvalue_type (); *exception_gchandle = xamarin_create_bindas_exception (mType, nsvalueType, method); xamarin_mono_object_release (&mType); xamarin_mono_object_release (&nsvalueType); diff --git a/runtime/xamarin/runtime.h b/runtime/xamarin/runtime.h index 293d0afd24bd..8e92d97f0b8c 100644 --- a/runtime/xamarin/runtime.h +++ b/runtime/xamarin/runtime.h @@ -254,8 +254,8 @@ MonoException * xamarin_create_system_entry_point_not_found_exception (const cha NSString * xamarin_print_all_exceptions (GCHandle handle); id xamarin_invoke_objc_method_implementation (id self, SEL sel, IMP xamarin_impl); -MonoClass * xamarin_get_nsnumber_class (); -MonoClass * xamarin_get_nsvalue_class (); +MonoType * xamarin_get_nsnumber_type (); +MonoType * xamarin_get_nsvalue_type (); MonoClass * xamarin_get_inativeobject_class (); MonoClass * xamarin_get_nsobject_class (); MonoClass * xamarin_get_nsstring_class (); diff --git a/src/ObjCRuntime/Runtime.CoreCLR.cs b/src/ObjCRuntime/Runtime.CoreCLR.cs index 7cdd5fc4fa6f..0bb068df994a 100644 --- a/src/ObjCRuntime/Runtime.CoreCLR.cs +++ b/src/ObjCRuntime/Runtime.CoreCLR.cs @@ -175,6 +175,29 @@ static bool IsClassOfType (Type type, TypeLookup match) return rv; } + static unsafe MonoObject* LookupType (TypeLookup type) + { + Type rv = null; + + switch (type) { + case TypeLookup.Foundation_NSNumber: + rv = typeof (Foundation.NSNumber); + break; + case TypeLookup.Foundation_NSValue: + rv = typeof (Foundation.NSValue); + break; + case TypeLookup.System_String: + rv = typeof (string); + break; + default: + throw new ArgumentOutOfRangeException (nameof (type)); + } + + log_coreclr ($"LookupType ({type}) => {rv}"); + + return (MonoObject*) GetMonoObject (rv); + } + static unsafe MonoObject* GetElementClass (MonoObject* classobj) { var type = (Type) GetMonoObjectTarget (classobj); @@ -663,11 +686,6 @@ static bool IsNullable (Type type) return false; } - static unsafe MonoObject* GetStringClass () - { - return (MonoObject *) GetMonoObject (typeof (string)); - } - unsafe static bool IsByRef (MonoObject *typeobj) { var type = (Type) GetMonoObjectTarget (typeobj);