diff --git a/csbindgen-tests/build.rs b/csbindgen-tests/build.rs index 1c27da7..ad1921c 100644 --- a/csbindgen-tests/build.rs +++ b/csbindgen-tests/build.rs @@ -87,8 +87,8 @@ fn main() -> Result<(), Box> { //.input_extern_files(&["src/lib.rs"]) .csharp_class_name("NativeMethods") .csharp_dll_name("csbindgen_tests") - // .csharp_use_function_pointer(true) - .csharp_use_function_pointer(false) + .csharp_use_function_pointer(true) + //.csharp_use_function_pointer(false) .csharp_generate_const(true) .generate_csharp_file("../dotnet-sandbox/NativeMethods.cs") .unwrap(); diff --git a/csbindgen-tests/src/lib.rs b/csbindgen-tests/src/lib.rs index 38e4ca5..1ac903a 100644 --- a/csbindgen-tests/src/lib.rs +++ b/csbindgen-tests/src/lib.rs @@ -1,6 +1,6 @@ use std::{ collections::HashSet, - ffi::{c_char, c_long, c_ulong, CString}, + ffi::{c_char, c_long, c_ulong, CString}, ptr::NonNull, }; #[allow(dead_code)] @@ -171,11 +171,23 @@ pub extern "C" fn event(event: event) { } #[no_mangle] -pub extern "C" fn test_func_issue_39(f: extern "C" fn(i32)){ +pub extern "C" fn test_func_issue_39(_f: extern "C" fn(i32)){ } #[no_mangle] -pub extern "C" fn test_func_issue_39_variation1(f: extern "C" fn(i32, i32, i32)){ +pub extern "C" fn test_func_issue_39_variation1(_f: extern "C" fn(i32, i32, i32)){ +} + +#[no_mangle] +pub extern "C" fn nonnull_parameter(_output_word_uuid: NonNull<[u8; 16]>){ +} + +#[no_mangle] +pub extern "C" fn non_nonnull_parameter(_output_word_uuid: [u8; 16]){ +} + +#[no_mangle] +pub extern "C" fn ge(_f: extern "C" fn(i32, i32, i32)){ } #[no_mangle] diff --git a/dotnet-sandbox/NativeMethods.cs b/dotnet-sandbox/NativeMethods.cs index b23e5e5..b64dd39 100644 --- a/dotnet-sandbox/NativeMethods.cs +++ b/dotnet-sandbox/NativeMethods.cs @@ -46,23 +46,23 @@ namespace CsBindgen [DllImport(__DllName, EntryPoint = "@event", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern void @event(@event @event); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void test_func_issue_39_f_delegate(int arg1); - [DllImport(__DllName, EntryPoint = "test_func_issue_39", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void test_func_issue_39(test_func_issue_39_f_delegate f); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate void test_func_issue_39_variation1_f_delegate(int arg1, int arg2, int arg3); + public static extern void test_func_issue_39(delegate* unmanaged[Cdecl] _f); [DllImport(__DllName, EntryPoint = "test_func_issue_39_variation1", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void test_func_issue_39_variation1(test_func_issue_39_variation1_f_delegate f); + public static extern void test_func_issue_39_variation1(delegate* unmanaged[Cdecl] _f); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate int nest_test__f_delegate(nest_test__f_delegate* pxFunc); + [DllImport(__DllName, EntryPoint = "nonnull_parameter", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void nonnull_parameter(NonNull _output_word_uuid); + + [DllImport(__DllName, EntryPoint = "non_nonnull_parameter", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void non_nonnull_parameter(void/* byte[] */ _output_word_uuid); + + [DllImport(__DllName, EntryPoint = "ge", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] + public static extern void ge(delegate* unmanaged[Cdecl] _f); [DllImport(__DllName, EntryPoint = "nest_test", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void nest_test(nest_test__f_delegate _f); + public static extern void nest_test(delegate* unmanaged[Cdecl]*, int> _f); [DllImport(__DllName, EntryPoint = "alias_test1", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern void alias_test1(long* _a); @@ -82,23 +82,14 @@ namespace CsBindgen [DllImport(__DllName, EntryPoint = "csharp_to_rust_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern void csharp_to_rust_bytes(byte* bytes, int len); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate int callback_test_cb_delegate(int a); - [DllImport(__DllName, EntryPoint = "callback_test", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern int callback_test(callback_test_cb_delegate cb); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate int csharp_to_rust_cb_delegate(int x, int y); + public static extern int callback_test(delegate* unmanaged[Cdecl] cb); [DllImport(__DllName, EntryPoint = "csharp_to_rust", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern void csharp_to_rust(csharp_to_rust_cb_delegate cb); - - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate int rust_to_csharp_return_delegate(int x, int y); + public static extern void csharp_to_rust(delegate* unmanaged[Cdecl] cb); [DllImport(__DllName, EntryPoint = "rust_to_csharp", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern rust_to_csharp_return_delegate rust_to_csharp(); + public static extern delegate* unmanaged[Cdecl] rust_to_csharp(); [DllImport(__DllName, EntryPoint = "sum", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern int sum(int x, int y); @@ -106,20 +97,14 @@ namespace CsBindgen [DllImport(__DllName, EntryPoint = "cbt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern void cbt(CallbackTable _cb); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate int nullable_callback_test_cb_delegate(int a); - [DllImport(__DllName, EntryPoint = "nullable_callback_test", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern int nullable_callback_test(nullable_callback_test_cb_delegate cb); + public static extern int nullable_callback_test(delegate* unmanaged[Cdecl] cb); [DllImport(__DllName, EntryPoint = "types_iroiro", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern void types_iroiro(nint _i, nuint _u, CLong _cl, CULong _cul); - [UnmanagedFunctionPointer(CallingConvention.Cdecl)] - public delegate int callback_test2_return_delegate(int a); - [DllImport(__DllName, EntryPoint = "callback_test2", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] - public static extern callback_test2_return_delegate callback_test2(); + public static extern delegate* unmanaged[Cdecl] callback_test2(); [DllImport(__DllName, EntryPoint = "callback", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] public static extern int callback(int a); @@ -214,7 +199,7 @@ namespace CsBindgen [StructLayout(LayoutKind.Sequential)] internal unsafe partial struct NfcCard { - public void* @delegate; + public delegate* unmanaged[Cdecl] @delegate; } [StructLayout(LayoutKind.Sequential)] @@ -268,8 +253,8 @@ namespace CsBindgen [StructLayout(LayoutKind.Sequential)] internal unsafe partial struct CallbackTable { - public void* foo; - public void* foobar; + public delegate* unmanaged[Cdecl] foo; + public delegate* unmanaged[Cdecl] foobar; }