Skip to content

[runtime] Rework how we call 'ConformsToProtocol' a little bit. #23002

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

Merged
merged 2 commits into from
Jun 17, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
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
1 change: 1 addition & 0 deletions runtime/delegates.t4
Original file line number Diff line number Diff line change
Expand Up @@ -664,6 +664,7 @@
},

new XDelegate ("NSInteger", "nint", "xamarin_invoke_conforms_to_protocol",
"GCHandle", "IntPtr", "gchandle",
"id", "IntPtr", "obj",
"Protocol *", "IntPtr", "protocol"
) {
Expand Down
4 changes: 2 additions & 2 deletions src/ObjCRuntime/Runtime.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2644,9 +2644,9 @@ public static string? OriginalWorkingDirectory {
[DllImport ("__Internal")]
static extern IntPtr xamarin_get_original_working_directory_path ();

static nint InvokeConformsToProtocol (IntPtr handle, IntPtr protocol)
static nint InvokeConformsToProtocol (IntPtr gchandle, IntPtr handle, IntPtr protocol)
{
var obj = Runtime.GetNSObject (handle);
var obj = GetGCHandleTarget (gchandle) as NSObject;
if (obj is null)
return 0;
var rv = obj.ConformsToProtocol (protocol);
Expand Down
3 changes: 2 additions & 1 deletion tools/common/StaticRegistrar.cs
Original file line number Diff line number Diff line change
Expand Up @@ -3490,7 +3490,8 @@ bool SpecializeTrampoline (AutoIndentStringBuilder sb, ObjCMethod method, List<E
sb.AppendLine ("-(BOOL) conformsToProtocol: (void *) protocol");
sb.AppendLine ("{");
sb.AppendLine ("GCHandle exception_gchandle;");
sb.AppendLine ("BOOL rv = xamarin_invoke_conforms_to_protocol (self, (Protocol *) protocol, &exception_gchandle) != 0;");
sb.AppendLine ("GCHandle obj_gchandle = xamarin_get_gchandle (self);");
sb.AppendLine ("BOOL rv = xamarin_invoke_conforms_to_protocol (obj_gchandle, self, (Protocol *) protocol, &exception_gchandle) != 0;");
sb.AppendLine ("xamarin_process_managed_exception_gchandle (exception_gchandle);");
sb.AppendLine ("return rv;");
sb.AppendLine ("}");
Expand Down