mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-22 22:46:26 +00:00
Merge branch 'main' into support-reference
This commit is contained in:
commit
d4ba618c35
16
csbindgen-tests/src/lib.rs
vendored
16
csbindgen-tests/src/lib.rs
vendored
@ -606,8 +606,24 @@ pub struct CallbackTable {
|
|||||||
pub foobar: extern "C" fn(i: i32) -> i32,
|
pub foobar: extern "C" fn(i: i32) -> i32,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
pub extern "C" fn reference_type(_a: &i32, _b: &*mut i32, _c: &[u8; 16], _d: &Context) {}
|
pub extern "C" fn reference_type(_a: &i32, _b: &*mut i32, _c: &[u8; 16], _d: &Context) {}
|
||||||
|
|
||||||
|
pub struct InternalHiddenContext {
|
||||||
|
pub a: i32
|
||||||
|
}
|
||||||
|
|
||||||
|
pub struct TreatAsEmptyStruct {
|
||||||
|
internal: std::sync::Arc<InternalHiddenContext>
|
||||||
|
}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn init_treat_as_empty_struct_context(_out: NonNull<Box<TreatAsEmptyStruct>>) {}
|
||||||
|
|
||||||
|
#[no_mangle]
|
||||||
|
pub unsafe extern "C" fn free_treat_as_empty_struct_context(_src: *mut TreatAsEmptyStruct) {}
|
||||||
|
|
||||||
|
|
||||||
// fn run_physix(){
|
// fn run_physix(){
|
||||||
// unsafe {
|
// unsafe {
|
||||||
// let foundation = physx_create_foundation();
|
// let foundation = physx_create_foundation();
|
||||||
|
@ -170,23 +170,42 @@ pub fn collect_struct(ast: &syn::File, result: &mut Vec<RustStruct>) {
|
|||||||
is_union: true,
|
is_union: true,
|
||||||
});
|
});
|
||||||
} else if let Item::Struct(t) = item {
|
} else if let Item::Struct(t) = item {
|
||||||
if let syn::Fields::Named(f) = &t.fields {
|
let mut repr = None;
|
||||||
let struct_name = t.ident.to_string();
|
for attr in &t.attrs {
|
||||||
let fields = collect_fields(f);
|
let last_segment = attr.path.segments.last().unwrap();
|
||||||
result.push(RustStruct {
|
if last_segment.ident == "repr" {
|
||||||
struct_name,
|
repr = Some(attr.tokens.to_string());
|
||||||
fields,
|
}
|
||||||
is_union: false,
|
}
|
||||||
});
|
|
||||||
} else if let syn::Fields::Unnamed(f) = &t.fields {
|
if let Some(_) = repr {
|
||||||
let struct_name = t.ident.to_string();
|
if let syn::Fields::Named(f) = &t.fields {
|
||||||
let fields = collect_fields_unnamed(f);
|
let struct_name = t.ident.to_string();
|
||||||
result.push(RustStruct {
|
let fields = collect_fields(f);
|
||||||
struct_name,
|
result.push(RustStruct {
|
||||||
fields,
|
struct_name,
|
||||||
is_union: false,
|
fields,
|
||||||
});
|
is_union: false,
|
||||||
} else if let syn::Fields::Unit = &t.fields {
|
});
|
||||||
|
} else if let syn::Fields::Unnamed(f) = &t.fields {
|
||||||
|
let struct_name = t.ident.to_string();
|
||||||
|
let fields = collect_fields_unnamed(f);
|
||||||
|
result.push(RustStruct {
|
||||||
|
struct_name,
|
||||||
|
fields,
|
||||||
|
is_union: false,
|
||||||
|
});
|
||||||
|
} else if let syn::Fields::Unit = &t.fields {
|
||||||
|
let struct_name = t.ident.to_string();
|
||||||
|
let fields: Vec<FieldMember> = Vec::new();
|
||||||
|
result.push(RustStruct {
|
||||||
|
struct_name,
|
||||||
|
fields,
|
||||||
|
is_union: false,
|
||||||
|
});
|
||||||
|
}
|
||||||
|
} else {
|
||||||
|
// non #[repr(?)] struct, treat as Unit struct
|
||||||
let struct_name = t.ident.to_string();
|
let struct_name = t.ident.to_string();
|
||||||
let fields: Vec<FieldMember> = Vec::new();
|
let fields: Vec<FieldMember> = Vec::new();
|
||||||
result.push(RustStruct {
|
result.push(RustStruct {
|
||||||
|
13
dotnet-sandbox/NativeMethods.cs
vendored
13
dotnet-sandbox/NativeMethods.cs
vendored
@ -176,9 +176,17 @@ namespace CsBindgen
|
|||||||
[DllImport(__DllName, EntryPoint = "call_bindgen_lz4", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "call_bindgen_lz4", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void call_bindgen_lz4();
|
public static extern void call_bindgen_lz4();
|
||||||
|
|
||||||
|
|
||||||
[DllImport(__DllName, EntryPoint = "reference_type", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
[DllImport(__DllName, EntryPoint = "reference_type", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
public static extern void reference_type(int* _a, int** _b, void/* byte[] */* _c, Context* _d);
|
public static extern void reference_type(int* _a, int** _b, void/* byte[] */* _c, Context* _d);
|
||||||
|
|
||||||
|
[DllImport(__DllName, EntryPoint = "init_treat_as_empty_struct_context", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern void init_treat_as_empty_struct_context(TreatAsEmptyStruct** _out);
|
||||||
|
|
||||||
|
[DllImport(__DllName, EntryPoint = "free_treat_as_empty_struct_context", CallingConvention = CallingConvention.Cdecl, ExactSpelling = true)]
|
||||||
|
public static extern void free_treat_as_empty_struct_context(TreatAsEmptyStruct* _src);
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -263,6 +271,11 @@ namespace CsBindgen
|
|||||||
public delegate* unmanaged[Cdecl]<int, int> foobar;
|
public delegate* unmanaged[Cdecl]<int, int> foobar;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
[StructLayout(LayoutKind.Sequential)]
|
||||||
|
internal unsafe partial struct TreatAsEmptyStruct
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
[Flags]
|
[Flags]
|
||||||
internal enum EnumFlags : uint
|
internal enum EnumFlags : uint
|
||||||
|
Loading…
Reference in New Issue
Block a user