From 4dba240d2becc74d9c77860fd10d0baeb97660fc Mon Sep 17 00:00:00 2001 From: neuecc Date: Sat, 4 Mar 2023 14:39:45 +0900 Subject: [PATCH] format rust -> rust generated code --- csbindgen-tests/build.rs | 34 +- csbindgen-tests/src/lib.rs | 36 +- csbindgen-tests/src/lz4_ffi.rs | 1274 ++++++++++++++------------------ csbindgen/src/emitter.rs | 10 +- csbindgen/src/type_meta.rs | 2 + dotnet-sandbox/Program.cs | 24 +- dotnet-sandbox/asm.cs | 3 + dotnet-sandbox/method_call.cs | 9 + 8 files changed, 637 insertions(+), 755 deletions(-) create mode 100644 dotnet-sandbox/asm.cs diff --git a/csbindgen-tests/build.rs b/csbindgen-tests/build.rs index 2af8b24..029ba7f 100644 --- a/csbindgen-tests/build.rs +++ b/csbindgen-tests/build.rs @@ -40,23 +40,23 @@ fn main() { // .generate()? // .write_to_file("src/bullet3.rs")?; - // csbindgen::Builder::default() - // .input_bindgen_file("src/lz4.rs") - // .method_filter(|x| { !x.starts_with("_") && !x.starts_with("XXH") } ) - // .rust_method_prefix("csbindgen_") - // .rust_file_header("use super::lz4;") - // .rust_method_type_path("lz4") - // .csharp_class_name("LibLz4") - // .csharp_namespace("CsBindgen") - // .csharp_dll_name("csbindgen_tests") - // .csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal") - // .csharp_entry_point_prefix("csbindgen_") - // .csharp_method_prefix("") - // .csharp_class_accessibility("public") - // .csharp_c_long_convert("int") - // .csharp_c_ulong_convert("uint") - // .generate_to_file("src/lz4_ffi.rs", "../dotnet-sandbox/lz4_bindgen.cs") - // .unwrap(); + csbindgen::Builder::default() + .input_bindgen_file("src/lz4.rs") + .method_filter(|x| { x.starts_with("LZ4")} ) + .rust_method_prefix("csbindgen_") + .rust_file_header("use super::lz4;") + .rust_method_type_path("lz4") + .csharp_class_name("LibLz4") + .csharp_namespace("CsBindgen") + .csharp_dll_name("csbindgen_tests") + .csharp_dll_name_if("UNITY_IOS && !UNITY_EDITOR", "__Internal") + .csharp_entry_point_prefix("csbindgen_") + .csharp_method_prefix("") + .csharp_class_accessibility("public") + .csharp_c_long_convert("int") + .csharp_c_ulong_convert("uint") + .generate_to_file("src/lz4_ffi.rs", "../dotnet-sandbox/lz4_bindgen.cs") + .unwrap(); csbindgen::Builder::default() .input_extern_file("src/lib.rs") diff --git a/csbindgen-tests/src/lib.rs b/csbindgen-tests/src/lib.rs index afda906..9451f3a 100644 --- a/csbindgen-tests/src/lib.rs +++ b/csbindgen-tests/src/lib.rs @@ -1,3 +1,5 @@ +use std::io::Bytes; + #[allow(dead_code)] #[allow(non_snake_case)] #[allow(non_camel_case_types)] @@ -14,15 +16,43 @@ pub extern "C" fn my_add(x: i32, y: i32) -> i32 { x + y } -#[allow(unused)] #[no_mangle] -pub extern "C" fn my_bool(x: bool, y: bool, z: bool, xr: *mut bool, yr: *mut bool, zr: *mut bool) -> bool { +pub extern "C" fn my_bool( + x: bool, + y: bool, + z: bool, + xr: *mut bool, + yr: *mut bool, + zr: *mut bool, +) -> bool { unsafe { *xr = x; *yr = y; *zr = z; - true } + + true +} + +#[no_mangle] +pub unsafe extern "C" fn new(x: *mut *mut Vec) { + let v = Box::new(Vec::new()); + *x = Box::into_raw(v); +} + +#[no_mangle] +pub unsafe extern "C" fn unsafe_return_string() -> *const u8 { +todo!(); +} + +#[no_mangle] +pub unsafe extern "C" fn unsafe_return_string2() -> *const u8 { + todo!(); +} + +#[no_mangle] +pub extern "C" fn unsafe_destroy_string(s: *mut String) { + unsafe { Box::from_raw(s) }; } #[test] diff --git a/csbindgen-tests/src/lz4_ffi.rs b/csbindgen-tests/src/lz4_ffi.rs index 8bdd336..644a09f 100644 --- a/csbindgen-tests/src/lz4_ffi.rs +++ b/csbindgen-tests/src/lz4_ffi.rs @@ -7,79 +7,69 @@ use super::lz4; #[no_mangle] -pub extern "C" fn csbindgen_LZ4_versionNumber( +pub unsafe extern "C" fn csbindgen_LZ4_versionNumber( ) -> c_int { - unsafe { - return lz4::LZ4_versionNumber( + lz4::LZ4_versionNumber( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_versionString( +pub unsafe extern "C" fn csbindgen_LZ4_versionString( ) -> *const c_char { - unsafe { - return lz4::LZ4_versionString( + lz4::LZ4_versionString( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_default( +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 { - unsafe { - return lz4::LZ4_compress_default( - src, - dst, - srcSize, - dstCapacity - ) - } + lz4::LZ4_compress_default( + src, + dst, + srcSize, + dstCapacity + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_safe( +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 { - unsafe { - return lz4::LZ4_decompress_safe( - src, - dst, - compressedSize, - dstCapacity - ) - } + lz4::LZ4_decompress_safe( + src, + dst, + compressedSize, + dstCapacity + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressBound( +pub unsafe extern "C" fn csbindgen_LZ4_compressBound( inputSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressBound( - inputSize - ) - } + lz4::LZ4_compressBound( + inputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_fast( +pub unsafe extern "C" fn csbindgen_LZ4_compress_fast( src: *const c_char, dst: *mut c_char, srcSize: c_int, @@ -87,31 +77,27 @@ pub extern "C" fn csbindgen_LZ4_compress_fast( acceleration: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_fast( - src, - dst, - srcSize, - dstCapacity, - acceleration - ) - } + lz4::LZ4_compress_fast( + src, + dst, + srcSize, + dstCapacity, + acceleration + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_sizeofState( +pub unsafe extern "C" fn csbindgen_LZ4_sizeofState( ) -> c_int { - unsafe { - return lz4::LZ4_sizeofState( + lz4::LZ4_sizeofState( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_fast_extState( +pub unsafe extern "C" fn csbindgen_LZ4_compress_fast_extState( state: *mut c_void, src: *const c_char, dst: *mut c_char, @@ -120,38 +106,34 @@ pub extern "C" fn csbindgen_LZ4_compress_fast_extState( acceleration: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_fast_extState( - state, - src, - dst, - srcSize, - dstCapacity, - acceleration - ) - } + lz4::LZ4_compress_fast_extState( + state, + src, + dst, + srcSize, + dstCapacity, + acceleration + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_destSize( +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 { - unsafe { - return lz4::LZ4_compress_destSize( - src, - dst, - srcSizePtr, - targetDstSize - ) - } + lz4::LZ4_compress_destSize( + src, + dst, + srcSizePtr, + targetDstSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_safe_partial( +pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_partial( src: *const c_char, dst: *mut c_char, srcSize: c_int, @@ -159,71 +141,61 @@ pub extern "C" fn csbindgen_LZ4_decompress_safe_partial( dstCapacity: c_int ) -> c_int { - unsafe { - return lz4::LZ4_decompress_safe_partial( - src, - dst, - srcSize, - targetOutputSize, - dstCapacity - ) - } + lz4::LZ4_decompress_safe_partial( + src, + dst, + srcSize, + targetOutputSize, + dstCapacity + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_createStream( +pub unsafe extern "C" fn csbindgen_LZ4_createStream( ) -> *mut lz4::LZ4_stream_t { - unsafe { - return lz4::LZ4_createStream( + lz4::LZ4_createStream( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_freeStream( +pub unsafe extern "C" fn csbindgen_LZ4_freeStream( streamPtr: *mut lz4::LZ4_stream_t ) -> c_int { - unsafe { - return lz4::LZ4_freeStream( - streamPtr - ) - } + lz4::LZ4_freeStream( + streamPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_resetStream_fast( +pub unsafe extern "C" fn csbindgen_LZ4_resetStream_fast( streamPtr: *mut lz4::LZ4_stream_t ) { - unsafe { - return lz4::LZ4_resetStream_fast( - streamPtr - ) - } + lz4::LZ4_resetStream_fast( + streamPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_loadDict( +pub unsafe extern "C" fn csbindgen_LZ4_loadDict( streamPtr: *mut lz4::LZ4_stream_t, dictionary: *const c_char, dictSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_loadDict( - streamPtr, - dictionary, - dictSize - ) - } + lz4::LZ4_loadDict( + streamPtr, + dictionary, + dictSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_fast_continue( +pub unsafe extern "C" fn csbindgen_LZ4_compress_fast_continue( streamPtr: *mut lz4::LZ4_stream_t, src: *const c_char, dst: *mut c_char, @@ -232,88 +204,76 @@ pub extern "C" fn csbindgen_LZ4_compress_fast_continue( acceleration: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_fast_continue( - streamPtr, - src, - dst, - srcSize, - dstCapacity, - acceleration - ) - } + lz4::LZ4_compress_fast_continue( + streamPtr, + src, + dst, + srcSize, + dstCapacity, + acceleration + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_saveDict( +pub unsafe extern "C" fn csbindgen_LZ4_saveDict( streamPtr: *mut lz4::LZ4_stream_t, safeBuffer: *mut c_char, maxDictSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_saveDict( - streamPtr, - safeBuffer, - maxDictSize - ) - } + lz4::LZ4_saveDict( + streamPtr, + safeBuffer, + maxDictSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_createStreamDecode( +pub unsafe extern "C" fn csbindgen_LZ4_createStreamDecode( ) -> *mut lz4::LZ4_streamDecode_t { - unsafe { - return lz4::LZ4_createStreamDecode( + lz4::LZ4_createStreamDecode( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_freeStreamDecode( +pub unsafe extern "C" fn csbindgen_LZ4_freeStreamDecode( LZ4_stream: *mut lz4::LZ4_streamDecode_t ) -> c_int { - unsafe { - return lz4::LZ4_freeStreamDecode( - LZ4_stream - ) - } + lz4::LZ4_freeStreamDecode( + LZ4_stream + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_setStreamDecode( +pub unsafe extern "C" fn csbindgen_LZ4_setStreamDecode( LZ4_streamDecode: *mut lz4::LZ4_streamDecode_t, dictionary: *const c_char, dictSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_setStreamDecode( - LZ4_streamDecode, - dictionary, - dictSize - ) - } + lz4::LZ4_setStreamDecode( + LZ4_streamDecode, + dictionary, + dictSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decoderRingBufferSize( +pub unsafe extern "C" fn csbindgen_LZ4_decoderRingBufferSize( maxBlockSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_decoderRingBufferSize( - maxBlockSize - ) - } + lz4::LZ4_decoderRingBufferSize( + maxBlockSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_safe_continue( +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, @@ -321,19 +281,17 @@ pub extern "C" fn csbindgen_LZ4_decompress_safe_continue( dstCapacity: c_int ) -> c_int { - unsafe { - return lz4::LZ4_decompress_safe_continue( - LZ4_streamDecode, - src, - dst, - srcSize, - dstCapacity - ) - } + lz4::LZ4_decompress_safe_continue( + LZ4_streamDecode, + src, + dst, + srcSize, + dstCapacity + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_safe_usingDict( +pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_usingDict( src: *const c_char, dst: *mut c_char, srcSize: c_int, @@ -342,20 +300,18 @@ pub extern "C" fn csbindgen_LZ4_decompress_safe_usingDict( dictSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_decompress_safe_usingDict( - src, - dst, - srcSize, - dstCapacity, - dictStart, - dictSize - ) - } + lz4::LZ4_decompress_safe_usingDict( + src, + dst, + srcSize, + dstCapacity, + dictStart, + dictSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_safe_partial_usingDict( +pub unsafe extern "C" fn csbindgen_LZ4_decompress_safe_partial_usingDict( src: *const c_char, dst: *mut c_char, compressedSize: c_int, @@ -365,87 +321,77 @@ pub extern "C" fn csbindgen_LZ4_decompress_safe_partial_usingDict( dictSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_decompress_safe_partial_usingDict( - src, - dst, - compressedSize, - targetOutputSize, - maxOutputSize, - dictStart, - dictSize - ) - } + lz4::LZ4_decompress_safe_partial_usingDict( + src, + dst, + compressedSize, + targetOutputSize, + maxOutputSize, + dictStart, + dictSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_initStream( +pub unsafe extern "C" fn csbindgen_LZ4_initStream( buffer: *mut c_void, size: usize ) -> *mut lz4::LZ4_stream_t { - unsafe { - return lz4::LZ4_initStream( - buffer, - size - ) - } + lz4::LZ4_initStream( + buffer, + size + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress( +pub unsafe extern "C" fn csbindgen_LZ4_compress( src: *const c_char, dest: *mut c_char, srcSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress( - src, - dest, - srcSize - ) - } + lz4::LZ4_compress( + src, + dest, + srcSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_limitedOutput( +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 { - unsafe { - return lz4::LZ4_compress_limitedOutput( - src, - dest, - srcSize, - maxOutputSize - ) - } + lz4::LZ4_compress_limitedOutput( + src, + dest, + srcSize, + maxOutputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_withState( +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 { - unsafe { - return lz4::LZ4_compress_withState( - state, - source, - dest, - inputSize - ) - } + lz4::LZ4_compress_withState( + state, + source, + dest, + inputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_limitedOutput_withState( +pub unsafe extern "C" fn csbindgen_LZ4_compress_limitedOutput_withState( state: *mut c_void, source: *const c_char, dest: *mut c_char, @@ -453,37 +399,33 @@ pub extern "C" fn csbindgen_LZ4_compress_limitedOutput_withState( maxOutputSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_limitedOutput_withState( - state, - source, - dest, - inputSize, - maxOutputSize - ) - } + lz4::LZ4_compress_limitedOutput_withState( + state, + source, + dest, + inputSize, + maxOutputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_continue( +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 { - unsafe { - return lz4::LZ4_compress_continue( - LZ4_streamPtr, - source, - dest, - inputSize - ) - } + lz4::LZ4_compress_continue( + LZ4_streamPtr, + source, + dest, + inputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_limitedOutput_continue( +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, @@ -491,171 +433,149 @@ pub extern "C" fn csbindgen_LZ4_compress_limitedOutput_continue( maxOutputSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_limitedOutput_continue( - LZ4_streamPtr, - source, - dest, - inputSize, - maxOutputSize - ) - } + lz4::LZ4_compress_limitedOutput_continue( + LZ4_streamPtr, + source, + dest, + inputSize, + maxOutputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_uncompress( +pub unsafe extern "C" fn csbindgen_LZ4_uncompress( source: *const c_char, dest: *mut c_char, outputSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_uncompress( - source, - dest, - outputSize - ) - } + lz4::LZ4_uncompress( + source, + dest, + outputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_uncompress_unknownOutputSize( +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 { - unsafe { - return lz4::LZ4_uncompress_unknownOutputSize( - source, - dest, - isize_, - maxOutputSize - ) - } + lz4::LZ4_uncompress_unknownOutputSize( + source, + dest, + isize_, + maxOutputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_create( +pub unsafe extern "C" fn csbindgen_LZ4_create( inputBuffer: *mut c_char ) -> *mut c_void { - unsafe { - return lz4::LZ4_create( - inputBuffer - ) - } + lz4::LZ4_create( + inputBuffer + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_sizeofStreamState( +pub unsafe extern "C" fn csbindgen_LZ4_sizeofStreamState( ) -> c_int { - unsafe { - return lz4::LZ4_sizeofStreamState( + lz4::LZ4_sizeofStreamState( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_resetStreamState( +pub unsafe extern "C" fn csbindgen_LZ4_resetStreamState( state: *mut c_void, inputBuffer: *mut c_char ) -> c_int { - unsafe { - return lz4::LZ4_resetStreamState( - state, - inputBuffer - ) - } + lz4::LZ4_resetStreamState( + state, + inputBuffer + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_slideInputBuffer( +pub unsafe extern "C" fn csbindgen_LZ4_slideInputBuffer( state: *mut c_void ) -> *mut c_char { - unsafe { - return lz4::LZ4_slideInputBuffer( - state - ) - } + lz4::LZ4_slideInputBuffer( + state + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_safe_withPrefix64k( +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 { - unsafe { - return lz4::LZ4_decompress_safe_withPrefix64k( - src, - dst, - compressedSize, - maxDstSize - ) - } + lz4::LZ4_decompress_safe_withPrefix64k( + src, + dst, + compressedSize, + maxDstSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_fast_withPrefix64k( +pub unsafe extern "C" fn csbindgen_LZ4_decompress_fast_withPrefix64k( src: *const c_char, dst: *mut c_char, originalSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_decompress_fast_withPrefix64k( - src, - dst, - originalSize - ) - } + lz4::LZ4_decompress_fast_withPrefix64k( + src, + dst, + originalSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_fast( +pub unsafe extern "C" fn csbindgen_LZ4_decompress_fast( src: *const c_char, dst: *mut c_char, originalSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_decompress_fast( - src, - dst, - originalSize - ) - } + lz4::LZ4_decompress_fast( + src, + dst, + originalSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_fast_continue( +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 { - unsafe { - return lz4::LZ4_decompress_fast_continue( - LZ4_streamDecode, - src, - dst, - originalSize - ) - } + lz4::LZ4_decompress_fast_continue( + LZ4_streamDecode, + src, + dst, + originalSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_decompress_fast_usingDict( +pub unsafe extern "C" fn csbindgen_LZ4_decompress_fast_usingDict( src: *const c_char, dst: *mut c_char, originalSize: c_int, @@ -663,31 +583,27 @@ pub extern "C" fn csbindgen_LZ4_decompress_fast_usingDict( dictSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_decompress_fast_usingDict( - src, - dst, - originalSize, - dictStart, - dictSize - ) - } + lz4::LZ4_decompress_fast_usingDict( + src, + dst, + originalSize, + dictStart, + dictSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_resetStream( +pub unsafe extern "C" fn csbindgen_LZ4_resetStream( streamPtr: *mut lz4::LZ4_stream_t ) { - unsafe { - return lz4::LZ4_resetStream( - streamPtr - ) - } + lz4::LZ4_resetStream( + streamPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_HC( +pub unsafe extern "C" fn csbindgen_LZ4_compress_HC( src: *const c_char, dst: *mut c_char, srcSize: c_int, @@ -695,31 +611,27 @@ pub extern "C" fn csbindgen_LZ4_compress_HC( compressionLevel: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_HC( - src, - dst, - srcSize, - dstCapacity, - compressionLevel - ) - } + lz4::LZ4_compress_HC( + src, + dst, + srcSize, + dstCapacity, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_sizeofStateHC( +pub unsafe extern "C" fn csbindgen_LZ4_sizeofStateHC( ) -> c_int { - unsafe { - return lz4::LZ4_sizeofStateHC( + lz4::LZ4_sizeofStateHC( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_HC_extStateHC( +pub unsafe extern "C" fn csbindgen_LZ4_compress_HC_extStateHC( stateHC: *mut c_void, src: *const c_char, dst: *mut c_char, @@ -728,20 +640,18 @@ pub extern "C" fn csbindgen_LZ4_compress_HC_extStateHC( compressionLevel: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_HC_extStateHC( - stateHC, - src, - dst, - srcSize, - maxDstSize, - compressionLevel - ) - } + lz4::LZ4_compress_HC_extStateHC( + stateHC, + src, + dst, + srcSize, + maxDstSize, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_HC_destSize( +pub unsafe extern "C" fn csbindgen_LZ4_compress_HC_destSize( stateHC: *mut c_void, src: *const c_char, dst: *mut c_char, @@ -750,74 +660,64 @@ pub extern "C" fn csbindgen_LZ4_compress_HC_destSize( compressionLevel: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_HC_destSize( - stateHC, - src, - dst, - srcSizePtr, - targetDstSize, - compressionLevel - ) - } + lz4::LZ4_compress_HC_destSize( + stateHC, + src, + dst, + srcSizePtr, + targetDstSize, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_createStreamHC( +pub unsafe extern "C" fn csbindgen_LZ4_createStreamHC( ) -> *mut lz4::LZ4_streamHC_t { - unsafe { - return lz4::LZ4_createStreamHC( + lz4::LZ4_createStreamHC( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_freeStreamHC( +pub unsafe extern "C" fn csbindgen_LZ4_freeStreamHC( streamHCPtr: *mut lz4::LZ4_streamHC_t ) -> c_int { - unsafe { - return lz4::LZ4_freeStreamHC( - streamHCPtr - ) - } + lz4::LZ4_freeStreamHC( + streamHCPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_resetStreamHC_fast( +pub unsafe extern "C" fn csbindgen_LZ4_resetStreamHC_fast( streamHCPtr: *mut lz4::LZ4_streamHC_t, compressionLevel: c_int ) { - unsafe { - return lz4::LZ4_resetStreamHC_fast( - streamHCPtr, - compressionLevel - ) - } + lz4::LZ4_resetStreamHC_fast( + streamHCPtr, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_loadDictHC( +pub unsafe extern "C" fn csbindgen_LZ4_loadDictHC( streamHCPtr: *mut lz4::LZ4_streamHC_t, dictionary: *const c_char, dictSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_loadDictHC( - streamHCPtr, - dictionary, - dictSize - ) - } + lz4::LZ4_loadDictHC( + streamHCPtr, + dictionary, + dictSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_HC_continue( +pub unsafe extern "C" fn csbindgen_LZ4_compress_HC_continue( streamHCPtr: *mut lz4::LZ4_streamHC_t, src: *const c_char, dst: *mut c_char, @@ -825,19 +725,17 @@ pub extern "C" fn csbindgen_LZ4_compress_HC_continue( maxDstSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_HC_continue( - streamHCPtr, - src, - dst, - srcSize, - maxDstSize - ) - } + lz4::LZ4_compress_HC_continue( + streamHCPtr, + src, + dst, + srcSize, + maxDstSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_HC_continue_destSize( +pub unsafe extern "C" fn csbindgen_LZ4_compress_HC_continue_destSize( LZ4_streamHCPtr: *mut lz4::LZ4_streamHC_t, src: *const c_char, dst: *mut c_char, @@ -845,101 +743,89 @@ pub extern "C" fn csbindgen_LZ4_compress_HC_continue_destSize( targetDstSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compress_HC_continue_destSize( - LZ4_streamHCPtr, - src, - dst, - srcSizePtr, - targetDstSize - ) - } + lz4::LZ4_compress_HC_continue_destSize( + LZ4_streamHCPtr, + src, + dst, + srcSizePtr, + targetDstSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_saveDictHC( +pub unsafe extern "C" fn csbindgen_LZ4_saveDictHC( streamHCPtr: *mut lz4::LZ4_streamHC_t, safeBuffer: *mut c_char, maxDictSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_saveDictHC( - streamHCPtr, - safeBuffer, - maxDictSize - ) - } + lz4::LZ4_saveDictHC( + streamHCPtr, + safeBuffer, + maxDictSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_initStreamHC( +pub unsafe extern "C" fn csbindgen_LZ4_initStreamHC( buffer: *mut c_void, size: usize ) -> *mut lz4::LZ4_streamHC_t { - unsafe { - return lz4::LZ4_initStreamHC( - buffer, - size - ) - } + lz4::LZ4_initStreamHC( + buffer, + size + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC( +pub unsafe extern "C" fn csbindgen_LZ4_compressHC( source: *const c_char, dest: *mut c_char, inputSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressHC( - source, - dest, - inputSize - ) - } + lz4::LZ4_compressHC( + source, + dest, + inputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC_limitedOutput( +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 { - unsafe { - return lz4::LZ4_compressHC_limitedOutput( - source, - dest, - inputSize, - maxOutputSize - ) - } + lz4::LZ4_compressHC_limitedOutput( + source, + dest, + inputSize, + maxOutputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC2( +pub unsafe extern "C" fn csbindgen_LZ4_compressHC2( source: *const c_char, dest: *mut c_char, inputSize: c_int, compressionLevel: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressHC2( - source, - dest, - inputSize, - compressionLevel - ) - } + lz4::LZ4_compressHC2( + source, + dest, + inputSize, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput( +pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput( source: *const c_char, dest: *mut c_char, inputSize: c_int, @@ -947,37 +833,33 @@ pub extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput( compressionLevel: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressHC2_limitedOutput( - source, - dest, - inputSize, - maxOutputSize, - compressionLevel - ) - } + lz4::LZ4_compressHC2_limitedOutput( + source, + dest, + inputSize, + maxOutputSize, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC_withStateHC( +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 { - unsafe { - return lz4::LZ4_compressHC_withStateHC( - state, - source, - dest, - inputSize - ) - } + lz4::LZ4_compressHC_withStateHC( + state, + source, + dest, + inputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC_limitedOutput_withStateHC( +pub unsafe extern "C" fn csbindgen_LZ4_compressHC_limitedOutput_withStateHC( state: *mut c_void, source: *const c_char, dest: *mut c_char, @@ -985,19 +867,17 @@ pub extern "C" fn csbindgen_LZ4_compressHC_limitedOutput_withStateHC( maxOutputSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressHC_limitedOutput_withStateHC( - state, - source, - dest, - inputSize, - maxOutputSize - ) - } + lz4::LZ4_compressHC_limitedOutput_withStateHC( + state, + source, + dest, + inputSize, + maxOutputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC2_withStateHC( +pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_withStateHC( state: *mut c_void, source: *const c_char, dest: *mut c_char, @@ -1005,19 +885,17 @@ pub extern "C" fn csbindgen_LZ4_compressHC2_withStateHC( compressionLevel: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressHC2_withStateHC( - state, - source, - dest, - inputSize, - compressionLevel - ) - } + lz4::LZ4_compressHC2_withStateHC( + state, + source, + dest, + inputSize, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_withStateHC( +pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_withStateHC( state: *mut c_void, source: *const c_char, dest: *mut c_char, @@ -1026,38 +904,34 @@ pub extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_withStateHC( compressionLevel: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressHC2_limitedOutput_withStateHC( - state, - source, - dest, - inputSize, - maxOutputSize, - compressionLevel - ) - } + lz4::LZ4_compressHC2_limitedOutput_withStateHC( + state, + source, + dest, + inputSize, + maxOutputSize, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC_continue( +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 { - unsafe { - return lz4::LZ4_compressHC_continue( - LZ4_streamHCPtr, - source, - dest, - inputSize - ) - } + lz4::LZ4_compressHC_continue( + LZ4_streamHCPtr, + source, + dest, + inputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC_limitedOutput_continue( +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, @@ -1065,55 +939,47 @@ pub extern "C" fn csbindgen_LZ4_compressHC_limitedOutput_continue( maxOutputSize: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressHC_limitedOutput_continue( - LZ4_streamHCPtr, - source, - dest, - inputSize, - maxOutputSize - ) - } + lz4::LZ4_compressHC_limitedOutput_continue( + LZ4_streamHCPtr, + source, + dest, + inputSize, + maxOutputSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_createHC( +pub unsafe extern "C" fn csbindgen_LZ4_createHC( inputBuffer: *const c_char ) -> *mut c_void { - unsafe { - return lz4::LZ4_createHC( - inputBuffer - ) - } + lz4::LZ4_createHC( + inputBuffer + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_freeHC( +pub unsafe extern "C" fn csbindgen_LZ4_freeHC( LZ4HC_Data: *mut c_void ) -> c_int { - unsafe { - return lz4::LZ4_freeHC( - LZ4HC_Data - ) - } + lz4::LZ4_freeHC( + LZ4HC_Data + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_slideInputBufferHC( +pub unsafe extern "C" fn csbindgen_LZ4_slideInputBufferHC( LZ4HC_Data: *mut c_void ) -> *mut c_char { - unsafe { - return lz4::LZ4_slideInputBufferHC( - LZ4HC_Data - ) - } + lz4::LZ4_slideInputBufferHC( + LZ4HC_Data + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC2_continue( +pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_continue( LZ4HC_Data: *mut c_void, source: *const c_char, dest: *mut c_char, @@ -1121,19 +987,17 @@ pub extern "C" fn csbindgen_LZ4_compressHC2_continue( compressionLevel: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressHC2_continue( - LZ4HC_Data, - source, - dest, - inputSize, - compressionLevel - ) - } + lz4::LZ4_compressHC2_continue( + LZ4HC_Data, + source, + dest, + inputSize, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_continue( +pub unsafe extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_continue( LZ4HC_Data: *mut c_void, source: *const c_char, dest: *mut c_char, @@ -1142,110 +1006,94 @@ pub extern "C" fn csbindgen_LZ4_compressHC2_limitedOutput_continue( compressionLevel: c_int ) -> c_int { - unsafe { - return lz4::LZ4_compressHC2_limitedOutput_continue( - LZ4HC_Data, - source, - dest, - inputSize, - maxOutputSize, - compressionLevel - ) - } + lz4::LZ4_compressHC2_limitedOutput_continue( + LZ4HC_Data, + source, + dest, + inputSize, + maxOutputSize, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_sizeofStreamStateHC( +pub unsafe extern "C" fn csbindgen_LZ4_sizeofStreamStateHC( ) -> c_int { - unsafe { - return lz4::LZ4_sizeofStreamStateHC( + lz4::LZ4_sizeofStreamStateHC( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_resetStreamStateHC( +pub unsafe extern "C" fn csbindgen_LZ4_resetStreamStateHC( state: *mut c_void, inputBuffer: *mut c_char ) -> c_int { - unsafe { - return lz4::LZ4_resetStreamStateHC( - state, - inputBuffer - ) - } + lz4::LZ4_resetStreamStateHC( + state, + inputBuffer + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4_resetStreamHC( +pub unsafe extern "C" fn csbindgen_LZ4_resetStreamHC( streamHCPtr: *mut lz4::LZ4_streamHC_t, compressionLevel: c_int ) { - unsafe { - return lz4::LZ4_resetStreamHC( - streamHCPtr, - compressionLevel - ) - } + lz4::LZ4_resetStreamHC( + streamHCPtr, + compressionLevel + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_isError( +pub unsafe extern "C" fn csbindgen_LZ4F_isError( code: lz4::LZ4F_errorCode_t ) -> c_uint { - unsafe { - return lz4::LZ4F_isError( - code - ) - } + lz4::LZ4F_isError( + code + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_getErrorName( +pub unsafe extern "C" fn csbindgen_LZ4F_getErrorName( code: lz4::LZ4F_errorCode_t ) -> *const c_char { - unsafe { - return lz4::LZ4F_getErrorName( - code - ) - } + lz4::LZ4F_getErrorName( + code + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressionLevel_max( +pub unsafe extern "C" fn csbindgen_LZ4F_compressionLevel_max( ) -> c_int { - unsafe { - return lz4::LZ4F_compressionLevel_max( + lz4::LZ4F_compressionLevel_max( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressFrameBound( +pub unsafe extern "C" fn csbindgen_LZ4F_compressFrameBound( srcSize: usize, preferencesPtr: *const lz4::LZ4F_preferences_t ) -> usize { - unsafe { - return lz4::LZ4F_compressFrameBound( - srcSize, - preferencesPtr - ) - } + lz4::LZ4F_compressFrameBound( + srcSize, + preferencesPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressFrame( +pub unsafe extern "C" fn csbindgen_LZ4F_compressFrame( dstBuffer: *mut c_void, dstCapacity: usize, srcBuffer: *const c_void, @@ -1253,89 +1101,77 @@ pub extern "C" fn csbindgen_LZ4F_compressFrame( preferencesPtr: *const lz4::LZ4F_preferences_t ) -> usize { - unsafe { - return lz4::LZ4F_compressFrame( - dstBuffer, - dstCapacity, - srcBuffer, - srcSize, - preferencesPtr - ) - } + lz4::LZ4F_compressFrame( + dstBuffer, + dstCapacity, + srcBuffer, + srcSize, + preferencesPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_getVersion( +pub unsafe extern "C" fn csbindgen_LZ4F_getVersion( ) -> c_uint { - unsafe { - return lz4::LZ4F_getVersion( + lz4::LZ4F_getVersion( - ) - } + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_createCompressionContext( +pub unsafe extern "C" fn csbindgen_LZ4F_createCompressionContext( cctxPtr: *mut *mut lz4::LZ4F_cctx, version: c_uint ) -> lz4::LZ4F_errorCode_t { - unsafe { - return lz4::LZ4F_createCompressionContext( - cctxPtr, - version - ) - } + lz4::LZ4F_createCompressionContext( + cctxPtr, + version + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_freeCompressionContext( +pub unsafe extern "C" fn csbindgen_LZ4F_freeCompressionContext( cctx: *mut lz4::LZ4F_cctx ) -> lz4::LZ4F_errorCode_t { - unsafe { - return lz4::LZ4F_freeCompressionContext( - cctx - ) - } + lz4::LZ4F_freeCompressionContext( + cctx + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressBegin( +pub unsafe extern "C" fn csbindgen_LZ4F_compressBegin( cctx: *mut lz4::LZ4F_cctx, dstBuffer: *mut c_void, dstCapacity: usize, prefsPtr: *const lz4::LZ4F_preferences_t ) -> usize { - unsafe { - return lz4::LZ4F_compressBegin( - cctx, - dstBuffer, - dstCapacity, - prefsPtr - ) - } + lz4::LZ4F_compressBegin( + cctx, + dstBuffer, + dstCapacity, + prefsPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressBound( +pub unsafe extern "C" fn csbindgen_LZ4F_compressBound( srcSize: usize, prefsPtr: *const lz4::LZ4F_preferences_t ) -> usize { - unsafe { - return lz4::LZ4F_compressBound( - srcSize, - prefsPtr - ) - } + lz4::LZ4F_compressBound( + srcSize, + prefsPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressUpdate( +pub unsafe extern "C" fn csbindgen_LZ4F_compressUpdate( cctx: *mut lz4::LZ4F_cctx, dstBuffer: *mut c_void, dstCapacity: usize, @@ -1344,114 +1180,100 @@ pub extern "C" fn csbindgen_LZ4F_compressUpdate( cOptPtr: *const lz4::LZ4F_compressOptions_t ) -> usize { - unsafe { - return lz4::LZ4F_compressUpdate( - cctx, - dstBuffer, - dstCapacity, - srcBuffer, - srcSize, - cOptPtr - ) - } + lz4::LZ4F_compressUpdate( + cctx, + dstBuffer, + dstCapacity, + srcBuffer, + srcSize, + cOptPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_flush( +pub unsafe extern "C" fn csbindgen_LZ4F_flush( cctx: *mut lz4::LZ4F_cctx, dstBuffer: *mut c_void, dstCapacity: usize, cOptPtr: *const lz4::LZ4F_compressOptions_t ) -> usize { - unsafe { - return lz4::LZ4F_flush( - cctx, - dstBuffer, - dstCapacity, - cOptPtr - ) - } + lz4::LZ4F_flush( + cctx, + dstBuffer, + dstCapacity, + cOptPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressEnd( +pub unsafe extern "C" fn csbindgen_LZ4F_compressEnd( cctx: *mut lz4::LZ4F_cctx, dstBuffer: *mut c_void, dstCapacity: usize, cOptPtr: *const lz4::LZ4F_compressOptions_t ) -> usize { - unsafe { - return lz4::LZ4F_compressEnd( - cctx, - dstBuffer, - dstCapacity, - cOptPtr - ) - } + lz4::LZ4F_compressEnd( + cctx, + dstBuffer, + dstCapacity, + cOptPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_createDecompressionContext( +pub unsafe extern "C" fn csbindgen_LZ4F_createDecompressionContext( dctxPtr: *mut *mut lz4::LZ4F_dctx, version: c_uint ) -> lz4::LZ4F_errorCode_t { - unsafe { - return lz4::LZ4F_createDecompressionContext( - dctxPtr, - version - ) - } + lz4::LZ4F_createDecompressionContext( + dctxPtr, + version + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_freeDecompressionContext( +pub unsafe extern "C" fn csbindgen_LZ4F_freeDecompressionContext( dctx: *mut lz4::LZ4F_dctx ) -> lz4::LZ4F_errorCode_t { - unsafe { - return lz4::LZ4F_freeDecompressionContext( - dctx - ) - } + lz4::LZ4F_freeDecompressionContext( + dctx + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_headerSize( +pub unsafe extern "C" fn csbindgen_LZ4F_headerSize( src: *const c_void, srcSize: usize ) -> usize { - unsafe { - return lz4::LZ4F_headerSize( - src, - srcSize - ) - } + lz4::LZ4F_headerSize( + src, + srcSize + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_getFrameInfo( +pub unsafe extern "C" fn csbindgen_LZ4F_getFrameInfo( dctx: *mut lz4::LZ4F_dctx, frameInfoPtr: *mut lz4::LZ4F_frameInfo_t, srcBuffer: *const c_void, srcSizePtr: *mut usize ) -> usize { - unsafe { - return lz4::LZ4F_getFrameInfo( - dctx, - frameInfoPtr, - srcBuffer, - srcSizePtr - ) - } + lz4::LZ4F_getFrameInfo( + dctx, + frameInfoPtr, + srcBuffer, + srcSizePtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_decompress( +pub unsafe extern "C" fn csbindgen_LZ4F_decompress( dctx: *mut lz4::LZ4F_dctx, dstBuffer: *mut c_void, dstSizePtr: *mut usize, @@ -1460,28 +1282,24 @@ pub extern "C" fn csbindgen_LZ4F_decompress( dOptPtr: *const lz4::LZ4F_decompressOptions_t ) -> usize { - unsafe { - return lz4::LZ4F_decompress( - dctx, - dstBuffer, - dstSizePtr, - srcBuffer, - srcSizePtr, - dOptPtr - ) - } + lz4::LZ4F_decompress( + dctx, + dstBuffer, + dstSizePtr, + srcBuffer, + srcSizePtr, + dOptPtr + ) } #[no_mangle] -pub extern "C" fn csbindgen_LZ4F_resetDecompressionContext( +pub unsafe extern "C" fn csbindgen_LZ4F_resetDecompressionContext( dctx: *mut lz4::LZ4F_dctx ) { - unsafe { - return lz4::LZ4F_resetDecompressionContext( - dctx - ) - } + lz4::LZ4F_resetDecompressionContext( + dctx + ) } \ No newline at end of file diff --git a/csbindgen/src/emitter.rs b/csbindgen/src/emitter.rs index b5f2015..bf79d86 100644 --- a/csbindgen/src/emitter.rs +++ b/csbindgen/src/emitter.rs @@ -39,22 +39,20 @@ pub fn emit_rust_method(list: &Vec, options: &BindgenOptions) -> S let parameter_only_names = item .parameters .iter() - .map(|p| format!(" {}", p.name)) + .map(|p| format!(" {}", p.name)) .collect::>() .join(",\n"); let template = format!( " #[no_mangle] -pub extern \"C\" fn {method_prefix}{method_name}( +pub unsafe extern \"C\" fn {method_prefix}{method_name}( {parameters} ){return_line} {{ - unsafe {{ - return {method_type_path2}{method_name}( + {method_type_path2}{method_name}( {parameter_only_names} - ) - }} + ) }} " ); diff --git a/csbindgen/src/type_meta.rs b/csbindgen/src/type_meta.rs index 071efd1..fc3450d 100644 --- a/csbindgen/src/type_meta.rs +++ b/csbindgen/src/type_meta.rs @@ -111,6 +111,7 @@ impl RustType { fn convert_type_name(type_name: &str, options: &BindgenOptions) -> String { let name = match type_name { // std::os::raw https://doc.rust-lang.org/std/os/raw/index.html + // std::ffi::raw https://doc.rust-lang.org/core/ffi/index.html "c_char" => "byte", "c_schar" => "sbyte", "c_uchar" => "byte", @@ -125,6 +126,7 @@ impl RustType { "c_float" => "float", "c_double" => "double", "c_void" => "void", + "CString" => "sbyte", // rust primitives "i8" => "sbyte", "i16" => "short", diff --git a/dotnet-sandbox/Program.cs b/dotnet-sandbox/Program.cs index 9da0d70..c10caf3 100644 --- a/dotnet-sandbox/Program.cs +++ b/dotnet-sandbox/Program.cs @@ -1,14 +1,28 @@ -// See https://aka.ms/new-console-template for more information + + +// See https://aka.ms/new-console-template for more information //using Csbindgen; using CsBindgen; +using System.Buffers.Text; using System.Reflection; using System.Runtime.CompilerServices; using System.Runtime.InteropServices; +using System.Text; + + + unsafe { var a = false; var b = false; var c = false; + Console.WriteLine(Encoding.Default); + + + var p = LibRust.unsafe_return_string(); + + var s = Encoding.UTF8.GetString(p, 5); + Console.WriteLine(s); @@ -33,4 +47,12 @@ public static unsafe partial class LibraryImportNativeMethods public static partial bool my_bool([MarshalAs(UnmanagedType.U1)] bool x, [MarshalAs(UnmanagedType.U1)] bool y, [MarshalAs(UnmanagedType.U1)] bool z, bool* xr, bool* yr, bool* zr); + + [LibraryImport(__DllName)] + public static partial void foo(Foo f); +} + +public struct Foo +{ + [MarshalAs(UnmanagedType.U1)] public bool A; } \ No newline at end of file diff --git a/dotnet-sandbox/asm.cs b/dotnet-sandbox/asm.cs new file mode 100644 index 0000000..512414e --- /dev/null +++ b/dotnet-sandbox/asm.cs @@ -0,0 +1,3 @@ +using System.Runtime.CompilerServices; + +[assembly:DisableRuntimeMarshalling()] \ No newline at end of file diff --git a/dotnet-sandbox/method_call.cs b/dotnet-sandbox/method_call.cs index b5140e2..d165610 100644 --- a/dotnet-sandbox/method_call.cs +++ b/dotnet-sandbox/method_call.cs @@ -18,6 +18,15 @@ namespace CsBindgen [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); + [DllImport(__DllName, EntryPoint = "unsafe_return_string", CallingConvention = CallingConvention.Cdecl)] + public static extern byte* unsafe_return_string(); + + [DllImport(__DllName, EntryPoint = "unsafe_return_string2", CallingConvention = CallingConvention.Cdecl)] + public static extern byte* unsafe_return_string2(); + + [DllImport(__DllName, EntryPoint = "unsafe_destroy_string", CallingConvention = CallingConvention.Cdecl)] + public static extern void unsafe_destroy_string(String* s); + }