Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[runtime] Use a custom native -> managed trampoline for calling NSObject.InvokeConformsToProtocol from the generated static registrar code. #15830

Merged
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions runtime/delegates.t4
Original file line number Diff line number Diff line change
Expand Up @@ -678,6 +678,13 @@
WrappedManagedFunction = "AttemptRetainNSObject",
OnlyDynamicUsage = false,
},

new XDelegate ("bool", "bool", "xamarin_invoke_conforms_to_protocol",
"id", "IntPtr", "obj",
"Protocol *", "IntPtr", "protocol"
) {
WrappedManagedFunction = "InvokeConformsToProtocol",
},
};
delegates.CalculateLengths ();
#><#+
Expand Down
8 changes: 8 additions & 0 deletions src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2143,6 +2143,14 @@ public static string? OriginalWorkingDirectory {
static extern IntPtr xamarin_get_original_working_directory_path ();
#endif // NET || !__MACOS__

static bool InvokeConformsToProtocol (IntPtr handle, IntPtr protocol)
{
var obj = Runtime.GetNSObject (handle);
if (obj is null)
return false;
return obj.ConformsToProtocol (protocol);
}

}

internal class IntPtrEqualityComparer : IEqualityComparer<IntPtr>
Expand Down
16 changes: 16 additions & 0 deletions tools/common/StaticRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3340,6 +3340,22 @@ void Specialize (AutoIndentStringBuilder sb, ObjCMethod method, List<Exception>
return;
}

var customConformsToProtocol = method.Selector == "conformsToProtocol:" && method.Method.DeclaringType.Is ("Foundation", "NSObject") && method.Method.Name == "InvokeConformsToProtocol" && method.Parameters.Length == 1;
if (customConformsToProtocol) {
if (Driver.IsDotNet) {
customConformsToProtocol &= method.Parameters [0].Is ("ObjCRuntime", "NativeHandle");
} else {
customConformsToProtocol &= method.Parameters [0].Is ("System", "IntPtr");
}
if (customConformsToProtocol) {
sb.AppendLine ("-(BOOL) conformsToProtocol: (void *) protocol");
sb.AppendLine ("{");
sb.AppendLine ("return xamarin_invoke_conforms_to_protocol (self, (Protocol *) protocol);");
sb.AppendLine ("}");
return;
}
}

var rettype = string.Empty;
var returntype = method.ReturnType;
var isStatic = method.IsStatic;
Expand Down