From 4bf3f6004df086472cdecb0fe132dbf381709023 Mon Sep 17 00:00:00 2001 From: Rolf Bjarne Kvinge Date: Wed, 21 Feb 2024 09:03:23 +0100 Subject: [PATCH] [CoreFoundation] Make P/Invokes in CFSocket have blittable signatures. Contributes towards #15684. --- src/CoreFoundation/CFSocket.cs | 18 +++++++++--------- .../BlittablePInvokes.KnownFailures.cs | 1 - 2 files changed, 9 insertions(+), 10 deletions(-) diff --git a/src/CoreFoundation/CFSocket.cs b/src/CoreFoundation/CFSocket.cs index 32144b6eed8e..0423d0304851 100644 --- a/src/CoreFoundation/CFSocket.cs +++ b/src/CoreFoundation/CFSocket.cs @@ -456,17 +456,17 @@ public CFSocket (AddressFamily family, SocketType type, ProtocolType proto, CFRu internal CFSocket (CFSocketSignature sig, double timeout) { unsafe { -#if NET Initialize ( CFRunLoop.Current, - (CFSocketContext* ctx) => CFSocketCreateConnectedToSocketSignature (IntPtr.Zero, ref sig, (nuint) (ulong) defaultCallbackTypes, &OnCallback, ctx, timeout) - ); + (CFSocketContext* ctx) => { + CFSocketSignature localSig = sig; +#if NET + return CFSocketCreateConnectedToSocketSignature (IntPtr.Zero, &localSig, (nuint) (ulong) defaultCallbackTypes, &OnCallback, ctx, timeout); #else - Initialize ( - CFRunLoop.Current, - (CFSocketContext* ctx) => CFSocketCreateConnectedToSocketSignature (IntPtr.Zero, ref sig, (nuint) (ulong) defaultCallbackTypes, OnCallback, ctx, timeout) - ); + return CFSocketCreateConnectedToSocketSignature (IntPtr.Zero, &localSig, (nuint) (ulong) defaultCallbackTypes, OnCallback, ctx, timeout); #endif + } + ); } } @@ -496,13 +496,13 @@ void Initialize (CFRunLoop runLoop, CreateSocket createSocket) #if NET [DllImport (Constants.CoreFoundationLibrary)] - unsafe extern static IntPtr CFSocketCreateConnectedToSocketSignature (IntPtr allocator, ref CFSocketSignature signature, + unsafe extern static IntPtr CFSocketCreateConnectedToSocketSignature (IntPtr allocator, CFSocketSignature* signature, nuint /*CFOptionFlags*/ callBackTypes, delegate* unmanaged callout, CFSocketContext* context, double timeout); #else [DllImport (Constants.CoreFoundationLibrary)] - unsafe extern static IntPtr CFSocketCreateConnectedToSocketSignature (IntPtr allocator, ref CFSocketSignature signature, + unsafe extern static IntPtr CFSocketCreateConnectedToSocketSignature (IntPtr allocator, CFSocketSignature* signature, nuint /*CFOptionFlags*/ callBackTypes, CFSocketCallBack callout, CFSocketContext* context, double timeout); diff --git a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs index d20a3ef4870b..3bcda7415165 100644 --- a/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs +++ b/tests/cecil-tests/BlittablePInvokes.KnownFailures.cs @@ -427,7 +427,6 @@ public partial class BlittablePInvokes { "System.IntPtr CoreFoundation.CFPropertyList::CFPropertyListCreateData(System.IntPtr,System.IntPtr,System.IntPtr,System.UIntPtr,System.IntPtr&)", "System.IntPtr CoreFoundation.CFPropertyList::CFPropertyListCreateWithData(System.IntPtr,System.IntPtr,System.UIntPtr,System.IntPtr&,System.IntPtr&)", "System.IntPtr CoreFoundation.CFRunLoopSourceCustom::CFRunLoopSourceCreate(System.IntPtr,System.IntPtr,CoreFoundation.CFRunLoopSourceContext&)", - "System.IntPtr CoreFoundation.CFSocket::CFSocketCreateConnectedToSocketSignature(System.IntPtr,CoreFoundation.CFSocketSignature&,System.UIntPtr,method System.Void *(System.IntPtr,System.UIntPtr,System.IntPtr,System.IntPtr,System.IntPtr),CoreFoundation.CFSocketContext*,System.Double)", "System.IntPtr CoreFoundation.CFUrl::CFURLCreateWithFileSystemPath(System.IntPtr,System.IntPtr,System.IntPtr,System.Boolean)", "System.IntPtr CoreFoundation.DispatchData::dispatch_data_create_map(System.IntPtr,System.IntPtr&,System.UIntPtr&)", "System.IntPtr CoreGraphics.CGEvent::CGEventCreateKeyboardEvent(System.IntPtr,System.UInt16,System.Boolean)",