[runtime] Implement mono_method_get_class for CoreCLR. (#11389)
This commit is contained in:
Родитель
6f743fd292
Коммит
8e9f86aad8
|
@ -231,4 +231,12 @@ mono_jit_exec (MonoDomain * domain, MonoAssembly * assembly, int argc, const cha
|
|||
return (int) exitCode;
|
||||
}
|
||||
|
||||
MonoClass *
|
||||
mono_method_get_class (MonoMethod * method)
|
||||
{
|
||||
MonoClass *rv = xamarin_bridge_get_method_declaring_type (method);
|
||||
LOG_CORECLR (stderr, "%s (%p) => %p\n", __func__, method, rv);
|
||||
return rv;
|
||||
}
|
||||
|
||||
#endif // CORECLR_RUNTIME
|
||||
|
|
|
@ -341,6 +341,13 @@
|
|||
OnlyCoreCLR = true,
|
||||
},
|
||||
|
||||
new XDelegate ("MonoObject *", "IntPtr", "xamarin_bridge_get_method_declaring_type",
|
||||
"MonoObject *", "IntPtr", "gchandle"
|
||||
) {
|
||||
WrappedManagedFunction = "GetMethodDeclaringType",
|
||||
OnlyDynamicUsage = false,
|
||||
OnlyCoreCLR = true,
|
||||
},
|
||||
};
|
||||
delegates.CalculateLengths ();
|
||||
#><#+
|
||||
|
|
|
@ -329,7 +329,9 @@
|
|||
|
||||
new Export ("MonoClass *", "mono_method_get_class",
|
||||
"MonoMethod *", "method"
|
||||
),
|
||||
) {
|
||||
HasCoreCLRBridgeFunction = true,
|
||||
},
|
||||
|
||||
new Export ("void", "mono_dllmap_insert",
|
||||
"MonoImage *", "assembly",
|
||||
|
|
|
@ -82,7 +82,12 @@ typedef enum {
|
|||
} MonoImageOpenStatus;
|
||||
|
||||
/* metadata/metadata.h */
|
||||
#if defined (CORECLR_RUNTIME)
|
||||
// In Mono, MonoClass is not related to MonoObject at all, but for the CoreCLR bridge we use the same struct representation for both types.
|
||||
typedef struct _MonoObject MonoClass;
|
||||
#else
|
||||
typedef struct _MonoClass MonoClass;
|
||||
#endif
|
||||
typedef struct _MonoDomain MonoDomain;
|
||||
#if defined (CORECLR_RUNTIME)
|
||||
// In Mono, MonoMethod is not related to MonoObject at all, but for the CoreCLR bridge we use the same struct representation for both types.
|
||||
|
|
|
@ -716,7 +716,9 @@ xamarin_check_for_gced_object (MonoObject *obj, SEL sel, id self, MonoMethod *me
|
|||
|
||||
if (obj != NULL) {
|
||||
#if DEBUG
|
||||
verify_cast (mono_method_get_class (method), obj, [self class], sel, method, exception_gchandle);
|
||||
MonoClass *declaring_type = mono_method_get_class (method);
|
||||
verify_cast (declaring_type, obj, [self class], sel, method, exception_gchandle);
|
||||
xamarin_mono_object_release (&declaring_type);
|
||||
#endif
|
||||
return;
|
||||
}
|
||||
|
|
|
@ -543,7 +543,10 @@ xamarin_invoke_trampoline (enum TrampolineType type, id self, SEL sel, iterator_
|
|||
* This problem is documented in the following bug:
|
||||
* https://bugzilla.xamarin.com/show_bug.cgi?id=6556
|
||||
*/
|
||||
retval = xamarin_new_nsobject (self, mono_method_get_class (method), &exception_gchandle);
|
||||
MonoClass *declaring_type = mono_method_get_class (method);
|
||||
ADD_TO_MONOOBJECT_RELEASE_LIST (declaring_type);
|
||||
|
||||
retval = xamarin_new_nsobject (self, declaring_type, &exception_gchandle);
|
||||
if (exception_gchandle != INVALID_GCHANDLE)
|
||||
goto exception_handling;
|
||||
ADD_TO_MONOOBJECT_RELEASE_LIST (retval);
|
||||
|
|
|
@ -15,6 +15,8 @@ using System.Runtime.InteropServices;
|
|||
|
||||
using Foundation;
|
||||
|
||||
using MonoObjectPtr=System.IntPtr;
|
||||
|
||||
namespace ObjCRuntime {
|
||||
|
||||
public partial class Runtime {
|
||||
|
@ -107,6 +109,17 @@ namespace ObjCRuntime {
|
|||
return rv;
|
||||
}
|
||||
|
||||
static object GetMonoObjectTarget (MonoObjectPtr mobj)
|
||||
{
|
||||
if (mobj == IntPtr.Zero)
|
||||
return null;
|
||||
|
||||
unsafe {
|
||||
MonoObject *monoobj = (MonoObject *) mobj;
|
||||
return GetGCHandleTarget (monoobj->GCHandle);
|
||||
}
|
||||
}
|
||||
|
||||
static IntPtr MarshalStructure<T> (T value) where T: struct
|
||||
{
|
||||
var rv = Marshal.AllocHGlobal (Marshal.SizeOf (typeof (T)));
|
||||
|
@ -139,6 +152,13 @@ namespace ObjCRuntime {
|
|||
var obj = (NSObject) GetGCHandleTarget (gchandle);
|
||||
return (byte) obj.FlagsInternal;
|
||||
}
|
||||
|
||||
static IntPtr GetMethodDeclaringType (MonoObjectPtr mobj)
|
||||
{
|
||||
var method = (MethodBase) GetMonoObjectTarget (mobj);
|
||||
return GetMonoObject (method.DeclaringType);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3756,7 +3756,10 @@ namespace Registrar {
|
|||
|
||||
// the actual invoke
|
||||
if (isCtor) {
|
||||
invoke.AppendLine ("mthis = xamarin_new_nsobject (self, mono_method_get_class (managed_method), &exception_gchandle);");
|
||||
body_setup.AppendLine ("MonoClass *declaring_type = NULL;");
|
||||
invoke.AppendLine ("declaring_type = mono_method_get_class (managed_method);");
|
||||
invoke.AppendLine ("mthis = xamarin_new_nsobject (self, declaring_type, &exception_gchandle);");
|
||||
invoke.AppendLine ("xamarin_mono_object_release (&declaring_type);");
|
||||
cleanup.AppendLine ("xamarin_mono_object_release (&mthis);");
|
||||
invoke.AppendLine ("if (exception_gchandle != INVALID_GCHANDLE) goto exception_handling;");
|
||||
}
|
||||
|
|
Загрузка…
Ссылка в новой задаче