This commit is contained in:
neuecc 2023-09-04 20:54:04 +09:00
parent 044c0afdf2
commit 4ed2767538
3 changed files with 36 additions and 39 deletions

View File

@ -87,8 +87,8 @@ fn main() -> Result<(), Box<dyn Error>> {
//.input_extern_files(&["src/lib.rs"]) //.input_extern_files(&["src/lib.rs"])
.csharp_class_name("NativeMethods") .csharp_class_name("NativeMethods")
.csharp_dll_name("csbindgen_tests") .csharp_dll_name("csbindgen_tests")
// .csharp_use_function_pointer(true) .csharp_use_function_pointer(true)
.csharp_use_function_pointer(false) //.csharp_use_function_pointer(false)
.csharp_generate_const(true) .csharp_generate_const(true)
.generate_csharp_file("../dotnet-sandbox/NativeMethods.cs") .generate_csharp_file("../dotnet-sandbox/NativeMethods.cs")
.unwrap(); .unwrap();

View File

@ -1,6 +1,6 @@
use std::{ use std::{
collections::HashSet, collections::HashSet,
ffi::{c_char, c_long, c_ulong, CString}, ffi::{c_char, c_long, c_ulong, CString}, ptr::NonNull,
}; };
#[allow(dead_code)] #[allow(dead_code)]
@ -171,11 +171,23 @@ pub extern "C" fn event(event: event) {
} }
#[no_mangle] #[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] #[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] #[no_mangle]

View File

@ -46,23 +46,23 @@ namespace CsBindgen
[DllImport(__DllName, EntryPoint = "@event", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport(__DllName, EntryPoint = "@event", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void @event(@event @event); 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)] [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); public static extern void test_func_issue_39(delegate* unmanaged[Cdecl]<int, void> _f);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate void test_func_issue_39_variation1_f_delegate(int arg1, int arg2, int arg3);
[DllImport(__DllName, EntryPoint = "test_func_issue_39_variation1", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [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]<int, int, int, void> _f);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)] [DllImport(__DllName, EntryPoint = "nonnull_parameter", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public delegate int nest_test__f_delegate(nest_test__f_delegate* pxFunc); 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]<int, int, int, void> _f);
[DllImport(__DllName, EntryPoint = "nest_test", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [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]<delegate* unmanaged[Cdecl]<int, void>*, int> _f);
[DllImport(__DllName, EntryPoint = "alias_test1", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport(__DllName, EntryPoint = "alias_test1", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void alias_test1(long* _a); 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)] [DllImport(__DllName, EntryPoint = "csharp_to_rust_bytes", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void csharp_to_rust_bytes(byte* bytes, int len); 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)] [DllImport(__DllName, EntryPoint = "callback_test", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int callback_test(callback_test_cb_delegate cb); public static extern int callback_test(delegate* unmanaged[Cdecl]<int, int> cb);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int csharp_to_rust_cb_delegate(int x, int y);
[DllImport(__DllName, EntryPoint = "csharp_to_rust", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport(__DllName, EntryPoint = "csharp_to_rust", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void csharp_to_rust(csharp_to_rust_cb_delegate cb); public static extern void csharp_to_rust(delegate* unmanaged[Cdecl]<int, int, int> cb);
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
public delegate int rust_to_csharp_return_delegate(int x, int y);
[DllImport(__DllName, EntryPoint = "rust_to_csharp", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [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]<int, int, int> rust_to_csharp();
[DllImport(__DllName, EntryPoint = "sum", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport(__DllName, EntryPoint = "sum", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int sum(int x, int y); public static extern int sum(int x, int y);
@ -106,20 +97,14 @@ namespace CsBindgen
[DllImport(__DllName, EntryPoint = "cbt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport(__DllName, EntryPoint = "cbt", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void cbt(CallbackTable _cb); 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)] [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]<int, int> cb);
[DllImport(__DllName, EntryPoint = "types_iroiro", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport(__DllName, EntryPoint = "types_iroiro", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern void types_iroiro(nint _i, nuint _u, CLong _cl, CULong _cul); 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)] [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]<int, int> callback_test2();
[DllImport(__DllName, EntryPoint = "callback", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)] [DllImport(__DllName, EntryPoint = "callback", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
public static extern int callback(int a); public static extern int callback(int a);
@ -214,7 +199,7 @@ namespace CsBindgen
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal unsafe partial struct NfcCard internal unsafe partial struct NfcCard
{ {
public void* @delegate; public delegate* unmanaged[Cdecl]<ByteArray, ByteArray> @delegate;
} }
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
@ -268,8 +253,8 @@ namespace CsBindgen
[StructLayout(LayoutKind.Sequential)] [StructLayout(LayoutKind.Sequential)]
internal unsafe partial struct CallbackTable internal unsafe partial struct CallbackTable
{ {
public void* foo; public delegate* unmanaged[Cdecl]<void> foo;
public void* foobar; public delegate* unmanaged[Cdecl]<int, int> foobar;
} }