mirror of
https://github.com/Sarsoo/csbindgen.git
synced 2024-12-23 06:56:27 +00:00
reafactoring part1
This commit is contained in:
parent
4710958684
commit
b986cbefff
45
csbindgen-tests/src/lib.rs
vendored
45
csbindgen-tests/src/lib.rs
vendored
@ -1,4 +1,7 @@
|
||||
use std::ffi::{c_char, CString};
|
||||
use std::{
|
||||
collections::HashSet,
|
||||
ffi::{c_char, c_void, CString},
|
||||
};
|
||||
|
||||
#[allow(dead_code)]
|
||||
#[allow(non_snake_case)]
|
||||
@ -11,8 +14,6 @@ mod lz4;
|
||||
#[allow(non_camel_case_types)]
|
||||
mod lz4_ffi;
|
||||
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
#[allow(improper_ctypes_definitions)]
|
||||
pub extern "C" fn ignore_nop() -> (i32, i32) {
|
||||
@ -20,18 +21,50 @@ pub extern "C" fn ignore_nop() -> (i32, i32) {
|
||||
(1, 2)
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn nop() -> () {
|
||||
println!("hello nop!");
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn my_add(x: i32, y: i32) -> i32 {
|
||||
x + y
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn callback_test(cb: extern fn(a: i32) -> i32) -> i32 {
|
||||
// Fn
|
||||
cb(100)
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn create_counter_context() -> *mut c_void {
|
||||
let ctx = Box::new(CounterContext {
|
||||
set: HashSet::new(),
|
||||
});
|
||||
Box::into_raw(ctx) as *mut c_void
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn insert_counter_context(context: *mut c_void, value: i32) {
|
||||
let mut counter = Box::from_raw(context as *mut CounterContext);
|
||||
counter.set.insert(value);
|
||||
Box::into_raw(counter);
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn delete_counter_context(context: *mut c_void) {
|
||||
let counter = Box::from_raw(context as *mut CounterContext);
|
||||
for value in counter.set.iter() {
|
||||
println!("counter value: {}", value)
|
||||
}
|
||||
}
|
||||
|
||||
#[repr(C)]
|
||||
pub struct CounterContext {
|
||||
pub set: HashSet<i32>,
|
||||
}
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn my_bool(
|
||||
x: bool,
|
||||
@ -114,7 +147,6 @@ pub extern "C" fn delete_context(context: *mut Context) {
|
||||
unsafe { Box::from_raw(context) };
|
||||
}
|
||||
|
||||
|
||||
#[no_mangle]
|
||||
pub extern "C" fn call_bindgen() {
|
||||
let path = std::env::current_dir().unwrap();
|
||||
@ -144,7 +176,6 @@ fn build_test() {
|
||||
// // println!("lz4 num: {}", num);
|
||||
// // }
|
||||
|
||||
|
||||
csbindgen::Builder::default()
|
||||
.input_extern_file("csbindgen-tests/src/lib.rs")
|
||||
.csharp_class_name("LibRust")
|
||||
|
360
csbindgen-tests/src/lz4_ffi.rs
vendored
360
csbindgen-tests/src/lz4_ffi.rs
vendored
@ -9,7 +9,7 @@ use super::lz4;
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_versionNumber(
|
||||
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_versionNumber(
|
||||
|
||||
@ -30,9 +30,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_versionString(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compress_default(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_default(
|
||||
src,
|
||||
@ -46,9 +46,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_default(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
compressedSize: c_int,
|
||||
dstCapacity: c_int
|
||||
) -> c_int
|
||||
compressedSize: c_int,
|
||||
dstCapacity: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_safe(
|
||||
src,
|
||||
@ -60,8 +60,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe(
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compressBound(
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressBound(
|
||||
inputSize
|
||||
@ -72,10 +72,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressBound(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compress_fast(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
acceleration: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
acceleration: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_fast(
|
||||
src,
|
||||
@ -89,7 +89,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_fast(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_sizeofState(
|
||||
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_sizeofState(
|
||||
|
||||
@ -101,10 +101,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_fast_extState(
|
||||
state: *mut c_void,
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
acceleration: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
acceleration: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_fast_extState(
|
||||
state,
|
||||
@ -121,8 +121,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_destSize(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSizePtr: *mut c_int,
|
||||
targetDstSize: c_int
|
||||
) -> c_int
|
||||
targetDstSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_destSize(
|
||||
src,
|
||||
@ -136,10 +136,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_destSize(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_partial(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
targetOutputSize: c_int,
|
||||
dstCapacity: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
targetOutputSize: c_int,
|
||||
dstCapacity: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_safe_partial(
|
||||
src,
|
||||
@ -163,7 +163,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_createStream(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_freeStream(
|
||||
streamPtr: *mut lz4::LZ4_stream_t
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_freeStream(
|
||||
streamPtr
|
||||
@ -184,8 +184,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_resetStream_fast(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_loadDict(
|
||||
streamPtr: *mut lz4::LZ4_stream_t,
|
||||
dictionary: *const c_char,
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_loadDict(
|
||||
streamPtr,
|
||||
@ -199,10 +199,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_fast_continue(
|
||||
streamPtr: *mut lz4::LZ4_stream_t,
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
acceleration: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
acceleration: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_fast_continue(
|
||||
streamPtr,
|
||||
@ -218,8 +218,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_fast_continue(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_saveDict(
|
||||
streamPtr: *mut lz4::LZ4_stream_t,
|
||||
safeBuffer: *mut c_char,
|
||||
maxDictSize: c_int
|
||||
) -> c_int
|
||||
maxDictSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_saveDict(
|
||||
streamPtr,
|
||||
@ -241,7 +241,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_createStreamDecode(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_freeStreamDecode(
|
||||
LZ4_stream: *mut lz4::LZ4_streamDecode_t
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_freeStreamDecode(
|
||||
LZ4_stream
|
||||
@ -252,8 +252,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_freeStreamDecode(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_setStreamDecode(
|
||||
LZ4_streamDecode: *mut lz4::LZ4_streamDecode_t,
|
||||
dictionary: *const c_char,
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_setStreamDecode(
|
||||
LZ4_streamDecode,
|
||||
@ -264,8 +264,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_setStreamDecode(
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_decoderRingBufferSize(
|
||||
maxBlockSize: c_int
|
||||
) -> c_int
|
||||
maxBlockSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decoderRingBufferSize(
|
||||
maxBlockSize
|
||||
@ -277,9 +277,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_continue(
|
||||
LZ4_streamDecode: *mut lz4::LZ4_streamDecode_t,
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_safe_continue(
|
||||
LZ4_streamDecode,
|
||||
@ -294,11 +294,11 @@ pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_continue(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_usingDict(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
dictStart: *const c_char,
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_safe_usingDict(
|
||||
src,
|
||||
@ -314,12 +314,12 @@ pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_usingDict(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_partial_usingDict(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
compressedSize: c_int,
|
||||
targetOutputSize: c_int,
|
||||
maxOutputSize: c_int,
|
||||
compressedSize: c_int,
|
||||
targetOutputSize: c_int,
|
||||
maxOutputSize: c_int,
|
||||
dictStart: *const c_char,
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_safe_partial_usingDict(
|
||||
src,
|
||||
@ -335,7 +335,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_partial_usingDict(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_initStream(
|
||||
buffer: *mut c_void,
|
||||
size: usize
|
||||
size: usize
|
||||
) -> *mut lz4::LZ4_stream_t
|
||||
{
|
||||
lz4::LZ4_initStream(
|
||||
@ -348,8 +348,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_initStream(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compress(
|
||||
src: *const c_char,
|
||||
dest: *mut c_char,
|
||||
srcSize: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress(
|
||||
src,
|
||||
@ -362,9 +362,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compress_limitedOutput(
|
||||
src: *const c_char,
|
||||
dest: *mut c_char,
|
||||
srcSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_limitedOutput(
|
||||
src,
|
||||
@ -379,8 +379,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_withState(
|
||||
state: *mut c_void,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_withState(
|
||||
state,
|
||||
@ -395,9 +395,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_limitedOutput_withState(
|
||||
state: *mut c_void,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_limitedOutput_withState(
|
||||
state,
|
||||
@ -413,8 +413,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_continue(
|
||||
LZ4_streamPtr: *mut lz4::LZ4_stream_t,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_continue(
|
||||
LZ4_streamPtr,
|
||||
@ -429,9 +429,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_limitedOutput_continue(
|
||||
LZ4_streamPtr: *mut lz4::LZ4_stream_t,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_limitedOutput_continue(
|
||||
LZ4_streamPtr,
|
||||
@ -446,8 +446,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_limitedOutput_continue(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_uncompress(
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
outputSize: c_int
|
||||
) -> c_int
|
||||
outputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_uncompress(
|
||||
source,
|
||||
@ -460,9 +460,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_uncompress(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_uncompress_unknownOutputSize(
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
isize_: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
isize_: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_uncompress_unknownOutputSize(
|
||||
source,
|
||||
@ -485,7 +485,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_create(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_sizeofStreamState(
|
||||
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_sizeofStreamState(
|
||||
|
||||
@ -496,7 +496,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_sizeofStreamState(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_resetStreamState(
|
||||
state: *mut c_void,
|
||||
inputBuffer: *mut c_char
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_resetStreamState(
|
||||
state,
|
||||
@ -518,9 +518,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_slideInputBuffer(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_withPrefix64k(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
compressedSize: c_int,
|
||||
maxDstSize: c_int
|
||||
) -> c_int
|
||||
compressedSize: c_int,
|
||||
maxDstSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_safe_withPrefix64k(
|
||||
src,
|
||||
@ -534,8 +534,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_withPrefix64k(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_decompress_fast_withPrefix64k(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
originalSize: c_int
|
||||
) -> c_int
|
||||
originalSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_fast_withPrefix64k(
|
||||
src,
|
||||
@ -548,8 +548,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_decompress_fast_withPrefix64k(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_decompress_fast(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
originalSize: c_int
|
||||
) -> c_int
|
||||
originalSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_fast(
|
||||
src,
|
||||
@ -563,8 +563,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_decompress_fast_continue(
|
||||
LZ4_streamDecode: *mut lz4::LZ4_streamDecode_t,
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
originalSize: c_int
|
||||
) -> c_int
|
||||
originalSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_fast_continue(
|
||||
LZ4_streamDecode,
|
||||
@ -578,10 +578,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_decompress_fast_continue(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_decompress_fast_usingDict(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
originalSize: c_int,
|
||||
originalSize: c_int,
|
||||
dictStart: *const c_char,
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_decompress_fast_usingDict(
|
||||
src,
|
||||
@ -606,10 +606,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_resetStream(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compress_HC(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
dstCapacity: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_HC(
|
||||
src,
|
||||
@ -623,7 +623,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_HC(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_sizeofStateHC(
|
||||
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_sizeofStateHC(
|
||||
|
||||
@ -635,10 +635,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_HC_extStateHC(
|
||||
stateHC: *mut c_void,
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
maxDstSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
maxDstSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_HC_extStateHC(
|
||||
stateHC,
|
||||
@ -656,9 +656,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_HC_destSize(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSizePtr: *mut c_int,
|
||||
targetDstSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
targetDstSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_HC_destSize(
|
||||
stateHC,
|
||||
@ -683,7 +683,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_createStreamHC(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_freeStreamHC(
|
||||
streamHCPtr: *mut lz4::LZ4_streamHC_t
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_freeStreamHC(
|
||||
streamHCPtr
|
||||
@ -693,7 +693,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_freeStreamHC(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_resetStreamHC_fast(
|
||||
streamHCPtr: *mut lz4::LZ4_streamHC_t,
|
||||
compressionLevel: c_int
|
||||
compressionLevel: c_int
|
||||
)
|
||||
{
|
||||
lz4::LZ4_resetStreamHC_fast(
|
||||
@ -706,8 +706,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_resetStreamHC_fast(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_loadDictHC(
|
||||
streamHCPtr: *mut lz4::LZ4_streamHC_t,
|
||||
dictionary: *const c_char,
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
dictSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_loadDictHC(
|
||||
streamHCPtr,
|
||||
@ -721,9 +721,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_HC_continue(
|
||||
streamHCPtr: *mut lz4::LZ4_streamHC_t,
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSize: c_int,
|
||||
maxDstSize: c_int
|
||||
) -> c_int
|
||||
srcSize: c_int,
|
||||
maxDstSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_HC_continue(
|
||||
streamHCPtr,
|
||||
@ -740,8 +740,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_HC_continue_destSize(
|
||||
src: *const c_char,
|
||||
dst: *mut c_char,
|
||||
srcSizePtr: *mut c_int,
|
||||
targetDstSize: c_int
|
||||
) -> c_int
|
||||
targetDstSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compress_HC_continue_destSize(
|
||||
LZ4_streamHCPtr,
|
||||
@ -756,8 +756,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_compress_HC_continue_destSize(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_saveDictHC(
|
||||
streamHCPtr: *mut lz4::LZ4_streamHC_t,
|
||||
safeBuffer: *mut c_char,
|
||||
maxDictSize: c_int
|
||||
) -> c_int
|
||||
maxDictSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_saveDictHC(
|
||||
streamHCPtr,
|
||||
@ -769,7 +769,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_saveDictHC(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_initStreamHC(
|
||||
buffer: *mut c_void,
|
||||
size: usize
|
||||
size: usize
|
||||
) -> *mut lz4::LZ4_streamHC_t
|
||||
{
|
||||
lz4::LZ4_initStreamHC(
|
||||
@ -782,8 +782,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_initStreamHC(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compressHC(
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC(
|
||||
source,
|
||||
@ -796,9 +796,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compressHC_limitedOutput(
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC_limitedOutput(
|
||||
source,
|
||||
@ -812,9 +812,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC_limitedOutput(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compressHC2(
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC2(
|
||||
source,
|
||||
@ -828,10 +828,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC2(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput(
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC2_limitedOutput(
|
||||
source,
|
||||
@ -847,8 +847,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC_withStateHC(
|
||||
state: *mut c_void,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC_withStateHC(
|
||||
state,
|
||||
@ -863,9 +863,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC_limitedOutput_withStateHC(
|
||||
state: *mut c_void,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC_limitedOutput_withStateHC(
|
||||
state,
|
||||
@ -881,9 +881,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_withStateHC(
|
||||
state: *mut c_void,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC2_withStateHC(
|
||||
state,
|
||||
@ -899,10 +899,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_withStateHC(
|
||||
state: *mut c_void,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC2_limitedOutput_withStateHC(
|
||||
state,
|
||||
@ -919,8 +919,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC_continue(
|
||||
LZ4_streamHCPtr: *mut lz4::LZ4_streamHC_t,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC_continue(
|
||||
LZ4_streamHCPtr,
|
||||
@ -935,9 +935,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC_limitedOutput_continue(
|
||||
LZ4_streamHCPtr: *mut lz4::LZ4_streamHC_t,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC_limitedOutput_continue(
|
||||
LZ4_streamHCPtr,
|
||||
@ -961,7 +961,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_createHC(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_freeHC(
|
||||
LZ4HC_Data: *mut c_void
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_freeHC(
|
||||
LZ4HC_Data
|
||||
@ -983,9 +983,9 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_continue(
|
||||
LZ4HC_Data: *mut c_void,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC2_continue(
|
||||
LZ4HC_Data,
|
||||
@ -1001,10 +1001,10 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_continue(
|
||||
LZ4HC_Data: *mut c_void,
|
||||
source: *const c_char,
|
||||
dest: *mut c_char,
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
inputSize: c_int,
|
||||
maxOutputSize: c_int,
|
||||
compressionLevel: c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_compressHC2_limitedOutput_continue(
|
||||
LZ4HC_Data,
|
||||
@ -1019,7 +1019,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_continue(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_sizeofStreamStateHC(
|
||||
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_sizeofStreamStateHC(
|
||||
|
||||
@ -1030,7 +1030,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_sizeofStreamStateHC(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_resetStreamStateHC(
|
||||
state: *mut c_void,
|
||||
inputBuffer: *mut c_char
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4_resetStreamStateHC(
|
||||
state,
|
||||
@ -1041,7 +1041,7 @@ pub unsafe extern "C" fn csbindgen_LZ4_resetStreamStateHC(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4_resetStreamHC(
|
||||
streamHCPtr: *mut lz4::LZ4_streamHC_t,
|
||||
compressionLevel: c_int
|
||||
compressionLevel: c_int
|
||||
)
|
||||
{
|
||||
lz4::LZ4_resetStreamHC(
|
||||
@ -1052,8 +1052,8 @@ pub unsafe extern "C" fn csbindgen_LZ4_resetStreamHC(
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_isError(
|
||||
code: lz4::LZ4F_errorCode_t
|
||||
) -> c_uint
|
||||
code: lz4::LZ4F_errorCode_t
|
||||
) -> c_uint
|
||||
{
|
||||
lz4::LZ4F_isError(
|
||||
code
|
||||
@ -1062,7 +1062,7 @@ pub unsafe extern "C" fn csbindgen_LZ4F_isError(
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_getErrorName(
|
||||
code: lz4::LZ4F_errorCode_t
|
||||
code: lz4::LZ4F_errorCode_t
|
||||
) -> *const c_char
|
||||
{
|
||||
lz4::LZ4F_getErrorName(
|
||||
@ -1073,7 +1073,7 @@ pub unsafe extern "C" fn csbindgen_LZ4F_getErrorName(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_compressionLevel_max(
|
||||
|
||||
) -> c_int
|
||||
) -> c_int
|
||||
{
|
||||
lz4::LZ4F_compressionLevel_max(
|
||||
|
||||
@ -1082,9 +1082,9 @@ pub unsafe extern "C" fn csbindgen_LZ4F_compressionLevel_max(
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_compressFrameBound(
|
||||
srcSize: usize,
|
||||
srcSize: usize,
|
||||
preferencesPtr: *const lz4::LZ4F_preferences_t
|
||||
) -> usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_compressFrameBound(
|
||||
srcSize,
|
||||
@ -1095,11 +1095,11 @@ pub unsafe extern "C" fn csbindgen_LZ4F_compressFrameBound(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_compressFrame(
|
||||
dstBuffer: *mut c_void,
|
||||
dstCapacity: usize,
|
||||
dstCapacity: usize,
|
||||
srcBuffer: *const c_void,
|
||||
srcSize: usize,
|
||||
srcSize: usize,
|
||||
preferencesPtr: *const lz4::LZ4F_preferences_t
|
||||
) -> usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_compressFrame(
|
||||
dstBuffer,
|
||||
@ -1113,7 +1113,7 @@ pub unsafe extern "C" fn csbindgen_LZ4F_compressFrame(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_getVersion(
|
||||
|
||||
) -> c_uint
|
||||
) -> c_uint
|
||||
{
|
||||
lz4::LZ4F_getVersion(
|
||||
|
||||
@ -1123,8 +1123,8 @@ pub unsafe extern "C" fn csbindgen_LZ4F_getVersion(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_createCompressionContext(
|
||||
cctxPtr: *mut *mut lz4::LZ4F_cctx,
|
||||
version: c_uint
|
||||
) -> lz4::LZ4F_errorCode_t
|
||||
version: c_uint
|
||||
) -> lz4::LZ4F_errorCode_t
|
||||
{
|
||||
lz4::LZ4F_createCompressionContext(
|
||||
cctxPtr,
|
||||
@ -1135,7 +1135,7 @@ pub unsafe extern "C" fn csbindgen_LZ4F_createCompressionContext(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_freeCompressionContext(
|
||||
cctx: *mut lz4::LZ4F_cctx
|
||||
) -> lz4::LZ4F_errorCode_t
|
||||
) -> lz4::LZ4F_errorCode_t
|
||||
{
|
||||
lz4::LZ4F_freeCompressionContext(
|
||||
cctx
|
||||
@ -1146,9 +1146,9 @@ pub unsafe extern "C" fn csbindgen_LZ4F_freeCompressionContext(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_compressBegin(
|
||||
cctx: *mut lz4::LZ4F_cctx,
|
||||
dstBuffer: *mut c_void,
|
||||
dstCapacity: usize,
|
||||
dstCapacity: usize,
|
||||
prefsPtr: *const lz4::LZ4F_preferences_t
|
||||
) -> usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_compressBegin(
|
||||
cctx,
|
||||
@ -1160,9 +1160,9 @@ pub unsafe extern "C" fn csbindgen_LZ4F_compressBegin(
|
||||
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_compressBound(
|
||||
srcSize: usize,
|
||||
srcSize: usize,
|
||||
prefsPtr: *const lz4::LZ4F_preferences_t
|
||||
) -> usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_compressBound(
|
||||
srcSize,
|
||||
@ -1174,11 +1174,11 @@ pub unsafe extern "C" fn csbindgen_LZ4F_compressBound(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_compressUpdate(
|
||||
cctx: *mut lz4::LZ4F_cctx,
|
||||
dstBuffer: *mut c_void,
|
||||
dstCapacity: usize,
|
||||
dstCapacity: usize,
|
||||
srcBuffer: *const c_void,
|
||||
srcSize: usize,
|
||||
srcSize: usize,
|
||||
cOptPtr: *const lz4::LZ4F_compressOptions_t
|
||||
) -> usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_compressUpdate(
|
||||
cctx,
|
||||
@ -1194,9 +1194,9 @@ pub unsafe extern "C" fn csbindgen_LZ4F_compressUpdate(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_flush(
|
||||
cctx: *mut lz4::LZ4F_cctx,
|
||||
dstBuffer: *mut c_void,
|
||||
dstCapacity: usize,
|
||||
dstCapacity: usize,
|
||||
cOptPtr: *const lz4::LZ4F_compressOptions_t
|
||||
) -> usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_flush(
|
||||
cctx,
|
||||
@ -1210,9 +1210,9 @@ pub unsafe extern "C" fn csbindgen_LZ4F_flush(
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_compressEnd(
|
||||
cctx: *mut lz4::LZ4F_cctx,
|
||||
dstBuffer: *mut c_void,
|
||||
dstCapacity: usize,
|
||||
dstCapacity: usize,
|
||||
cOptPtr: *const lz4::LZ4F_compressOptions_t
|
||||
) -> usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_compressEnd(
|
||||
cctx,
|
||||
@ -1225,8 +1225,8 @@ pub unsafe extern "C" fn csbindgen_LZ4F_compressEnd(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_createDecompressionContext(
|
||||
dctxPtr: *mut *mut lz4::LZ4F_dctx,
|
||||
version: c_uint
|
||||
) -> lz4::LZ4F_errorCode_t
|
||||
version: c_uint
|
||||
) -> lz4::LZ4F_errorCode_t
|
||||
{
|
||||
lz4::LZ4F_createDecompressionContext(
|
||||
dctxPtr,
|
||||
@ -1237,7 +1237,7 @@ pub unsafe extern "C" fn csbindgen_LZ4F_createDecompressionContext(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_freeDecompressionContext(
|
||||
dctx: *mut lz4::LZ4F_dctx
|
||||
) -> lz4::LZ4F_errorCode_t
|
||||
) -> lz4::LZ4F_errorCode_t
|
||||
{
|
||||
lz4::LZ4F_freeDecompressionContext(
|
||||
dctx
|
||||
@ -1247,8 +1247,8 @@ pub unsafe extern "C" fn csbindgen_LZ4F_freeDecompressionContext(
|
||||
#[no_mangle]
|
||||
pub unsafe extern "C" fn csbindgen_LZ4F_headerSize(
|
||||
src: *const c_void,
|
||||
srcSize: usize
|
||||
) -> usize
|
||||
srcSize: usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_headerSize(
|
||||
src,
|
||||
@ -1262,7 +1262,7 @@ pub unsafe extern "C" fn csbindgen_LZ4F_getFrameInfo(
|
||||
frameInfoPtr: *mut lz4::LZ4F_frameInfo_t,
|
||||
srcBuffer: *const c_void,
|
||||
srcSizePtr: *mut usize
|
||||
) -> usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_getFrameInfo(
|
||||
dctx,
|
||||
@ -1280,7 +1280,7 @@ pub unsafe extern "C" fn csbindgen_LZ4F_decompress(
|
||||
srcBuffer: *const c_void,
|
||||
srcSizePtr: *mut usize,
|
||||
dOptPtr: *const lz4::LZ4F_decompressOptions_t
|
||||
) -> usize
|
||||
) -> usize
|
||||
{
|
||||
lz4::LZ4F_decompress(
|
||||
dctx,
|
||||
|
@ -170,8 +170,8 @@ pub fn emit_csharp(
|
||||
|
||||
structs_string
|
||||
.push_str(format!(" {}public {} {}", attr, type_name, field.name).as_str());
|
||||
if field.rust_type.is_fixed_array {
|
||||
let mut digits = field.rust_type.fixed_array_digits.clone();
|
||||
if let TypeKind::FixedArray(digits, _) = &field.rust_type.type_kind {
|
||||
let mut digits = digits.clone();
|
||||
if digits == "0" {
|
||||
digits = "1".to_string(); // 0 fixed array is not allowed in C#
|
||||
};
|
||||
|
@ -1,5 +1,7 @@
|
||||
use crate::{builder::BindgenOptions, type_meta::*};
|
||||
use std::collections::{HashMap, HashSet};
|
||||
use std::{
|
||||
collections::{HashMap, HashSet},
|
||||
};
|
||||
use syn::{ForeignItem, Item, Pat, ReturnType};
|
||||
|
||||
enum FnItem {
|
||||
@ -65,7 +67,7 @@ fn parse_method(item: FnItem, options: &BindgenOptions) -> Option<ExternMethod>
|
||||
}
|
||||
|
||||
let rust_type = parse_type(&t.ty);
|
||||
if rust_type.type_name.is_empty(){
|
||||
if rust_type.type_name.is_empty() {
|
||||
println!("Csbindgen can't handle this parameter type so ignore generate, method_name: {} parameter_name: {}", method_name, parameter_name);
|
||||
return None;
|
||||
}
|
||||
@ -81,7 +83,10 @@ fn parse_method(item: FnItem, options: &BindgenOptions) -> Option<ExternMethod>
|
||||
if let ReturnType::Type(_, b) = &sig.output {
|
||||
let rust_type = parse_type(b);
|
||||
if rust_type.type_name.is_empty() {
|
||||
println!("Csbindgen can't handle this return type so ignore generate, method_name: {}", method_name);
|
||||
println!(
|
||||
"Csbindgen can't handle this return type so ignore generate, method_name: {}",
|
||||
method_name
|
||||
);
|
||||
return None;
|
||||
}
|
||||
|
||||
@ -114,14 +119,9 @@ pub fn collect_type_alias(ast: &syn::File) -> Vec<(String, RustType)> {
|
||||
result.push((
|
||||
name,
|
||||
RustType {
|
||||
is_const: false,
|
||||
is_fixed_array: false,
|
||||
is_mut: false,
|
||||
is_pointer: false,
|
||||
is_pointer_pointer: false,
|
||||
fixed_array_digits: "".to_string(),
|
||||
type_name: alias.to_string(),
|
||||
},
|
||||
type_kind: TypeKind::Normal
|
||||
}
|
||||
));
|
||||
}
|
||||
}
|
||||
@ -209,59 +209,62 @@ pub fn reduce_struct(structs: &Vec<RustStruct>, using_types: &HashSet<String>) -
|
||||
}
|
||||
|
||||
fn parse_type(t: &syn::Type) -> RustType {
|
||||
let mut has_star = false;
|
||||
let mut has_star_star = false;
|
||||
let mut has_const = false;
|
||||
let mut has_mut = false;
|
||||
let mut digits: String = "".to_string();
|
||||
|
||||
let name = match t {
|
||||
match t {
|
||||
syn::Type::Ptr(t) => {
|
||||
has_star = true;
|
||||
has_const = t.const_token.is_some();
|
||||
has_mut = t.mutability.is_some();
|
||||
let has_const = t.const_token.is_some();
|
||||
// let has_mut = t.mutability.is_some();
|
||||
|
||||
if let syn::Type::Path(path) = &*t.elem {
|
||||
path.path.segments.last().unwrap().ident.to_string()
|
||||
return RustType {
|
||||
type_name: path.path.segments.last().unwrap().ident.to_string(),
|
||||
type_kind: TypeKind::Pointer(if has_const { PointerType::ConstPointer } else { PointerType::MutPointer })
|
||||
};
|
||||
} else if let syn::Type::Ptr(t) = &*t.elem {
|
||||
has_star = false;
|
||||
has_star_star = true;
|
||||
if let syn::Type::Path(path) = &*t.elem {
|
||||
path.path.segments.last().unwrap().ident.to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
return RustType {
|
||||
type_name: path.path.segments.last().unwrap().ident.to_string(),
|
||||
type_kind: TypeKind::Pointer(if has_const { PointerType::ConstPointerPointer } else { PointerType::MutPointerPointer })
|
||||
};
|
||||
}
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
}
|
||||
syn::Type::Path(t) => t.path.segments.last().unwrap().ident.to_string(),
|
||||
syn::Type::Path(t) => {
|
||||
return RustType{
|
||||
type_name:t.path.segments.last().unwrap().ident.to_string(),
|
||||
type_kind: TypeKind::Normal
|
||||
}
|
||||
}
|
||||
syn::Type::Array(t) => {
|
||||
let mut digits = "".to_string();
|
||||
if let syn::Expr::Lit(x) = &t.len {
|
||||
if let syn::Lit::Int(x) = &x.lit {
|
||||
digits = x.base10_digits().to_string();
|
||||
}
|
||||
};
|
||||
|
||||
parse_type(&t.elem).type_name // maybe ok, only retrieve type_name
|
||||
let type_name = parse_type(&t.elem).type_name; // maybe ok, only retrieve type_name
|
||||
return RustType {
|
||||
type_name,
|
||||
type_kind: TypeKind::FixedArray(digits, None),
|
||||
};
|
||||
}
|
||||
syn::Type::Tuple(t) => {
|
||||
if t.elems.len() == 0 {
|
||||
"()".to_string()
|
||||
} else {
|
||||
"".to_string()
|
||||
}
|
||||
return RustType {
|
||||
type_name: "()".to_string(),
|
||||
type_kind: TypeKind::Normal,
|
||||
};
|
||||
};
|
||||
}
|
||||
_ => "".to_string(),
|
||||
syn::Type::BareFn(_) => {
|
||||
//todo!();
|
||||
}
|
||||
_ => {}
|
||||
};
|
||||
|
||||
// type_name = "" will ignore in collect method
|
||||
RustType {
|
||||
is_const: has_const,
|
||||
is_mut: has_mut,
|
||||
is_pointer: has_star,
|
||||
is_pointer_pointer: has_star_star,
|
||||
is_fixed_array: !digits.is_empty(),
|
||||
type_name: name,
|
||||
fixed_array_digits: digits,
|
||||
type_name: "".to_string(),
|
||||
type_kind: TypeKind::Normal,
|
||||
}
|
||||
}
|
||||
|
@ -41,54 +41,49 @@ pub struct ExternMethod {
|
||||
pub return_type: Option<RustType>,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug, PartialEq, Eq, Hash)]
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RustType {
|
||||
pub type_name: String,
|
||||
pub is_pointer: bool,
|
||||
pub is_pointer_pointer: bool,
|
||||
pub is_const: bool,
|
||||
pub is_mut: bool,
|
||||
pub is_fixed_array: bool,
|
||||
pub fixed_array_digits: String,
|
||||
pub type_kind: TypeKind,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum TypeKind {
|
||||
Normal,
|
||||
Pointer(PointerType),
|
||||
FixedArray(String, Option<PointerType>), // digits
|
||||
Function(Vec<RustType>, Option<Box<RustType>>), // parameter, return
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub enum PointerType {
|
||||
ConstPointer,
|
||||
MutPointer,
|
||||
ConstPointerPointer,
|
||||
MutPointerPointer,
|
||||
}
|
||||
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct RustStruct {
|
||||
pub struct_name: String,
|
||||
pub fields: Vec<FieldMember>,
|
||||
pub is_union: bool
|
||||
pub is_union: bool,
|
||||
}
|
||||
|
||||
impl RustType {
|
||||
pub fn to_string(&self, type_path: &str) -> String {
|
||||
let mut sb = String::new();
|
||||
|
||||
if self.is_pointer || self.is_pointer_pointer {
|
||||
sb.push('*');
|
||||
}
|
||||
if self.is_const {
|
||||
sb.push_str("const");
|
||||
}
|
||||
if self.is_mut {
|
||||
sb.push_str("mut");
|
||||
}
|
||||
if self.is_pointer_pointer {
|
||||
if self.is_const {
|
||||
sb.push_str(" *const");
|
||||
} else {
|
||||
sb.push_str(" *mut");
|
||||
}
|
||||
fn emit_pointer(sb: &mut String, p: &PointerType) {
|
||||
match p {
|
||||
ConstPointer => sb.push_str("*const"),
|
||||
MutPointer => sb.push_str("*mut"),
|
||||
ConstPointerPointer => sb.push_str("*const *const"),
|
||||
MutPointerPointer => sb.push_str("*mut *mut"),
|
||||
};
|
||||
}
|
||||
|
||||
sb.push(' ');
|
||||
|
||||
if self.is_fixed_array {
|
||||
sb.push('[');
|
||||
sb.push_str(self.type_name.as_str());
|
||||
sb.push_str("; ");
|
||||
sb.push_str(self.fixed_array_digits.as_str());
|
||||
sb.push(']');
|
||||
} else {
|
||||
let emit_type_name = |sb: &mut String| {
|
||||
if !(self.type_name.starts_with("c_")
|
||||
|| self.type_name == "usize"
|
||||
|| self.type_name == "isize"
|
||||
@ -98,7 +93,35 @@ impl RustType {
|
||||
sb.push_str("::");
|
||||
}
|
||||
sb.push_str(self.type_name.as_str());
|
||||
}
|
||||
};
|
||||
|
||||
use PointerType::*;
|
||||
use TypeKind::*;
|
||||
match &self.type_kind {
|
||||
Normal => {
|
||||
emit_type_name(&mut sb);
|
||||
}
|
||||
Pointer(p) => {
|
||||
emit_pointer(&mut sb, p);
|
||||
sb.push(' ');
|
||||
emit_type_name(&mut sb);
|
||||
}
|
||||
FixedArray(digits, pointer) => {
|
||||
if let Some(p) = pointer {
|
||||
emit_pointer(&mut sb, p);
|
||||
sb.push(' ');
|
||||
}
|
||||
|
||||
sb.push('[');
|
||||
emit_type_name(&mut sb);
|
||||
sb.push_str("; ");
|
||||
sb.push_str(digits.as_str());
|
||||
sb.push(']');
|
||||
}
|
||||
Function(x, y) => {
|
||||
todo!();
|
||||
}
|
||||
};
|
||||
|
||||
sb
|
||||
}
|
||||
@ -157,36 +180,48 @@ impl RustType {
|
||||
|
||||
let mut sb = String::new();
|
||||
|
||||
if self.is_fixed_array {
|
||||
sb.push_str("fixed ");
|
||||
match self.type_kind {
|
||||
TypeKind::FixedArray(_, _) => {
|
||||
sb.push_str("fixed ");
|
||||
|
||||
let type_name = convert_type_name(use_type.type_name.as_str(), options);
|
||||
let type_name = match type_name.as_str() {
|
||||
// C# fixed allow types
|
||||
"bool" | "byte" | "short" | "int" | "long" | "char" | "sbyte" | "ushort"
|
||||
| "uint" | "ulong" | "float" | "double" => type_name,
|
||||
_ => format!("byte/* {}, this length is invalid so must keep pointer and can't edit from C# */", type_name)
|
||||
};
|
||||
let type_name = convert_type_name(use_type.type_name.as_str(), options);
|
||||
let type_name = match type_name.as_str() {
|
||||
// C# fixed allow types
|
||||
"bool" | "byte" | "short" | "int" | "long" | "char" | "sbyte" | "ushort"
|
||||
| "uint" | "ulong" | "float" | "double" => type_name,
|
||||
_ => format!("byte/* {}, this length is invalid so must keep pointer and can't edit from C# */", type_name)
|
||||
};
|
||||
|
||||
sb.push_str(type_name.as_str());
|
||||
} else {
|
||||
sb.push_str(convert_type_name(use_type.type_name.as_str(), options).as_str());
|
||||
if use_alias {
|
||||
if use_type.is_pointer {
|
||||
sb.push('*');
|
||||
sb.push_str(type_name.as_str());
|
||||
}
|
||||
_ => {
|
||||
sb.push_str(convert_type_name(use_type.type_name.as_str(), options).as_str());
|
||||
|
||||
if use_alias {
|
||||
if let TypeKind::Pointer(p) = &use_type.type_kind {
|
||||
match p {
|
||||
PointerType::MutPointer | PointerType::ConstPointer => {
|
||||
sb.push('*');
|
||||
}
|
||||
PointerType::MutPointerPointer | PointerType::ConstPointerPointer => {
|
||||
sb.push_str("**");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
if use_type.is_pointer_pointer {
|
||||
sb.push_str("**");
|
||||
|
||||
if let TypeKind::Pointer(p) = &self.type_kind {
|
||||
match p {
|
||||
PointerType::MutPointer | PointerType::ConstPointer => {
|
||||
sb.push('*');
|
||||
}
|
||||
PointerType::MutPointerPointer | PointerType::ConstPointerPointer => {
|
||||
sb.push_str("**");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
if self.is_pointer {
|
||||
sb.push('*');
|
||||
}
|
||||
if self.is_pointer_pointer {
|
||||
sb.push_str("**");
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
sb
|
||||
}
|
||||
|
71
dotnet-sandbox/Program.cs
vendored
71
dotnet-sandbox/Program.cs
vendored
@ -13,47 +13,54 @@ using System.Text;
|
||||
|
||||
unsafe
|
||||
{
|
||||
LibRust.call_bindgen();
|
||||
// LibRust.call_bindgen();
|
||||
|
||||
|
||||
var ctx = LibRust.create_counter_context();
|
||||
LibRust.insert_counter_context(ctx, 10);
|
||||
LibRust.insert_counter_context(ctx, 20);
|
||||
LibRust.insert_counter_context(ctx, 20);
|
||||
LibRust.insert_counter_context(ctx, 30);
|
||||
LibRust.insert_counter_context(ctx, 99);
|
||||
LibRust.delete_counter_context(ctx);
|
||||
|
||||
var cString = LibRust.alloc_c_string();
|
||||
var u8String = LibRust.alloc_u8_string();
|
||||
var u8Buffer = LibRust.alloc_u8_buffer();
|
||||
var i32Buffer = LibRust.alloc_i32_buffer();
|
||||
try
|
||||
{
|
||||
var str = new String((sbyte*)cString);
|
||||
Console.WriteLine(str);
|
||||
//var cString = LibRust.alloc_c_string();
|
||||
//var u8String = LibRust.alloc_u8_string();
|
||||
//var u8Buffer = LibRust.alloc_u8_buffer();
|
||||
//var i32Buffer = LibRust.alloc_i32_buffer();
|
||||
//try
|
||||
//{
|
||||
// var str = new String((sbyte*)cString);
|
||||
// Console.WriteLine(str);
|
||||
|
||||
Console.WriteLine("----");
|
||||
// Console.WriteLine("----");
|
||||
|
||||
var str2 = Encoding.UTF8.GetString(u8String->AsSpan());
|
||||
Console.WriteLine(str2);
|
||||
// var str2 = Encoding.UTF8.GetString(u8String->AsSpan());
|
||||
// Console.WriteLine(str2);
|
||||
|
||||
Console.WriteLine("----");
|
||||
// Console.WriteLine("----");
|
||||
|
||||
var buffer3 = u8Buffer->AsSpan();
|
||||
foreach (var item in buffer3)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
// var buffer3 = u8Buffer->AsSpan();
|
||||
// foreach (var item in buffer3)
|
||||
// {
|
||||
// Console.WriteLine(item);
|
||||
// }
|
||||
|
||||
Console.WriteLine("----");
|
||||
// Console.WriteLine("----");
|
||||
|
||||
var i32Span = i32Buffer->AsSpan<int>();
|
||||
foreach (var item in i32Span)
|
||||
{
|
||||
Console.WriteLine(item);
|
||||
}
|
||||
}
|
||||
finally
|
||||
{
|
||||
LibRust.free_c_string(cString);
|
||||
LibRust.free_u8_string(u8String);
|
||||
LibRust.free_u8_buffer(u8Buffer);
|
||||
LibRust.free_i32_buffer(i32Buffer);
|
||||
}
|
||||
// var i32Span = i32Buffer->AsSpan<int>();
|
||||
// foreach (var item in i32Span)
|
||||
// {
|
||||
// Console.WriteLine(item);
|
||||
// }
|
||||
//}
|
||||
//finally
|
||||
//{
|
||||
// LibRust.free_c_string(cString);
|
||||
// LibRust.free_u8_string(u8String);
|
||||
// LibRust.free_u8_buffer(u8Buffer);
|
||||
// LibRust.free_i32_buffer(i32Buffer);
|
||||
//}
|
||||
|
||||
|
||||
//var buf = LibRust.return_raw_buffer();
|
||||
|
9
dotnet-sandbox/method_call.cs
vendored
9
dotnet-sandbox/method_call.cs
vendored
@ -17,6 +17,15 @@ namespace CsBindgen
|
||||
[DllImport(__DllName, EntryPoint = "my_add", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern int my_add(int x, int y);
|
||||
|
||||
[DllImport(__DllName, EntryPoint = "create_counter_context", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void* create_counter_context();
|
||||
|
||||
[DllImport(__DllName, EntryPoint = "insert_counter_context", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void insert_counter_context(void* context, int value);
|
||||
|
||||
[DllImport(__DllName, EntryPoint = "delete_counter_context", CallingConvention = CallingConvention.Cdecl)]
|
||||
public static extern void delete_counter_context(void* context);
|
||||
|
||||
[DllImport(__DllName, EntryPoint = "my_bool", CallingConvention = CallingConvention.Cdecl)]
|
||||
[return: MarshalAs(UnmanagedType.U1)]
|
||||
public static extern bool my_bool([MarshalAs(UnmanagedType.U1)] bool x, [MarshalAs(UnmanagedType.U1)] bool y, [MarshalAs(UnmanagedType.U1)] bool z, bool* xr, bool* yr, bool* zr);
|
||||
|
Loading…
Reference in New Issue
Block a user