Skip to content

Commit

Permalink
Change C# names of P/Invokes of objc_msgSend to be call-site specific. (
Browse files Browse the repository at this point in the history
#47608)

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

* Rename to match suggested pattern

* Follow Xamarin convention in all objc_msgSend cases.

* Fix typo

* Rename to match convention.
  • Loading branch information
jkoritzinsky authored Feb 2, 2021
1 parent e6a5339 commit 1562cf7
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 23 deletions.
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

0 comments on commit 1562cf7

Please sign in to comment.