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] Allow IntPtr for native objects in the dynamic registrar. Fixes #15708 #15712

Merged
merged 5 commits into from
Aug 23, 2022
Merged
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
8 changes: 7 additions & 1 deletion runtime/trampolines.m
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,13 @@
}
}
} else {
xamarin_assertion_message ("Don't know how to marshal a return value of type '%s.%s'. Please file a bug with a test case at https://github.com/xamarin/xamarin-macios/issues/new\n", mono_class_get_namespace (r_klass), mono_class_get_name (r_klass));
char *fullname = xamarin_class_get_full_name (r_klass, exception_gchandle);
Copy link
Contributor

Choose a reason for hiding this comment

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

last little bit - since fullname is only used in the error and @rolfbjarne implies that it's more costly than the xamarin_is_class_ tests, how about moving the allocation and deallocation into the else clause so that the price only gets paid in the failing case.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reverted the assertion to the original code as it did not need (extra) allocation, inside the caller, and still produced the same output.

if (!strcmp (fullname, "System.IntPtr")) {
Copy link
Member

Choose a reason for hiding this comment

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

There are two functions that are much faster and simpler: xamarin_is_class_intptr and xamarin_is_class_nativehandle, no need to compute a full type name nor compare strings.

returnValue = *(void **) mono_object_unbox (retval);
} else {
xamarin_assertion_message ("Don't know how to marshal a return value of type '%s.%s'. Please file a bug with a test case at https://github.com/xamarin/xamarin-macios/issues/new\n", mono_class_get_namespace (r_klass), mono_class_get_name (r_klass));
Copy link
Contributor

Choose a reason for hiding this comment

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

Since you have the fullname, why not change the assertion message to:
xamarin_assertion_message ("Don't know how to marshal a return value of type '%s', Please Please file a bug with a test case at https://github.com/xamarin/xamarin-macios/issues/new\n", full name);

On a side note, I wonder if this won't be immediately stale with the .NET 6 transition to NativeHandle instead of IntPtr.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Both good points @stephen-hawley I'll address them shortly. Thanks!

}
xamarin_free (fullname);
}

xamarin_mono_object_release (&r_klass);
Expand Down