diff --git a/src/AddressBook/ABAddressBook.cs b/src/AddressBook/ABAddressBook.cs index 2732685f2b..390bfe5182 100644 --- a/src/AddressBook/ABAddressBook.cs +++ b/src/AddressBook/ABAddressBook.cs @@ -200,15 +200,15 @@ namespace AddressBook { } } - internal delegate void InnerCompleted (IntPtr block, bool success, IntPtr error); + internal delegate void InnerCompleted (IntPtr block, byte success, IntPtr error); static readonly InnerCompleted static_completionHandler = TrampolineCompletionHandler; [MonoPInvokeCallback (typeof (InnerCompleted))] - static unsafe void TrampolineCompletionHandler (IntPtr block, bool success, IntPtr error) + static unsafe void TrampolineCompletionHandler (IntPtr block, byte success, IntPtr error) { var descriptor = (BlockLiteral*) block; var del = descriptor->Target as Action; if (del is not null) - del (success, Runtime.GetNSObject (error)); + del (success != 0, Runtime.GetNSObject (error)); } [DllImport (Constants.AddressBookLibrary)] diff --git a/src/CoreGraphics/CGPDFArray.cs b/src/CoreGraphics/CGPDFArray.cs index 016663a674..f222f192da 100644 --- a/src/CoreGraphics/CGPDFArray.cs +++ b/src/CoreGraphics/CGPDFArray.cs @@ -218,19 +218,21 @@ namespace CoreGraphics { } #endif - delegate bool ApplyBlockHandlerDelegate (IntPtr block, nint index, IntPtr value, IntPtr info); + delegate byte ApplyBlockHandlerDelegate (IntPtr block, nint index, IntPtr value, IntPtr info); static readonly ApplyBlockHandlerDelegate applyblock_handler = ApplyBlockHandler; #if !MONOMAC [MonoPInvokeCallback (typeof (ApplyBlockHandlerDelegate))] #endif - static bool ApplyBlockHandler (IntPtr block, nint index, IntPtr value, IntPtr info) + static byte ApplyBlockHandler (IntPtr block, nint index, IntPtr value, IntPtr info) { var del = BlockLiteral.GetTarget (block); - if (del is not null) - return del (index, CGPDFObject.FromHandle (value), info == IntPtr.Zero ? null : GCHandle.FromIntPtr (info).Target); + if (del is not null) { + var context = info == IntPtr.Zero ? null : GCHandle.FromIntPtr (info).Target; + return del (index, CGPDFObject.FromHandle (value), context) ? (byte) 1 : (byte) 0; + } - return false; + return 0; } public delegate bool ApplyCallback (nint index, object? value, object? info); diff --git a/src/CoreText/CTFontManager.cs b/src/CoreText/CTFontManager.cs index b2338cdb66..71982633ba 100644 --- a/src/CoreText/CTFontManager.cs +++ b/src/CoreText/CTFontManager.cs @@ -232,14 +232,18 @@ namespace CoreText { #endif public delegate bool CTFontRegistrationHandler (NSError [] errors, bool done); - internal delegate bool InnerRegistrationHandler (IntPtr block, IntPtr errors, bool done); + internal delegate byte InnerRegistrationHandler (IntPtr block, IntPtr errors, byte done); static readonly InnerRegistrationHandler callback = TrampolineRegistrationHandler; [MonoPInvokeCallback (typeof (InnerRegistrationHandler))] - static unsafe bool TrampolineRegistrationHandler (IntPtr block, /* NSArray */ IntPtr errors, bool done) + static unsafe byte TrampolineRegistrationHandler (IntPtr block, /* NSArray */ IntPtr errors, byte done) { var del = BlockLiteral.GetTarget (block); - return del is not null ? del (NSArray.ArrayFromHandle (errors), done) : true; + if (del is null) + return 0; + + var rv = del (NSArray.ArrayFromHandle (errors), done == 0 ? false : true); + return rv ? (byte) 1 : (byte) 0; } #if NET diff --git a/src/CoreText/CTLine.cs b/src/CoreText/CTLine.cs index d8aa26903b..5f3d7abe23 100644 --- a/src/CoreText/CTLine.cs +++ b/src/CoreText/CTLine.cs @@ -208,7 +208,7 @@ namespace CoreText { } public delegate void CaretEdgeEnumerator (double offset, nint charIndex, bool leadingEdge, ref bool stop); - unsafe delegate void CaretEdgeEnumeratorProxy (IntPtr block, double offset, nint charIndex, [MarshalAs (UnmanagedType.I1)] bool leadingEdge, [MarshalAs (UnmanagedType.I1)] ref bool stop); + unsafe delegate void CaretEdgeEnumeratorProxy (IntPtr block, double offset, nint charIndex, byte leadingEdge, byte* stop); #if NET [SupportedOSPlatform ("ios9.0")] @@ -225,11 +225,14 @@ namespace CoreText { static unsafe readonly CaretEdgeEnumeratorProxy static_enumerate = TrampolineEnumerate; [MonoPInvokeCallback (typeof (CaretEdgeEnumeratorProxy))] - static void TrampolineEnumerate (IntPtr blockPtr, double offset, nint charIndex, bool leadingEdge, ref bool stop) + unsafe static void TrampolineEnumerate (IntPtr blockPtr, double offset, nint charIndex, byte leadingEdge, byte* stopPointer) { var del = BlockLiteral.GetTarget (blockPtr); - if (del is not null) - del (offset, charIndex, leadingEdge, ref stop); + if (del is not null) { + bool stop = *stopPointer != 0; + del (offset, charIndex, leadingEdge != 0, ref stop); + *stopPointer = stop ? (byte) 1 : (byte) 0; + } } #if NET diff --git a/src/ImageIO/CGImageAnimation.cs b/src/ImageIO/CGImageAnimation.cs index 9019ba417f..fc13986825 100644 --- a/src/ImageIO/CGImageAnimation.cs +++ b/src/ImageIO/CGImageAnimation.cs @@ -120,22 +120,23 @@ namespace ImageIO { // This class bridges native block invocations that call into C# // static internal class SDCGImageSourceAnimationBlock { - static internal readonly DCGImageSourceAnimationBlock Handler = Invoke; + unsafe static internal readonly DCGImageSourceAnimationBlock Handler = Invoke; [MonoPInvokeCallback (typeof (DCGImageSourceAnimationBlock))] - static void Invoke (IntPtr block, nint index, IntPtr image, [MarshalAs (UnmanagedType.I1)] out bool stop) + internal unsafe static void Invoke (IntPtr block, nint index, IntPtr image, byte* stop) { var del = BlockLiteral.GetTarget (block); - if (del is not null) - del (index, new CoreGraphics.CGImage (image, false), out stop); - else - stop = false; + if (del is not null) { + del (index, new CoreGraphics.CGImage (image, false), out var stopValue); + *stop = stopValue ? (byte) 1 : (byte) 0; + } else + *stop = 0; } } /* class SDCGImageSourceAnimationBlock */ [UnmanagedFunctionPointerAttribute (CallingConvention.Cdecl)] [UserDelegateType (typeof (CGImageSourceAnimationHandler))] - internal delegate void DCGImageSourceAnimationBlock (IntPtr block, nint index, IntPtr imageHandle, [MarshalAs (UnmanagedType.I1)] out bool stop); + unsafe internal delegate void DCGImageSourceAnimationBlock (IntPtr block, nint index, IntPtr imageHandle, byte* stop); } } diff --git a/src/Network/NWBrowser.cs b/src/Network/NWBrowser.cs index 657e44f55a..210d137ade 100644 --- a/src/Network/NWBrowser.cs +++ b/src/Network/NWBrowser.cs @@ -131,18 +131,18 @@ namespace Network { [DllImport (Constants.NetworkLibrary)] unsafe static extern void nw_browser_set_browse_results_changed_handler (OS_nw_browser browser, BlockLiteral* handler); - delegate void nw_browser_browse_results_changed_handler_t (IntPtr block, IntPtr oldResult, IntPtr newResult, bool completed); + delegate void nw_browser_browse_results_changed_handler_t (IntPtr block, IntPtr oldResult, IntPtr newResult, byte completed); static nw_browser_browse_results_changed_handler_t static_ChangesHandler = TrampolineChangesHandler; [MonoPInvokeCallback (typeof (nw_browser_browse_results_changed_handler_t))] - static void TrampolineChangesHandler (IntPtr block, IntPtr oldResult, IntPtr newResult, bool completed) + static void TrampolineChangesHandler (IntPtr block, IntPtr oldResult, IntPtr newResult, byte completed) { var del = BlockLiteral.GetTarget (block); if (del is not null) { // we do the cleanup of the objs in the internal handlers NWBrowseResult? nwOldResult = (oldResult == IntPtr.Zero) ? null : new NWBrowseResult (oldResult, owns: false); NWBrowseResult? nwNewResult = (newResult == IntPtr.Zero) ? null : new NWBrowseResult (newResult, owns: false); - del (nwOldResult, nwNewResult, completed); + del (nwOldResult, nwNewResult, completed != 0); } } diff --git a/src/Network/NWConnection.cs b/src/Network/NWConnection.cs index 84bc276727..14322ee8c2 100644 --- a/src/Network/NWConnection.cs +++ b/src/Network/NWConnection.cs @@ -131,15 +131,15 @@ namespace Network { } } - delegate void nw_connection_boolean_event_handler_t (IntPtr block, [MarshalAs (UnmanagedType.U1)] bool value); + delegate void nw_connection_boolean_event_handler_t (IntPtr block, byte value); static nw_connection_boolean_event_handler_t static_BooleanChangeHandler = TrampolineBooleanChangeHandler; [MonoPInvokeCallback (typeof (nw_connection_boolean_event_handler_t))] - static void TrampolineBooleanChangeHandler (IntPtr block, bool value) + static void TrampolineBooleanChangeHandler (IntPtr block, byte value) { var del = BlockLiteral.GetTarget> (block); if (del is not null) - del (value); + del (value != 0); } [DllImport (Constants.NetworkLibrary)] @@ -242,7 +242,7 @@ namespace Network { delegate void nw_connection_receive_completion_t (IntPtr block, IntPtr dispatchData, IntPtr contentContext, - [MarshalAs (UnmanagedType.U1)] bool isComplete, + byte isComplete, IntPtr error); static nw_connection_receive_completion_t static_ReceiveCompletion = TrampolineReceiveCompletion; @@ -250,7 +250,7 @@ namespace Network { static nw_connection_receive_completion_t static_ReceiveCompletionDispatchReadnOnlyData = TrampolineReceiveCompletionReadOnlyData; [MonoPInvokeCallback (typeof (nw_connection_receive_completion_t))] - static void TrampolineReceiveCompletion (IntPtr block, IntPtr dispatchDataPtr, IntPtr contentContext, bool isComplete, IntPtr error) + static void TrampolineReceiveCompletion (IntPtr block, IntPtr dispatchDataPtr, IntPtr contentContext, byte isComplete, IntPtr error) { var del = BlockLiteral.GetTarget (block); if (del is not null) { @@ -266,7 +266,7 @@ namespace Network { del (bufferAddress, bufferSize, contentContext == IntPtr.Zero ? null : new NWContentContext (contentContext, owns: false), - isComplete, + isComplete != 0, error == IntPtr.Zero ? null : new NWError (error, owns: false)); if (dispatchData is not null) { @@ -277,7 +277,7 @@ namespace Network { } [MonoPInvokeCallback (typeof (nw_connection_receive_completion_t))] - static void TrampolineReceiveCompletionData (IntPtr block, IntPtr dispatchDataPtr, IntPtr contentContext, bool isComplete, IntPtr error) + static void TrampolineReceiveCompletionData (IntPtr block, IntPtr dispatchDataPtr, IntPtr contentContext, byte isComplete, IntPtr error) { var del = BlockLiteral.GetTarget (block); if (del is not null) { @@ -289,7 +289,7 @@ namespace Network { del (dispatchData, contentContext == IntPtr.Zero ? null : new NWContentContext (contentContext, owns: false), - isComplete, + isComplete != 0, error == IntPtr.Zero ? null : new NWError (error, owns: false)); if (dispatchData is not null) @@ -298,7 +298,7 @@ namespace Network { } [MonoPInvokeCallback (typeof (nw_connection_receive_completion_t))] - static void TrampolineReceiveCompletionReadOnlyData (IntPtr block, IntPtr dispatchDataPtr, IntPtr contentContext, bool isComplete, IntPtr error) + static void TrampolineReceiveCompletionReadOnlyData (IntPtr block, IntPtr dispatchDataPtr, IntPtr contentContext, byte isComplete, IntPtr error) { var del = BlockLiteral.GetTarget (block); if (del is not null) { @@ -307,7 +307,7 @@ namespace Network { var spanData = new ReadOnlySpan (dispatchData?.ToArray () ?? Array.Empty ()); del (spanData, contentContext == IntPtr.Zero ? null : new NWContentContext (contentContext, owns: false), - isComplete, + isComplete != 0, error == IntPtr.Zero ? null : new NWError (error, owns: false)); if (dispatchData is not null) { diff --git a/src/Network/NWConnectionGroup.cs b/src/Network/NWConnectionGroup.cs index 8aef493278..84104a4deb 100644 --- a/src/Network/NWConnectionGroup.cs +++ b/src/Network/NWConnectionGroup.cs @@ -227,17 +227,17 @@ namespace Network { [DllImport (Constants.NetworkLibrary)] unsafe static extern void nw_connection_group_set_receive_handler (OS_nw_connection_group group, uint maximum_message_size, [MarshalAs (UnmanagedType.I1)] bool reject_oversized_messages, BlockLiteral* handler); - delegate void nw_connection_group_receive_handler_t (IntPtr block, IntPtr content, IntPtr context, bool isCompleted); + delegate void nw_connection_group_receive_handler_t (IntPtr block, IntPtr content, IntPtr context, byte isCompleted); static nw_connection_group_receive_handler_t static_ReceiveHandler = TrampolineReceiveHandler; [MonoPInvokeCallback (typeof (nw_connection_group_receive_handler_t))] - static void TrampolineReceiveHandler (IntPtr block, IntPtr content, IntPtr context, bool isCompleted) + static void TrampolineReceiveHandler (IntPtr block, IntPtr content, IntPtr context, byte isCompleted) { var del = BlockLiteral.GetTarget (block); if (del is not null) { using var nsContent = new DispatchData (content, owns: false); using var nsContext = new NWContentContext (context, owns: false); - del (nsContent, nsContext, isCompleted); + del (nsContent, nsContext, isCompleted != 0); } } diff --git a/src/Network/NWEthernetChannel.cs b/src/Network/NWEthernetChannel.cs index 4ee083505c..c2ab91aacc 100644 --- a/src/Network/NWEthernetChannel.cs +++ b/src/Network/NWEthernetChannel.cs @@ -150,18 +150,20 @@ namespace Network { [DllImport (Constants.NetworkLibrary)] unsafe static extern void nw_ethernet_channel_set_receive_handler (OS_nw_ethernet_channel ethernet_channel, /* [NullAllowed] */ BlockLiteral *handler); - delegate void nw_ethernet_channel_receive_handler_t (IntPtr block, OS_dispatch_data content, ushort vlan_tag, byte[] local_address, byte[] remote_address); + delegate void nw_ethernet_channel_receive_handler_t (IntPtr block, OS_dispatch_data content, ushort vlan_tag, IntPtr local_address, IntPtr remote_address); static nw_ethernet_channel_receive_handler_t static_ReceiveHandler = TrampolineReceiveHandler; [MonoPInvokeCallback (typeof (nw_ethernet_channel_receive_handler_t))] - static void TrampolineReceiveHandler (IntPtr block, OS_dispatch_data content, ushort vlanTag, byte[] localAddress, byte[] remoteAddress) + static void TrampolineReceiveHandler (IntPtr block, OS_dispatch_data content, ushort vlanTag, IntPtr localAddressArray, IntPtr remoteAddressArray) { + // localAddress and remoteAddress are defined as: + // typedef unsigned char nw_ethernet_address_t[6]; var del = BlockLiteral.GetTarget (block); if (del is not null) { var dispatchData = (content == IntPtr.Zero) ? null : new DispatchData (content, owns: false); - var local = (localAddress is null) ? null : Encoding.UTF8.GetString (localAddress); - var remote = (remoteAddress is null) ? null : Encoding.UTF8.GetString (remoteAddress); + var local = Marshal.PtrToStringAuto (localAddressArray, 6); + var remote = Marshal.PtrToStringAuto (remoteAddressArray, 6); del (dispatchData, vlanTag, local, remote); } diff --git a/src/Network/NWFramer.cs b/src/Network/NWFramer.cs index 015264fe2b..87a580b0a3 100644 --- a/src/Network/NWFramer.cs +++ b/src/Network/NWFramer.cs @@ -140,17 +140,17 @@ namespace Network { [DllImport (Constants.NetworkLibrary)] unsafe static extern void nw_framer_set_output_handler (OS_nw_framer framer, void* output_handler); - delegate void nw_framer_set_output_handler_t (IntPtr block, OS_nw_framer framer, OS_nw_protocol_metadata message, nuint message_length, bool is_complete); + delegate void nw_framer_set_output_handler_t (IntPtr block, OS_nw_framer framer, OS_nw_protocol_metadata message, nuint message_length, byte is_complete); static nw_framer_set_output_handler_t static_OutputHandler = TrampolineOutputHandler; [MonoPInvokeCallback (typeof (nw_framer_set_output_handler_t))] - static void TrampolineOutputHandler (IntPtr block, OS_nw_framer framer, OS_nw_protocol_metadata message, nuint message_length, bool is_complete) + static void TrampolineOutputHandler (IntPtr block, OS_nw_framer framer, OS_nw_protocol_metadata message, nuint message_length, byte is_complete) { var del = BlockLiteral.GetTarget> (block); if (del is not null) { var nwFramer = new NWFramer (framer, owns: true); var nwProtocolMetadata = new NWFramerMessage (message, owns: true); - del (nwFramer, nwProtocolMetadata, message_length, is_complete); + del (nwFramer, nwProtocolMetadata, message_length, is_complete != 0); } } @@ -331,18 +331,18 @@ namespace Network { [return: MarshalAs (UnmanagedType.I1)] static extern unsafe bool nw_framer_parse_output (OS_nw_framer framer, nuint minimum_incomplete_length, nuint maximum_length, byte* temp_buffer, BlockLiteral* parse); - delegate void nw_framer_parse_output_t (IntPtr block, IntPtr buffer, nuint buffer_length, bool is_complete); + delegate void nw_framer_parse_output_t (IntPtr block, IntPtr buffer, nuint buffer_length, byte is_complete); static nw_framer_parse_output_t static_ParseOutputHandler = TrampolineParseOutputHandler; [MonoPInvokeCallback (typeof (nw_framer_parse_output_t))] - static void TrampolineParseOutputHandler (IntPtr block, IntPtr buffer, nuint buffer_length, bool is_complete) + static void TrampolineParseOutputHandler (IntPtr block, IntPtr buffer, nuint buffer_length, byte is_complete) { var del = BlockLiteral.GetTarget, bool>> (block); if (del is not null) { var bBuffer = new byte [buffer_length]; Marshal.Copy (buffer, bBuffer, 0, (int) buffer_length); var mValue = new Memory (bBuffer); - del (mValue, is_complete); + del (mValue, is_complete != 0); } } @@ -363,18 +363,18 @@ namespace Network { [return: MarshalAs (UnmanagedType.I1)] static extern unsafe bool nw_framer_parse_input (OS_nw_framer framer, nuint minimum_incomplete_length, nuint maximum_length, byte* temp_buffer, BlockLiteral* parse); - delegate nuint nw_framer_parse_input_t (IntPtr block, IntPtr buffer, nuint buffer_length, bool is_complete); + delegate nuint nw_framer_parse_input_t (IntPtr block, IntPtr buffer, nuint buffer_length, byte is_complete); static nw_framer_parse_input_t static_ParseInputHandler = TrampolineParseInputHandler; [MonoPInvokeCallback (typeof (nw_framer_parse_input_t))] - static nuint TrampolineParseInputHandler (IntPtr block, IntPtr buffer, nuint buffer_length, bool is_complete) + static nuint TrampolineParseInputHandler (IntPtr block, IntPtr buffer, nuint buffer_length, byte is_complete) { var del = BlockLiteral.GetTarget (block); if (del is not null) { var bBuffer = new byte [buffer_length]; Marshal.Copy (buffer, bBuffer, 0, (int) buffer_length); var mValue = new Memory (bBuffer); - return del (mValue, is_complete); + return del (mValue, is_complete != 0); } return 0; } diff --git a/src/Network/NWFramerMessage.cs b/src/Network/NWFramerMessage.cs index 5b3e0cf9a4..f5f964fd0a 100644 --- a/src/Network/NWFramerMessage.cs +++ b/src/Network/NWFramerMessage.cs @@ -96,19 +96,19 @@ namespace Network { [DllImport (Constants.NetworkLibrary)] [return: MarshalAs (UnmanagedType.I1)] unsafe static extern bool nw_framer_message_access_value (OS_nw_protocol_metadata message, IntPtr key, BlockLiteral* access_value); - delegate bool nw_framer_message_access_value_t (IntPtr block, IntPtr data); + delegate byte nw_framer_message_access_value_t (IntPtr block, IntPtr data); static nw_framer_message_access_value_t static_AccessValueHandler = TrampolineAccessValueHandler; [MonoPInvokeCallback (typeof (nw_framer_message_access_value_t))] - static bool TrampolineAccessValueHandler (IntPtr block, IntPtr data) + static byte TrampolineAccessValueHandler (IntPtr block, IntPtr data) { // get and call, this is internal and we are trying to do all the magic in the call var del = BlockLiteral.GetTarget> (block); if (del is not null) { - return del (data); + return del (data) ? (byte) 1 : (byte) 0; } - return false; + return 0; } [BindingImpl (BindingImplOptions.Optimizable)] diff --git a/src/Network/NWMulticastGroup.cs b/src/Network/NWMulticastGroup.cs index 139d8c4bac..a8a54661fd 100644 --- a/src/Network/NWMulticastGroup.cs +++ b/src/Network/NWMulticastGroup.cs @@ -77,18 +77,18 @@ namespace Network { [DllImport (Constants.NetworkLibrary)] unsafe static extern void nw_group_descriptor_enumerate_endpoints (OS_nw_group_descriptor descriptor, BlockLiteral* enumerate_block); - delegate bool nw_group_descriptor_enumerate_endpoints_block_t (IntPtr block, OS_nw_endpoint endpoint); + delegate byte nw_group_descriptor_enumerate_endpoints_block_t (IntPtr block, OS_nw_endpoint endpoint); static nw_group_descriptor_enumerate_endpoints_block_t static_EnumerateEndpointsHandler = TrampolineEnumerateEndpointsHandler; [MonoPInvokeCallback (typeof (nw_group_descriptor_enumerate_endpoints_block_t))] - static bool TrampolineEnumerateEndpointsHandler (IntPtr block, OS_nw_endpoint endpoint) + static byte TrampolineEnumerateEndpointsHandler (IntPtr block, OS_nw_endpoint endpoint) { var del = BlockLiteral.GetTarget> (block); if (del is not null) { using var nsEndpoint = new NWEndpoint (endpoint, owns: false); - return del (nsEndpoint); + return del (nsEndpoint) ? (byte) 1 : (byte) 0; } - return false; + return 0; } [BindingImpl (BindingImplOptions.Optimizable)] diff --git a/src/Network/NWParameters.cs b/src/Network/NWParameters.cs index b0dcb81c4f..9350d9a537 100644 --- a/src/Network/NWParameters.cs +++ b/src/Network/NWParameters.cs @@ -382,21 +382,20 @@ namespace Network { nw_parameters_clear_prohibited_interface_types (GetCheckedHandle ()); } - delegate bool nw_parameters_iterate_interfaces_block_t (IntPtr block, IntPtr iface); + delegate byte nw_parameters_iterate_interfaces_block_t (IntPtr block, IntPtr iface); static nw_parameters_iterate_interfaces_block_t static_iterateProhibitedHandler = TrampolineIterateProhibitedHandler; [MonoPInvokeCallback (typeof (nw_parameters_iterate_interfaces_block_t))] - [return: MarshalAs (UnmanagedType.I1)] - static bool TrampolineIterateProhibitedHandler (IntPtr block, IntPtr iface) + static byte TrampolineIterateProhibitedHandler (IntPtr block, IntPtr iface) { var del = BlockLiteral.GetTarget> (block); if (del is not null) { var x = new NWInterface (iface, owns: false); var ret = del (x); x.Dispose (); - return ret; + return ret ? (byte) 1 : (byte) 0; } - return false; + return 0; } [DllImport (Constants.NetworkLibrary)] @@ -412,17 +411,16 @@ namespace Network { } } - delegate bool nw_parameters_iterate_interface_types_block_t (IntPtr block, NWInterfaceType type); + delegate byte nw_parameters_iterate_interface_types_block_t (IntPtr block, NWInterfaceType type); static nw_parameters_iterate_interface_types_block_t static_IterateProhibitedTypeHandler = TrampolineIterateProhibitedTypeHandler; [MonoPInvokeCallback (typeof (nw_parameters_iterate_interface_types_block_t))] - [return: MarshalAs (UnmanagedType.I1)] - static bool TrampolineIterateProhibitedTypeHandler (IntPtr block, NWInterfaceType type) + static byte TrampolineIterateProhibitedTypeHandler (IntPtr block, NWInterfaceType type) { var del = BlockLiteral.GetTarget> (block); if (del is not null) - return del (type); - return false; + return del (type) ? (byte) 1 : (byte) 0; + return 0; } [DllImport (Constants.NetworkLibrary)] diff --git a/src/Network/NWTxtRecord.cs b/src/Network/NWTxtRecord.cs index 720d0b890d..a7813248c1 100644 --- a/src/Network/NWTxtRecord.cs +++ b/src/Network/NWTxtRecord.cs @@ -144,18 +144,18 @@ namespace Network { [return: MarshalAs (UnmanagedType.I1)] unsafe static extern bool nw_txt_record_apply (OS_nw_txt_record txt_record, BlockLiteral* applier); - delegate bool nw_txt_record_apply_t (IntPtr block, string key, NWTxtRecordFindKey found, IntPtr value, nuint valueLen); + delegate byte nw_txt_record_apply_t (IntPtr block, IntPtr key, NWTxtRecordFindKey found, IntPtr value, nuint valueLen); unsafe static nw_txt_record_apply_t static_ApplyHandler = TrampolineApplyHandler; #if NET - public delegate bool NWTxtRecordApplyDelegate (string key, NWTxtRecordFindKey result, ReadOnlySpan value); + public delegate bool NWTxtRecordApplyDelegate (string? key, NWTxtRecordFindKey result, ReadOnlySpan value); #else - public delegate void NWTxtRecordApplyDelegate (string key, NWTxtRecordFindKey rersult, ReadOnlySpan value); - public delegate bool NWTxtRecordApplyDelegate2 (string key, NWTxtRecordFindKey result, ReadOnlySpan value); + public delegate void NWTxtRecordApplyDelegate (string? key, NWTxtRecordFindKey rersult, ReadOnlySpan value); + public delegate bool NWTxtRecordApplyDelegate2 (string? key, NWTxtRecordFindKey result, ReadOnlySpan value); #endif [MonoPInvokeCallback (typeof (nw_txt_record_apply_t))] - unsafe static bool TrampolineApplyHandler (IntPtr block, string key, NWTxtRecordFindKey found, IntPtr value, nuint valueLen) + unsafe static byte TrampolineApplyHandler (IntPtr block, IntPtr keyPointer, NWTxtRecordFindKey found, IntPtr value, nuint valueLen) { #if NET var del = BlockLiteral.GetTarget (block); @@ -163,20 +163,21 @@ namespace Network { var del = BlockLiteral.GetTarget (block); #endif if (del is null) - return false; + return (byte) 0; var mValue = new ReadOnlySpan ((void*) value, (int) valueLen); + var key = Marshal.PtrToStringAuto (keyPointer); #if NET - return del (key, found, mValue); + return del (key, found, mValue) ? (byte) 1 : (byte) 0; #else if (del is NWTxtRecordApplyDelegate apply) { apply (key, found, mValue); - return true; + return (byte) 1; } if (del is NWTxtRecordApplyDelegate2 apply2) - return apply2 (key, found, mValue); + return apply2 (key, found, mValue) ? (byte) 1 : (byte) 0; ; - return false; + return (byte) 0; #endif } @@ -215,13 +216,13 @@ namespace Network { [return: MarshalAs (UnmanagedType.I1)] static extern unsafe bool nw_txt_record_access_key (OS_nw_txt_record txt_record, IntPtr key, BlockLiteral* access_value); - unsafe delegate void nw_txt_record_access_key_t (IntPtr block, string key, NWTxtRecordFindKey found, IntPtr value, nuint valueLen); + unsafe delegate void nw_txt_record_access_key_t (IntPtr IntPtr, IntPtr key, NWTxtRecordFindKey found, IntPtr value, nuint valueLen); unsafe static nw_txt_record_access_key_t static_AccessKeyHandler = TrampolineAccessKeyHandler; - public delegate void NWTxtRecordGetValueDelegete (string key, NWTxtRecordFindKey result, ReadOnlySpan value); + public delegate void NWTxtRecordGetValueDelegete (string? key, NWTxtRecordFindKey result, ReadOnlySpan value); [MonoPInvokeCallback (typeof (nw_txt_record_access_key_t))] - unsafe static void TrampolineAccessKeyHandler (IntPtr block, string key, NWTxtRecordFindKey found, IntPtr value, nuint valueLen) + unsafe static void TrampolineAccessKeyHandler (IntPtr block, IntPtr keyPointer, NWTxtRecordFindKey found, IntPtr value, nuint valueLen) { var del = BlockLiteral.GetTarget (block); if (del is not null) { @@ -230,6 +231,7 @@ namespace Network { mValue = new ReadOnlySpan ((void*) value, (int) valueLen); else mValue = Array.Empty (); + var key = Marshal.PtrToStringAuto (keyPointer); del (key, found, mValue); } } diff --git a/src/Network/NWWebSocketRequest.cs b/src/Network/NWWebSocketRequest.cs index 82471b5fc4..ebc7fc1f1e 100644 --- a/src/Network/NWWebSocketRequest.cs +++ b/src/Network/NWWebSocketRequest.cs @@ -43,20 +43,22 @@ namespace Network { [return: MarshalAs (UnmanagedType.I1)] unsafe static extern bool nw_ws_request_enumerate_additional_headers (OS_nw_ws_request request, BlockLiteral* enumerator); - delegate void nw_ws_request_enumerate_additional_headers_t (IntPtr block, string header, string value); + delegate void nw_ws_request_enumerate_additional_headers_t (IntPtr block, IntPtr header, IntPtr value); static nw_ws_request_enumerate_additional_headers_t static_EnumerateHeaderHandler = TrampolineEnumerateHeaderHandler; [MonoPInvokeCallback (typeof (nw_ws_request_enumerate_additional_headers_t))] - static void TrampolineEnumerateHeaderHandler (IntPtr block, string header, string value) + static void TrampolineEnumerateHeaderHandler (IntPtr block, IntPtr headerPointer, IntPtr valuePointer) { - var del = BlockLiteral.GetTarget> (block); + var del = BlockLiteral.GetTarget> (block); if (del is not null) { + var header = Marshal.PtrToStringAuto (headerPointer); + var value = Marshal.PtrToStringAuto (valuePointer); del (header, value); } } [BindingImpl (BindingImplOptions.Optimizable)] - public void EnumerateAdditionalHeaders (Action handler) + public void EnumerateAdditionalHeaders (Action handler) { if (handler is null) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (handler)); @@ -72,20 +74,21 @@ namespace Network { [return: MarshalAs (UnmanagedType.I1)] unsafe static extern bool nw_ws_request_enumerate_subprotocols (OS_nw_ws_request request, BlockLiteral* enumerator); - delegate void nw_ws_request_enumerate_subprotocols_t (IntPtr block, string subprotocol); + delegate void nw_ws_request_enumerate_subprotocols_t (IntPtr block, IntPtr subprotocol); static nw_ws_request_enumerate_subprotocols_t static_EnumerateSubprotocolHandler = TrampolineEnumerateSubprotocolHandler; [MonoPInvokeCallback (typeof (nw_ws_request_enumerate_subprotocols_t))] - static void TrampolineEnumerateSubprotocolHandler (IntPtr block, string subprotocol) + static void TrampolineEnumerateSubprotocolHandler (IntPtr block, IntPtr subprotocolPointer) { - var del = BlockLiteral.GetTarget> (block); + var del = BlockLiteral.GetTarget> (block); if (del is not null) { + var subprotocol = Marshal.PtrToStringAuto (subprotocolPointer); del (subprotocol); } } [BindingImpl (BindingImplOptions.Optimizable)] - public void EnumerateSubprotocols (Action handler) + public void EnumerateSubprotocols (Action handler) { if (handler is null) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (handler)); diff --git a/src/Network/NWWebSocketResponse.cs b/src/Network/NWWebSocketResponse.cs index 0417505d8a..5e723c3751 100644 --- a/src/Network/NWWebSocketResponse.cs +++ b/src/Network/NWWebSocketResponse.cs @@ -72,20 +72,22 @@ namespace Network { [return: MarshalAs (UnmanagedType.I1)] unsafe static extern bool nw_ws_response_enumerate_additional_headers (OS_nw_ws_response response, BlockLiteral* enumerator); - delegate void nw_ws_response_enumerate_additional_headers_t (IntPtr block, string header, string value); + delegate void nw_ws_response_enumerate_additional_headers_t (IntPtr block, IntPtr header, IntPtr value); static nw_ws_response_enumerate_additional_headers_t static_EnumerateHeadersHandler = TrampolineEnumerateHeadersHandler; [MonoPInvokeCallback (typeof (nw_ws_response_enumerate_additional_headers_t))] - static void TrampolineEnumerateHeadersHandler (IntPtr block, string header, string value) + static void TrampolineEnumerateHeadersHandler (IntPtr block, IntPtr headerPointer, IntPtr valuePointer) { - var del = BlockLiteral.GetTarget> (block); + var del = BlockLiteral.GetTarget> (block); if (del is not null) { + var header = Marshal.PtrToStringAuto (headerPointer); + var value = Marshal.PtrToStringAuto (valuePointer); del (header, value); } } [BindingImpl (BindingImplOptions.Optimizable)] - public bool EnumerateAdditionalHeaders (Action handler) + public bool EnumerateAdditionalHeaders (Action handler) { if (handler is null) ObjCRuntime.ThrowHelper.ThrowArgumentNullException (nameof (handler)); diff --git a/src/Security/SecTrust.cs b/src/Security/SecTrust.cs index 9c57a2dd8a..9f8bf119c9 100644 --- a/src/Security/SecTrust.cs +++ b/src/Security/SecTrust.cs @@ -238,17 +238,17 @@ namespace Security { [DllImport (Constants.SecurityLibrary)] unsafe static extern SecStatusCode SecTrustEvaluateAsyncWithError (IntPtr /* SecTrustRef */ trust, IntPtr /* dispatch_queue_t */ queue, BlockLiteral* block); - internal delegate void TrustEvaluateErrorHandler (IntPtr block, IntPtr trust, bool result, IntPtr /* CFErrorRef _Nullable */ error); + internal delegate void TrustEvaluateErrorHandler (IntPtr block, IntPtr trust, byte result, IntPtr /* CFErrorRef _Nullable */ error); static readonly TrustEvaluateErrorHandler evaluate_error = TrampolineEvaluateError; [MonoPInvokeCallback (typeof (TrustEvaluateErrorHandler))] - static void TrampolineEvaluateError (IntPtr block, IntPtr trust, bool result, IntPtr /* CFErrorRef _Nullable */ error) + static void TrampolineEvaluateError (IntPtr block, IntPtr trust, byte result, IntPtr /* CFErrorRef _Nullable */ error) { var del = BlockLiteral.GetTarget (block); if (del is not null) { var t = trust == IntPtr.Zero ? null : new SecTrust (trust, false); var e = error == IntPtr.Zero ? null : new NSError (error); - del (t, result, e); + del (t, result != 0, e); } } diff --git a/src/UIKit/UIAccessibility.cs b/src/UIKit/UIAccessibility.cs index 3322c491e2..ccf7e67521 100644 --- a/src/UIKit/UIAccessibility.cs +++ b/src/UIKit/UIAccessibility.cs @@ -268,16 +268,16 @@ namespace UIKit { return tcs.Task; } - internal delegate void InnerRequestGuidedAccessSession (IntPtr block, bool enable); + internal delegate void InnerRequestGuidedAccessSession (IntPtr block, byte enable); static readonly InnerRequestGuidedAccessSession callback = TrampolineRequestGuidedAccessSession; [MonoPInvokeCallback (typeof (InnerRequestGuidedAccessSession))] - static unsafe void TrampolineRequestGuidedAccessSession (IntPtr block, bool enable) + static unsafe void TrampolineRequestGuidedAccessSession (IntPtr block, byte enable) { var descriptor = (BlockLiteral*) block; var del = (Action) (descriptor->Target); if (del != null) - del (enable); + del (enable != 0); } #if NET diff --git a/src/UIKit/UIGuidedAccessRestriction.cs b/src/UIKit/UIGuidedAccessRestriction.cs index 3c179abed4..fbfd2cfbf9 100644 --- a/src/UIKit/UIGuidedAccessRestriction.cs +++ b/src/UIKit/UIGuidedAccessRestriction.cs @@ -62,18 +62,18 @@ namespace UIKit { public delegate void UIGuidedAccessConfigureAccessibilityFeaturesCompletionHandler (bool success, NSError error); [UnmanagedFunctionPointer (CallingConvention.Cdecl)] - internal delegate void DUIGuidedAccessConfigureAccessibilityFeaturesCompletionHandler (IntPtr block, bool success, IntPtr error); + internal delegate void DUIGuidedAccessConfigureAccessibilityFeaturesCompletionHandler (IntPtr block, byte success, IntPtr error); static internal class UIGuidedAccessConfigureAccessibilityFeaturesTrampoline { static internal readonly DUIGuidedAccessConfigureAccessibilityFeaturesCompletionHandler Handler = Invoke; [MonoPInvokeCallback (typeof (DUIGuidedAccessConfigureAccessibilityFeaturesCompletionHandler))] - static unsafe void Invoke (IntPtr block, bool success, IntPtr error) + static unsafe void Invoke (IntPtr block, byte success, IntPtr error) { var descriptor = (BlockLiteral*) block; var del = (UIGuidedAccessConfigureAccessibilityFeaturesCompletionHandler) (descriptor->Target); if (del != null) - del (success, Runtime.GetNSObject (error)); + del (success != 0, Runtime.GetNSObject (error)); } }