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

Change C# names of P/Invokes of objc_msgSend to be call-site specific. #47608

Merged
6 commits merged into from
Feb 2, 2021
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
26 changes: 13 additions & 13 deletions src/libraries/Common/src/Interop/OSX/Interop.libobjc.cs
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,6 @@ internal static partial class Interop
{
internal static partial class libobjc
{
#if TARGET_ARM64
private const string MessageSendStructReturnEntryPoint = "objc_msgSend";
#else
private const string MessageSendStructReturnEntryPoint = "objc_msgSend_stret";
#endif

[StructLayout(LayoutKind.Sequential)]
private struct NSOperatingSystemVersion
{
Expand All @@ -28,21 +22,24 @@ private struct NSOperatingSystemVersion
private static extern IntPtr objc_getClass(string className);
[DllImport(Libraries.libobjc)]
private static extern IntPtr sel_getUid(string selector);
[DllImport(Libraries.libobjc)]
private static extern IntPtr objc_msgSend(IntPtr basePtr, IntPtr selector);
[DllImport(Libraries.libobjc, EntryPoint = "objc_msgSend")]
private static extern IntPtr intptr_objc_msgSend(IntPtr basePtr, IntPtr selector);

internal static Version GetOperatingSystemVersion()
{
int major = 0;
int minor = 0;
int patch = 0;

IntPtr processInfo = objc_msgSend(objc_getClass("NSProcessInfo"), sel_getUid("processInfo"));
IntPtr processInfo = intptr_objc_msgSend(objc_getClass("NSProcessInfo"), sel_getUid("processInfo"));

if (processInfo != IntPtr.Zero)
{
NSOperatingSystemVersion osVersion = get_operatingSystemVersion(processInfo, sel_getUid("operatingSystemVersion"));

#if TARGET_ARM64
NSOperatingSystemVersion osVersion = NSOperatingSystemVersion_objc_msgSend(processInfo, sel_getUid("operatingSystemVersion"));
#else
NSOperatingSystemVersion_objc_msgSend_stret(out NSOperatingSystemVersion osVersion, processInfo, sel_getUid("operatingSystemVersion"));
#endif
checked
{
major = (int)osVersion.majorVersion;
Expand All @@ -63,7 +60,10 @@ internal static Version GetOperatingSystemVersion()
return new Version(major, minor, patch);
}

[DllImport(Libraries.libobjc, EntryPoint = MessageSendStructReturnEntryPoint)]
private static extern NSOperatingSystemVersion get_operatingSystemVersion(IntPtr basePtr, IntPtr selector);
[DllImport(Libraries.libobjc, EntryPoint = "objc_msgSend")]
private static extern NSOperatingSystemVersion NSOperatingSystemVersion_objc_msgSend(IntPtr basePtr, IntPtr selector);

[DllImport(Libraries.libobjc, EntryPoint = "objc_msgSend_stret")]
private static extern void NSOperatingSystemVersion_objc_msgSend_stret(out NSOperatingSystemVersion osVersion, IntPtr basePtr, IntPtr selector);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -69,13 +69,12 @@ internal static class MacSupport

internal static CocoaContext GetCGContextForNSView(IntPtr handle)
{
IntPtr graphicsContext = objc_msgSend(objc_getClass("NSGraphicsContext"), sel_registerName("currentContext"));
IntPtr ctx = objc_msgSend(graphicsContext, sel_registerName("graphicsPort"));
Rect bounds = default;
IntPtr graphicsContext = intptr_objc_msgSend(objc_getClass("NSGraphicsContext"), sel_registerName("currentContext"));
IntPtr ctx = intptr_objc_msgSend(graphicsContext, sel_registerName("graphicsPort"));

CGContextSaveGState(ctx);

objc_msgSend_stret(ref bounds, handle, sel_registerName("bounds"));
Rect_objc_msgSend_stret(out Rect bounds, handle, sel_registerName("bounds"));

var isFlipped = bool_objc_msgSend(handle, sel_registerName("isFlipped"));
if (isFlipped)
Expand Down Expand Up @@ -211,13 +210,12 @@ internal static void ReleaseContext(IntPtr port, IntPtr context)
#region Cocoa Methods
[DllImport("libobjc.dylib")]
public static extern IntPtr objc_getClass(string className);
[DllImport("libobjc.dylib")]
public static extern IntPtr objc_msgSend(IntPtr basePtr, IntPtr selector, string argument);
[DllImport("libobjc.dylib")]
public static extern IntPtr objc_msgSend(IntPtr basePtr, IntPtr selector);
[DllImport("libobjc.dylib")]
public static extern void objc_msgSend_stret(ref Rect arect, IntPtr basePtr, IntPtr selector);
[DllImport("libobjc.dylib", EntryPoint = "objc_msgSend")]
public static extern IntPtr intptr_objc_msgSend(IntPtr basePtr, IntPtr selector);
[DllImport("libobjc.dylib", EntryPoint = "objc_msgSend_stret")]
public static extern void Rect_objc_msgSend_stret(out Rect arect, IntPtr basePtr, IntPtr selector);
[DllImport("libobjc.dylib", EntryPoint = "objc_msgSend")]
[return:MarshalAs(UnmanagedType.U1)]
public static extern bool bool_objc_msgSend(IntPtr handle, IntPtr selector);
[DllImport("libobjc.dylib")]
public static extern IntPtr sel_registerName(string selectorName);
Expand Down