Skip to content

Commit

Permalink
[runtime] Implement mono_method_get_class for CoreCLR. (#11389)
Browse files Browse the repository at this point in the history
  • Loading branch information
rolfbjarne authored Apr 30, 2021
1 parent 6f743fd commit 8e9f86a
Show file tree
Hide file tree
Showing 8 changed files with 54 additions and 4 deletions.
8 changes: 8 additions & 0 deletions runtime/coreclr-bridge.m
Original file line number Diff line number Diff line change
Expand Up @@ -231,4 +231,12 @@
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
7 changes: 7 additions & 0 deletions runtime/delegates.t4
Original file line number Diff line number Diff line change
Expand Up @@ -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 ();
#><#+
Expand Down
4 changes: 3 additions & 1 deletion runtime/exports.t4
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,9 @@

new Export ("MonoClass *", "mono_method_get_class",
"MonoMethod *", "method"
),
) {
HasCoreCLRBridgeFunction = true,
},

new Export ("void", "mono_dllmap_insert",
"MonoImage *", "assembly",
Expand Down
5 changes: 5 additions & 0 deletions runtime/mono-runtime.h.t4
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
4 changes: 3 additions & 1 deletion runtime/runtime.m
Original file line number Diff line number Diff line change
Expand Up @@ -716,7 +716,9 @@ -(void) xamarinSetFlags: (enum XamarinGCHandleFlags) flags;

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;
}
Expand Down
5 changes: 4 additions & 1 deletion runtime/trampolines-invoke.m
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,10 @@
* 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);
Expand Down
20 changes: 20 additions & 0 deletions src/ObjCRuntime/Runtime.CoreCLR.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,8 @@

using Foundation;

using MonoObjectPtr=System.IntPtr;

namespace ObjCRuntime {

public partial class Runtime {
Expand Down Expand Up @@ -107,6 +109,17 @@ static IntPtr GetMonoObjectImpl (object obj)
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)));
Expand Down Expand Up @@ -139,6 +152,13 @@ static byte GetFlagsForNSObject (IntPtr gchandle)
var obj = (NSObject) GetGCHandleTarget (gchandle);
return (byte) obj.FlagsInternal;
}

static IntPtr GetMethodDeclaringType (MonoObjectPtr mobj)
{
var method = (MethodBase) GetMonoObjectTarget (mobj);
return GetMonoObject (method.DeclaringType);
}

}
}

Expand Down
5 changes: 4 additions & 1 deletion tools/common/StaticRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3756,7 +3756,10 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>

// 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;");
}
Expand Down

7 comments on commit 8e9f86a

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on Build ❌

Tests failed on Build.

API diff

✅ API Diff from stable

View API diff

API & Generator diff

API Diff (from PR only) (no change)
Generator Diff (no change)

Packages generated

View packages

Test results

3 tests failed, 190 tests passed.

Failed tests

  • link all/Mac Catalyst/Debug: Failed (Tests run: 95 Passed: 91 Inconclusive: 0 Failed: 1 Ignored: 3)
  • link sdk/Mac Catalyst/Debug: Failed (Tests run: 135 Passed: 122 Inconclusive: 6 Failed: 1 Ignored: 12)
  • introspection/watchOS 32-bits - simulator/Debug (watchOS 5.0): Failed

Pipeline on Agent XAMBOT-1028'
[runtime] Implement mono_method_get_class for CoreCLR. (#11389)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests tvOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[runtime] Implement mono_method_get_class for CoreCLR. (#11389)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[runtime] Implement mono_method_get_class for CoreCLR. (#11389)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on macOS Mac Catalina (10.15) ❌

Tests failed on Mac Catalina (10.15).

Failed tests are:

  • apitest
  • introspection

Pipeline on Agent
[runtime] Implement mono_method_get_class for CoreCLR. (#11389)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on macOS Mac Mojave (10.14) ❌

Tests failed on Mac Mojave (10.14).

Failed tests are:

  • apitest
  • introspection
  • xammac_tests

Pipeline on Agent
[runtime] Implement mono_method_get_class for CoreCLR. (#11389)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

❌ Tests failed on macOS Mac High Sierra (10.13) ❌

Tests failed on Mac High Sierra (10.13).

Failed tests are:

  • apitest
  • introspection
  • xammac_tests

Pipeline on Agent
[runtime] Implement mono_method_get_class for CoreCLR. (#11389)

@vs-mobiletools-engineering-service2
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Tests were not ran (VSTS: device tests iOS32b). ⚠️

Results were skipped for this run due to provisioning problems Azure Devops. Please contact the bot administrator.

Pipeline on Agent
[runtime] Implement mono_method_get_class for CoreCLR. (#11389)

Please sign in to comment.