1
0
Fork 0
mirror of https://github.com/VSadov/Satori.git synced 2025-06-11 02:13:38 +09:00

Change C# names of P/Invokes of objc_msgSend to be call-site specific. (#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.
This commit is contained in:
Jeremy Koritzinsky 2021-02-02 11:58:47 -08:00 committed by GitHub
parent e6a5339b92
commit 1562cf743d
Signed by: github
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 21 additions and 23 deletions

View file

@ -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
{
@ -28,8 +22,8 @@ internal static partial class Interop
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()
{
@ -37,12 +31,15 @@ internal static partial class Interop
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;
@ -63,7 +60,10 @@ internal static partial class Interop
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);
}
}

View file

@ -69,13 +69,12 @@ namespace System.Drawing
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)
@ -211,13 +210,12 @@ namespace System.Drawing
#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);