From 4189fd72fd4c6d9997e365bd97e02ddd7e3b1151 Mon Sep 17 00:00:00 2001 From: neuecc Date: Mon, 27 Feb 2023 19:44:03 +0900 Subject: [PATCH] refactoring one --- csbindgen-tests/Cargo.toml | 5 + csbindgen-tests/build.rs | 20 +- csbindgen-tests/src/__main.rs | 23 + csbindgen-tests/src/ffi.rs | 1040 +------------------------------- csbindgen-tests/src/lz4/mod.rs | 1021 ------------------------------- csbindgen-tests/src/main.rs | 13 - csbindgen/src/builder.rs | 128 ++++ csbindgen/src/emitter.rs | 186 ++++++ csbindgen/src/lib.rs | 571 +----------------- csbindgen/src/parser.rs | 203 +++++++ csbindgen/src/type_meta.rs | 146 +++++ csbindgen/src/util.rs | 10 + dotnet-sandbox/bindgen.cs | 322 ---------- 13 files changed, 729 insertions(+), 2959 deletions(-) create mode 100644 csbindgen-tests/src/__main.rs delete mode 100644 csbindgen-tests/src/main.rs create mode 100644 csbindgen/src/builder.rs create mode 100644 csbindgen/src/emitter.rs create mode 100644 csbindgen/src/parser.rs create mode 100644 csbindgen/src/type_meta.rs create mode 100644 csbindgen/src/util.rs diff --git a/csbindgen-tests/Cargo.toml b/csbindgen-tests/Cargo.toml index cb3276c..a701e9c 100644 --- a/csbindgen-tests/Cargo.toml +++ b/csbindgen-tests/Cargo.toml @@ -3,8 +3,13 @@ name = "csbindgen-tests" version = "0.1.0" edition = "2021" +# [[bin]] +# name = "csbindgen-test-app" +# path = "src/main.rs" + [lib] crate-type = ["cdylib"] +path = "src/lib.rs" [dependencies] csbindgen = { path = "../csbindgen" } diff --git a/csbindgen-tests/build.rs b/csbindgen-tests/build.rs index 3481a7c..34d69bd 100644 --- a/csbindgen-tests/build.rs +++ b/csbindgen-tests/build.rs @@ -1,10 +1,9 @@ -#![feature(core_intrinsics)] fn main() { let bindings = bindgen::Builder::default() .header("c/lz4/lz4.h") - .header("c/lz4/lz4hc.h") - .header("c/lz4/lz4frame.h") - .header("c/lz4/xxhash.h") + //.header("c/lz4/lz4hc.h") + //.header("c/lz4/lz4frame.h") + //.header("c/lz4/xxhash.h") .generate() .expect("Unable to generate bindings"); @@ -12,12 +11,11 @@ fn main() { .write_to_file("src/lz4/mod.rs") .expect("Couldn't write bindings!"); - cc::Build::new().file("c/lz4/lz4.c").compile("lz4"); + cc::Build::new().file("c/lz4/lz4.c").compile("csharp_lz4"); - // TODO:write test - csbindgen::run( - "src/lz4/mod.rs", - "src/ffi.rs", - "../dotnet-sandbox/bindgen.cs", - ) + csbindgen::Builder::new() + .input_bindgen_file("src/lz4/mod.cs") + .rust_method_prefix("csbindgen_") + .generate_to_file("src/ffi.rs", "../dotnet-sandbox/bindgen.cs") + .unwrap(); } diff --git a/csbindgen-tests/src/__main.rs b/csbindgen-tests/src/__main.rs new file mode 100644 index 0000000..c758c80 --- /dev/null +++ b/csbindgen-tests/src/__main.rs @@ -0,0 +1,23 @@ +use std::env; + +#[allow(dead_code)] +#[allow(non_snake_case)] +#[allow(non_camel_case_types)] +#[allow(non_upper_case_globals)] +mod lz4; + +fn main() { + let path = env::current_dir().unwrap(); + println!("starting dir: {}", path.display()); + + unsafe { + let num = lz4::LZ4_versionNumber(); + println!("lz4 num: {}", num); + } + + csbindgen::run( + "csbindgen-tests/src/lz4/mod.rs", + "csbindgen-tests/src/ffi.rs", + "dotnet-sandbox/bindgen.cs", + ); +} diff --git a/csbindgen-tests/src/ffi.rs b/csbindgen-tests/src/ffi.rs index 4f6b876..4e5f43d 100644 --- a/csbindgen-tests/src/ffi.rs +++ b/csbindgen-tests/src/ffi.rs @@ -1,3 +1,5 @@ +// auto-generated via csbindgen + #[allow(unused)] use ::std::os::raw::*; use super::lz4; @@ -704,1041 +706,3 @@ pub extern "C" fn csbindgen_LZ4_resetStream( } } -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compress_HC( - src, - dst, - srcSize, - dstCapacity, - compressionLevel, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_sizeofStateHC( -) -> c_int -{ - unsafe { - return lz4::LZ4_sizeofStateHC( - ) - } -} - -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compress_HC_extStateHC( - stateHC, - src, - dst, - srcSize, - maxDstSize, - compressionLevel, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_HC_destSize( - stateHC: *mut c_void, - src: *const c_char, - dst: *mut c_char, - srcSizePtr: *mut c_int, - targetDstSize: c_int, - compressionLevel: c_int, -) -> c_int -{ - unsafe { - return lz4::LZ4_compress_HC_destSize( - stateHC, - src, - dst, - srcSizePtr, - targetDstSize, - compressionLevel, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_createStreamHC( -) -> *mut lz4::LZ4_streamHC_t -{ - unsafe { - return lz4::LZ4_createStreamHC( - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_freeStreamHC( - streamHCPtr: *mut lz4::LZ4_streamHC_t, -) -> c_int -{ - unsafe { - return lz4::LZ4_freeStreamHC( - streamHCPtr, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_resetStreamHC_fast( - streamHCPtr: *mut lz4::LZ4_streamHC_t, - compressionLevel: c_int, -) -{ - unsafe { - return lz4::LZ4_resetStreamHC_fast( - streamHCPtr, - compressionLevel, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compress_HC_continue( - streamHCPtr, - src, - dst, - srcSize, - maxDstSize, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_compress_HC_continue_destSize( - LZ4_streamHCPtr: *mut lz4::LZ4_streamHC_t, - src: *const c_char, - dst: *mut c_char, - srcSizePtr: *mut c_int, - targetDstSize: c_int, -) -> c_int -{ - unsafe { - return lz4::LZ4_compress_HC_continue_destSize( - LZ4_streamHCPtr, - src, - dst, - srcSizePtr, - targetDstSize, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_initStreamHC( - buffer: *mut c_void, - size: usize, -) -> *mut lz4::LZ4_streamHC_t -{ - unsafe { - return lz4::LZ4_initStreamHC( - buffer, - size, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compressHC2_limitedOutput( - source, - dest, - inputSize, - maxOutputSize, - compressionLevel, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compressHC_limitedOutput_withStateHC( - state, - source, - dest, - inputSize, - maxOutputSize, - ) - } -} - -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compressHC2_withStateHC( - state, - source, - dest, - inputSize, - compressionLevel, - ) - } -} - -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compressHC2_limitedOutput_withStateHC( - state, - source, - dest, - inputSize, - maxOutputSize, - compressionLevel, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compressHC_limitedOutput_continue( - LZ4_streamHCPtr, - source, - dest, - inputSize, - maxOutputSize, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_createHC( - inputBuffer: *const c_char, -) -> *mut c_void -{ - unsafe { - return lz4::LZ4_createHC( - inputBuffer, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_freeHC( - LZ4HC_Data: *mut c_void, -) -> c_int -{ - unsafe { - return lz4::LZ4_freeHC( - LZ4HC_Data, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_slideInputBufferHC( - LZ4HC_Data: *mut c_void, -) -> *mut c_char -{ - unsafe { - return lz4::LZ4_slideInputBufferHC( - LZ4HC_Data, - ) - } -} - -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compressHC2_continue( - LZ4HC_Data, - source, - dest, - inputSize, - compressionLevel, - ) - } -} - -#[no_mangle] -pub 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 -{ - unsafe { - return lz4::LZ4_compressHC2_limitedOutput_continue( - LZ4HC_Data, - source, - dest, - inputSize, - maxOutputSize, - compressionLevel, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_sizeofStreamStateHC( -) -> c_int -{ - unsafe { - return lz4::LZ4_sizeofStreamStateHC( - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_resetStreamStateHC( - state: *mut c_void, - inputBuffer: *mut c_char, -) -> c_int -{ - unsafe { - return lz4::LZ4_resetStreamStateHC( - state, - inputBuffer, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4_resetStreamHC( - streamHCPtr: *mut lz4::LZ4_streamHC_t, - compressionLevel: c_int, -) -{ - unsafe { - return lz4::LZ4_resetStreamHC( - streamHCPtr, - compressionLevel, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_isError( - code: lz4::LZ4F_errorCode_t, -) -> c_uint -{ - unsafe { - return lz4::LZ4F_isError( - code, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_getErrorName( - code: lz4::LZ4F_errorCode_t, -) -> *const c_char -{ - unsafe { - return lz4::LZ4F_getErrorName( - code, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressionLevel_max( -) -> c_int -{ - unsafe { - return lz4::LZ4F_compressionLevel_max( - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressFrameBound( - srcSize: usize, - preferencesPtr: *const lz4::LZ4F_preferences_t, -) -> usize -{ - unsafe { - return lz4::LZ4F_compressFrameBound( - srcSize, - preferencesPtr, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressFrame( - dstBuffer: *mut c_void, - dstCapacity: usize, - srcBuffer: *const c_void, - srcSize: usize, - preferencesPtr: *const lz4::LZ4F_preferences_t, -) -> usize -{ - unsafe { - return lz4::LZ4F_compressFrame( - dstBuffer, - dstCapacity, - srcBuffer, - srcSize, - preferencesPtr, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_getVersion( -) -> c_uint -{ - unsafe { - return lz4::LZ4F_getVersion( - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_freeCompressionContext( - cctx: *mut lz4::LZ4F_cctx, -) -> lz4::LZ4F_errorCode_t -{ - unsafe { - return lz4::LZ4F_freeCompressionContext( - cctx, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressBound( - srcSize: usize, - prefsPtr: *const lz4::LZ4F_preferences_t, -) -> usize -{ - unsafe { - return lz4::LZ4F_compressBound( - srcSize, - prefsPtr, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_compressUpdate( - cctx: *mut lz4::LZ4F_cctx, - dstBuffer: *mut c_void, - dstCapacity: usize, - srcBuffer: *const c_void, - srcSize: usize, - cOptPtr: *const lz4::LZ4F_compressOptions_t, -) -> usize -{ - unsafe { - return lz4::LZ4F_compressUpdate( - cctx, - dstBuffer, - dstCapacity, - srcBuffer, - srcSize, - cOptPtr, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_freeDecompressionContext( - dctx: *mut lz4::LZ4F_dctx, -) -> lz4::LZ4F_errorCode_t -{ - unsafe { - return lz4::LZ4F_freeDecompressionContext( - dctx, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_headerSize( - src: *const c_void, - srcSize: usize, -) -> usize -{ - unsafe { - return lz4::LZ4F_headerSize( - src, - srcSize, - ) - } -} - -#[no_mangle] -pub 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, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_decompress( - dctx: *mut lz4::LZ4F_dctx, - dstBuffer: *mut c_void, - dstSizePtr: *mut usize, - srcBuffer: *const c_void, - srcSizePtr: *mut usize, - dOptPtr: *const lz4::LZ4F_decompressOptions_t, -) -> usize -{ - unsafe { - return lz4::LZ4F_decompress( - dctx, - dstBuffer, - dstSizePtr, - srcBuffer, - srcSizePtr, - dOptPtr, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_LZ4F_resetDecompressionContext( - dctx: *mut lz4::LZ4F_dctx, -) -{ - unsafe { - return lz4::LZ4F_resetDecompressionContext( - dctx, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH_versionNumber( -) -> c_uint -{ - unsafe { - return lz4::XXH_versionNumber( - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH32( - input: *const c_void, - length: usize, - seed: c_uint, -) -> lz4::XXH32_hash_t -{ - unsafe { - return lz4::XXH32( - input, - length, - seed, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH32_createState( -) -> *mut lz4::XXH32_state_t -{ - unsafe { - return lz4::XXH32_createState( - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH32_freeState( - statePtr: *mut lz4::XXH32_state_t, -) -> lz4::XXH_errorcode -{ - unsafe { - return lz4::XXH32_freeState( - statePtr, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH32_copyState( - dst_state: *mut lz4::XXH32_state_t, - src_state: *const lz4::XXH32_state_t, -) -{ - unsafe { - return lz4::XXH32_copyState( - dst_state, - src_state, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH32_reset( - statePtr: *mut lz4::XXH32_state_t, - seed: c_uint, -) -> lz4::XXH_errorcode -{ - unsafe { - return lz4::XXH32_reset( - statePtr, - seed, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH32_update( - statePtr: *mut lz4::XXH32_state_t, - input: *const c_void, - length: usize, -) -> lz4::XXH_errorcode -{ - unsafe { - return lz4::XXH32_update( - statePtr, - input, - length, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH32_digest( - statePtr: *const lz4::XXH32_state_t, -) -> lz4::XXH32_hash_t -{ - unsafe { - return lz4::XXH32_digest( - statePtr, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH32_canonicalFromHash( - dst: *mut lz4::XXH32_canonical_t, - hash: lz4::XXH32_hash_t, -) -{ - unsafe { - return lz4::XXH32_canonicalFromHash( - dst, - hash, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH32_hashFromCanonical( - src: *const lz4::XXH32_canonical_t, -) -> lz4::XXH32_hash_t -{ - unsafe { - return lz4::XXH32_hashFromCanonical( - src, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH64( - input: *const c_void, - length: usize, - seed: c_ulonglong, -) -> lz4::XXH64_hash_t -{ - unsafe { - return lz4::XXH64( - input, - length, - seed, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH64_createState( -) -> *mut lz4::XXH64_state_t -{ - unsafe { - return lz4::XXH64_createState( - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH64_freeState( - statePtr: *mut lz4::XXH64_state_t, -) -> lz4::XXH_errorcode -{ - unsafe { - return lz4::XXH64_freeState( - statePtr, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH64_copyState( - dst_state: *mut lz4::XXH64_state_t, - src_state: *const lz4::XXH64_state_t, -) -{ - unsafe { - return lz4::XXH64_copyState( - dst_state, - src_state, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH64_reset( - statePtr: *mut lz4::XXH64_state_t, - seed: c_ulonglong, -) -> lz4::XXH_errorcode -{ - unsafe { - return lz4::XXH64_reset( - statePtr, - seed, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH64_update( - statePtr: *mut lz4::XXH64_state_t, - input: *const c_void, - length: usize, -) -> lz4::XXH_errorcode -{ - unsafe { - return lz4::XXH64_update( - statePtr, - input, - length, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH64_digest( - statePtr: *const lz4::XXH64_state_t, -) -> lz4::XXH64_hash_t -{ - unsafe { - return lz4::XXH64_digest( - statePtr, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH64_canonicalFromHash( - dst: *mut lz4::XXH64_canonical_t, - hash: lz4::XXH64_hash_t, -) -{ - unsafe { - return lz4::XXH64_canonicalFromHash( - dst, - hash, - ) - } -} - -#[no_mangle] -pub extern "C" fn csbindgen_XXH64_hashFromCanonical( - src: *const lz4::XXH64_canonical_t, -) -> lz4::XXH64_hash_t -{ - unsafe { - return lz4::XXH64_hashFromCanonical( - src, - ) - } -} - diff --git a/csbindgen-tests/src/lz4/mod.rs b/csbindgen-tests/src/lz4/mod.rs index 3fbf825..72666da 100644 --- a/csbindgen-tests/src/lz4/mod.rs +++ b/csbindgen-tests/src/lz4/mod.rs @@ -31,31 +31,6 @@ pub const WINT_MIN: u32 = 0; pub const WINT_MAX: u32 = 65535; pub const LZ4_STREAM_MINSIZE: u32 = 16416; pub const LZ4_STREAMDECODE_MINSIZE: u32 = 32; -pub const LZ4HC_CLEVEL_MIN: u32 = 3; -pub const LZ4HC_CLEVEL_DEFAULT: u32 = 9; -pub const LZ4HC_CLEVEL_OPT_MIN: u32 = 10; -pub const LZ4HC_CLEVEL_MAX: u32 = 12; -pub const LZ4HC_DICTIONARY_LOGSIZE: u32 = 16; -pub const LZ4HC_MAXD: u32 = 65536; -pub const LZ4HC_MAXD_MASK: u32 = 65535; -pub const LZ4HC_HASH_LOG: u32 = 15; -pub const LZ4HC_HASHTABLESIZE: u32 = 32768; -pub const LZ4HC_HASH_MASK: u32 = 32767; -pub const LZ4_STREAMHC_MINSIZE: u32 = 262200; -pub const LZ4F_VERSION: u32 = 100; -pub const LZ4F_HEADER_SIZE_MIN: u32 = 7; -pub const LZ4F_HEADER_SIZE_MAX: u32 = 19; -pub const LZ4F_BLOCK_HEADER_SIZE: u32 = 4; -pub const LZ4F_BLOCK_CHECKSUM_SIZE: u32 = 4; -pub const LZ4F_CONTENT_CHECKSUM_SIZE: u32 = 4; -pub const LZ4F_MAGICNUMBER: u32 = 407708164; -pub const LZ4F_MAGIC_SKIPPABLE_START: u32 = 407710288; -pub const LZ4F_MIN_SIZE_TO_KNOW_HEADER_LENGTH: u32 = 5; -pub const XXHASH_H_5627135585666179: u32 = 1; -pub const XXH_VERSION_MAJOR: u32 = 0; -pub const XXH_VERSION_MINOR: u32 = 6; -pub const XXH_VERSION_RELEASE: u32 = 5; -pub const XXH_VERSION_NUMBER: u32 = 605; pub type wchar_t = ::std::os::raw::c_ushort; pub type max_align_t = f64; extern "C" { @@ -621,999 +596,3 @@ extern "C" { #[doc = " LZ4_resetStream() :\n An LZ4_stream_t structure must be initialized at least once.\n This is done with LZ4_initStream(), or LZ4_resetStream().\n Consider switching to LZ4_initStream(),\n invoking LZ4_resetStream() will trigger deprecation warnings in the future."] pub fn LZ4_resetStream(streamPtr: *mut LZ4_stream_t); } -extern "C" { - #[doc = " LZ4_compress_HC() :\n Compress data from `src` into `dst`, using the powerful but slower \"HC\" algorithm.\n `dst` must be already allocated.\n Compression is guaranteed to succeed if `dstCapacity >= LZ4_compressBound(srcSize)` (see \"lz4.h\")\n Max supported `srcSize` value is LZ4_MAX_INPUT_SIZE (see \"lz4.h\")\n `compressionLevel` : any value between 1 and LZ4HC_CLEVEL_MAX will work.\n Values > LZ4HC_CLEVEL_MAX behave the same as LZ4HC_CLEVEL_MAX.\n @return : the number of bytes written into 'dst'\n or 0 if compression fails."] - pub fn LZ4_compress_HC( - src: *const ::std::os::raw::c_char, - dst: *mut ::std::os::raw::c_char, - srcSize: ::std::os::raw::c_int, - dstCapacity: ::std::os::raw::c_int, - compressionLevel: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - #[doc = " LZ4_compress_HC_extStateHC() :\n Same as LZ4_compress_HC(), but using an externally allocated memory segment for `state`.\n `state` size is provided by LZ4_sizeofStateHC().\n Memory segment must be aligned on 8-bytes boundaries (which a normal malloc() should do properly)."] - pub fn LZ4_sizeofStateHC() -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compress_HC_extStateHC( - stateHC: *mut ::std::os::raw::c_void, - src: *const ::std::os::raw::c_char, - dst: *mut ::std::os::raw::c_char, - srcSize: ::std::os::raw::c_int, - maxDstSize: ::std::os::raw::c_int, - compressionLevel: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - #[doc = " LZ4_compress_HC_destSize() : v1.9.0+\n Will compress as much data as possible from `src`\n to fit into `targetDstSize` budget.\n Result is provided in 2 parts :\n @return : the number of bytes written into 'dst' (necessarily <= targetDstSize)\n or 0 if compression fails.\n `srcSizePtr` : on success, *srcSizePtr is updated to indicate how much bytes were read from `src`"] - pub fn LZ4_compress_HC_destSize( - stateHC: *mut ::std::os::raw::c_void, - src: *const ::std::os::raw::c_char, - dst: *mut ::std::os::raw::c_char, - srcSizePtr: *mut ::std::os::raw::c_int, - targetDstSize: ::std::os::raw::c_int, - compressionLevel: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -pub type LZ4_streamHC_t = LZ4_streamHC_u; -extern "C" { - #[doc = " LZ4_createStreamHC() and LZ4_freeStreamHC() :\n These functions create and release memory for LZ4 HC streaming state.\n Newly created states are automatically initialized.\n A same state can be used multiple times consecutively,\n starting with LZ4_resetStreamHC_fast() to start a new stream of blocks."] - pub fn LZ4_createStreamHC() -> *mut LZ4_streamHC_t; -} -extern "C" { - pub fn LZ4_freeStreamHC(streamHCPtr: *mut LZ4_streamHC_t) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_resetStreamHC_fast( - streamHCPtr: *mut LZ4_streamHC_t, - compressionLevel: ::std::os::raw::c_int, - ); -} -extern "C" { - pub fn LZ4_loadDictHC( - streamHCPtr: *mut LZ4_streamHC_t, - dictionary: *const ::std::os::raw::c_char, - dictSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compress_HC_continue( - streamHCPtr: *mut LZ4_streamHC_t, - src: *const ::std::os::raw::c_char, - dst: *mut ::std::os::raw::c_char, - srcSize: ::std::os::raw::c_int, - maxDstSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - #[doc = " LZ4_compress_HC_continue_destSize() : v1.9.0+\n Similar to LZ4_compress_HC_continue(),\n but will read as much data as possible from `src`\n to fit into `targetDstSize` budget.\n Result is provided into 2 parts :\n @return : the number of bytes written into 'dst' (necessarily <= targetDstSize)\n or 0 if compression fails.\n `srcSizePtr` : on success, *srcSizePtr will be updated to indicate how much bytes were read from `src`.\n Note that this function may not consume the entire input."] - pub fn LZ4_compress_HC_continue_destSize( - LZ4_streamHCPtr: *mut LZ4_streamHC_t, - src: *const ::std::os::raw::c_char, - dst: *mut ::std::os::raw::c_char, - srcSizePtr: *mut ::std::os::raw::c_int, - targetDstSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_saveDictHC( - streamHCPtr: *mut LZ4_streamHC_t, - safeBuffer: *mut ::std::os::raw::c_char, - maxDictSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct LZ4HC_CCtx_internal { - pub hashTable: [LZ4_u32; 32768usize], - pub chainTable: [LZ4_u16; 65536usize], - pub end: *const LZ4_byte, - pub prefixStart: *const LZ4_byte, - pub dictStart: *const LZ4_byte, - pub dictLimit: LZ4_u32, - pub lowLimit: LZ4_u32, - pub nextToUpdate: LZ4_u32, - pub compressionLevel: ::std::os::raw::c_short, - pub favorDecSpeed: LZ4_i8, - pub dirty: LZ4_i8, - pub dictCtx: *const LZ4HC_CCtx_internal, -} -#[test] -fn bindgen_test_layout_LZ4HC_CCtx_internal() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 262192usize, - concat!("Size of: ", stringify!(LZ4HC_CCtx_internal)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(LZ4HC_CCtx_internal)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).hashTable) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(hashTable) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).chainTable) as usize - ptr as usize }, - 131072usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(chainTable) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).end) as usize - ptr as usize }, - 262144usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(end) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).prefixStart) as usize - ptr as usize }, - 262152usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(prefixStart) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dictStart) as usize - ptr as usize }, - 262160usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(dictStart) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dictLimit) as usize - ptr as usize }, - 262168usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(dictLimit) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).lowLimit) as usize - ptr as usize }, - 262172usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(lowLimit) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).nextToUpdate) as usize - ptr as usize }, - 262176usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(nextToUpdate) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).compressionLevel) as usize - ptr as usize }, - 262180usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(compressionLevel) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).favorDecSpeed) as usize - ptr as usize }, - 262182usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(favorDecSpeed) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dirty) as usize - ptr as usize }, - 262183usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(dirty) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dictCtx) as usize - ptr as usize }, - 262184usize, - concat!( - "Offset of field: ", - stringify!(LZ4HC_CCtx_internal), - "::", - stringify!(dictCtx) - ) - ); -} -#[repr(C)] -#[derive(Copy, Clone)] -pub union LZ4_streamHC_u { - pub minStateSize: [::std::os::raw::c_char; 262200usize], - pub internal_donotuse: LZ4HC_CCtx_internal, -} -#[test] -fn bindgen_test_layout_LZ4_streamHC_u() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 262200usize, - concat!("Size of: ", stringify!(LZ4_streamHC_u)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(LZ4_streamHC_u)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).minStateSize) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LZ4_streamHC_u), - "::", - stringify!(minStateSize) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).internal_donotuse) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LZ4_streamHC_u), - "::", - stringify!(internal_donotuse) - ) - ); -} -extern "C" { - pub fn LZ4_initStreamHC( - buffer: *mut ::std::os::raw::c_void, - size: usize, - ) -> *mut LZ4_streamHC_t; -} -extern "C" { - pub fn LZ4_compressHC( - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC_limitedOutput( - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - maxOutputSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC2( - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - compressionLevel: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC2_limitedOutput( - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - maxOutputSize: ::std::os::raw::c_int, - compressionLevel: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC_withStateHC( - state: *mut ::std::os::raw::c_void, - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC_limitedOutput_withStateHC( - state: *mut ::std::os::raw::c_void, - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - maxOutputSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC2_withStateHC( - state: *mut ::std::os::raw::c_void, - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - compressionLevel: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC2_limitedOutput_withStateHC( - state: *mut ::std::os::raw::c_void, - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - maxOutputSize: ::std::os::raw::c_int, - compressionLevel: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC_continue( - LZ4_streamHCPtr: *mut LZ4_streamHC_t, - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC_limitedOutput_continue( - LZ4_streamHCPtr: *mut LZ4_streamHC_t, - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - maxOutputSize: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_createHC(inputBuffer: *const ::std::os::raw::c_char) -> *mut ::std::os::raw::c_void; -} -extern "C" { - pub fn LZ4_freeHC(LZ4HC_Data: *mut ::std::os::raw::c_void) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_slideInputBufferHC( - LZ4HC_Data: *mut ::std::os::raw::c_void, - ) -> *mut ::std::os::raw::c_char; -} -extern "C" { - pub fn LZ4_compressHC2_continue( - LZ4HC_Data: *mut ::std::os::raw::c_void, - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - compressionLevel: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_compressHC2_limitedOutput_continue( - LZ4HC_Data: *mut ::std::os::raw::c_void, - source: *const ::std::os::raw::c_char, - dest: *mut ::std::os::raw::c_char, - inputSize: ::std::os::raw::c_int, - maxOutputSize: ::std::os::raw::c_int, - compressionLevel: ::std::os::raw::c_int, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_sizeofStreamStateHC() -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_resetStreamStateHC( - state: *mut ::std::os::raw::c_void, - inputBuffer: *mut ::std::os::raw::c_char, - ) -> ::std::os::raw::c_int; -} -extern "C" { - pub fn LZ4_resetStreamHC( - streamHCPtr: *mut LZ4_streamHC_t, - compressionLevel: ::std::os::raw::c_int, - ); -} -pub type LZ4F_errorCode_t = usize; -extern "C" { - pub fn LZ4F_isError(code: LZ4F_errorCode_t) -> ::std::os::raw::c_uint; -} -extern "C" { - pub fn LZ4F_getErrorName(code: LZ4F_errorCode_t) -> *const ::std::os::raw::c_char; -} -pub const LZ4F_blockSizeID_t_LZ4F_default: LZ4F_blockSizeID_t = 0; -pub const LZ4F_blockSizeID_t_LZ4F_max64KB: LZ4F_blockSizeID_t = 4; -pub const LZ4F_blockSizeID_t_LZ4F_max256KB: LZ4F_blockSizeID_t = 5; -pub const LZ4F_blockSizeID_t_LZ4F_max1MB: LZ4F_blockSizeID_t = 6; -pub const LZ4F_blockSizeID_t_LZ4F_max4MB: LZ4F_blockSizeID_t = 7; -pub type LZ4F_blockSizeID_t = ::std::os::raw::c_int; -pub const LZ4F_blockMode_t_LZ4F_blockLinked: LZ4F_blockMode_t = 0; -pub const LZ4F_blockMode_t_LZ4F_blockIndependent: LZ4F_blockMode_t = 1; -pub type LZ4F_blockMode_t = ::std::os::raw::c_int; -pub const LZ4F_contentChecksum_t_LZ4F_noContentChecksum: LZ4F_contentChecksum_t = 0; -pub const LZ4F_contentChecksum_t_LZ4F_contentChecksumEnabled: LZ4F_contentChecksum_t = 1; -pub type LZ4F_contentChecksum_t = ::std::os::raw::c_int; -pub const LZ4F_blockChecksum_t_LZ4F_noBlockChecksum: LZ4F_blockChecksum_t = 0; -pub const LZ4F_blockChecksum_t_LZ4F_blockChecksumEnabled: LZ4F_blockChecksum_t = 1; -pub type LZ4F_blockChecksum_t = ::std::os::raw::c_int; -pub const LZ4F_frameType_t_LZ4F_frame: LZ4F_frameType_t = 0; -pub const LZ4F_frameType_t_LZ4F_skippableFrame: LZ4F_frameType_t = 1; -pub type LZ4F_frameType_t = ::std::os::raw::c_int; -#[doc = " LZ4F_frameInfo_t :\n makes it possible to set or read frame parameters.\n Structure must be first init to 0, using memset() or LZ4F_INIT_FRAMEINFO,\n setting all parameters to default.\n It's then possible to update selectively some parameters"] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct LZ4F_frameInfo_t { - pub blockSizeID: LZ4F_blockSizeID_t, - pub blockMode: LZ4F_blockMode_t, - pub contentChecksumFlag: LZ4F_contentChecksum_t, - pub frameType: LZ4F_frameType_t, - pub contentSize: ::std::os::raw::c_ulonglong, - pub dictID: ::std::os::raw::c_uint, - pub blockChecksumFlag: LZ4F_blockChecksum_t, -} -#[test] -fn bindgen_test_layout_LZ4F_frameInfo_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 32usize, - concat!("Size of: ", stringify!(LZ4F_frameInfo_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(LZ4F_frameInfo_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).blockSizeID) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_frameInfo_t), - "::", - stringify!(blockSizeID) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).blockMode) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_frameInfo_t), - "::", - stringify!(blockMode) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).contentChecksumFlag) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_frameInfo_t), - "::", - stringify!(contentChecksumFlag) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).frameType) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_frameInfo_t), - "::", - stringify!(frameType) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).contentSize) as usize - ptr as usize }, - 16usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_frameInfo_t), - "::", - stringify!(contentSize) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).dictID) as usize - ptr as usize }, - 24usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_frameInfo_t), - "::", - stringify!(dictID) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).blockChecksumFlag) as usize - ptr as usize }, - 28usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_frameInfo_t), - "::", - stringify!(blockChecksumFlag) - ) - ); -} -#[doc = " LZ4F_preferences_t :\n makes it possible to supply advanced compression instructions to streaming interface.\n Structure must be first init to 0, using memset() or LZ4F_INIT_PREFERENCES,\n setting all parameters to default.\n All reserved fields must be set to zero."] -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct LZ4F_preferences_t { - pub frameInfo: LZ4F_frameInfo_t, - pub compressionLevel: ::std::os::raw::c_int, - pub autoFlush: ::std::os::raw::c_uint, - pub favorDecSpeed: ::std::os::raw::c_uint, - pub reserved: [::std::os::raw::c_uint; 3usize], -} -#[test] -fn bindgen_test_layout_LZ4F_preferences_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 56usize, - concat!("Size of: ", stringify!(LZ4F_preferences_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(LZ4F_preferences_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).frameInfo) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_preferences_t), - "::", - stringify!(frameInfo) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).compressionLevel) as usize - ptr as usize }, - 32usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_preferences_t), - "::", - stringify!(compressionLevel) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).autoFlush) as usize - ptr as usize }, - 36usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_preferences_t), - "::", - stringify!(autoFlush) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).favorDecSpeed) as usize - ptr as usize }, - 40usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_preferences_t), - "::", - stringify!(favorDecSpeed) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).reserved) as usize - ptr as usize }, - 44usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_preferences_t), - "::", - stringify!(reserved) - ) - ); -} -extern "C" { - pub fn LZ4F_compressionLevel_max() -> ::std::os::raw::c_int; -} -extern "C" { - #[doc = " LZ4F_compressFrameBound() :\n Returns the maximum possible compressed size with LZ4F_compressFrame() given srcSize and preferences.\n `preferencesPtr` is optional. It can be replaced by NULL, in which case, the function will assume default preferences.\n Note : this result is only usable with LZ4F_compressFrame().\n It may also be relevant to LZ4F_compressUpdate() _only if_ no flush() operation is ever performed."] - pub fn LZ4F_compressFrameBound( - srcSize: usize, - preferencesPtr: *const LZ4F_preferences_t, - ) -> usize; -} -extern "C" { - #[doc = " LZ4F_compressFrame() :\n Compress srcBuffer content into an LZ4-compressed frame.\n It's a one shot operation, all input content is consumed, and all output is generated.\n\n Note : it's a stateless operation (no LZ4F_cctx state needed).\n In order to reduce load on the allocator, LZ4F_compressFrame(), by default,\n uses the stack to allocate space for the compression state and some table.\n If this usage of the stack is too much for your application,\n consider compiling `lz4frame.c` with compile-time macro LZ4F_HEAPMODE set to 1 instead.\n All state allocations will use the Heap.\n It also means each invocation of LZ4F_compressFrame() will trigger several internal alloc/free invocations.\n\n @dstCapacity MUST be >= LZ4F_compressFrameBound(srcSize, preferencesPtr).\n @preferencesPtr is optional : one can provide NULL, in which case all preferences are set to default.\n @return : number of bytes written into dstBuffer.\n or an error code if it fails (can be tested using LZ4F_isError())"] - pub fn LZ4F_compressFrame( - dstBuffer: *mut ::std::os::raw::c_void, - dstCapacity: usize, - srcBuffer: *const ::std::os::raw::c_void, - srcSize: usize, - preferencesPtr: *const LZ4F_preferences_t, - ) -> usize; -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct LZ4F_cctx_s { - _unused: [u8; 0], -} -pub type LZ4F_cctx = LZ4F_cctx_s; -pub type LZ4F_compressionContext_t = *mut LZ4F_cctx; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct LZ4F_compressOptions_t { - pub stableSrc: ::std::os::raw::c_uint, - pub reserved: [::std::os::raw::c_uint; 3usize], -} -#[test] -fn bindgen_test_layout_LZ4F_compressOptions_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(LZ4F_compressOptions_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(LZ4F_compressOptions_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).stableSrc) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_compressOptions_t), - "::", - stringify!(stableSrc) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).reserved) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_compressOptions_t), - "::", - stringify!(reserved) - ) - ); -} -extern "C" { - pub fn LZ4F_getVersion() -> ::std::os::raw::c_uint; -} -extern "C" { - #[doc = " LZ4F_createCompressionContext() :\n The first thing to do is to create a compressionContext object,\n which will keep track of operation state during streaming compression.\n This is achieved using LZ4F_createCompressionContext(), which takes as argument a version,\n and a pointer to LZ4F_cctx*, to write the resulting pointer into.\n @version provided MUST be LZ4F_VERSION. It is intended to track potential version mismatch, notably when using DLL.\n The function provides a pointer to a fully allocated LZ4F_cctx object.\n @cctxPtr MUST be != NULL.\n If @return != zero, context creation failed.\n A created compression context can be employed multiple times for consecutive streaming operations.\n Once all streaming compression jobs are completed,\n the state object can be released using LZ4F_freeCompressionContext().\n Note1 : LZ4F_freeCompressionContext() is always successful. Its return value can be ignored.\n Note2 : LZ4F_freeCompressionContext() works fine with NULL input pointers (do nothing)."] - pub fn LZ4F_createCompressionContext( - cctxPtr: *mut *mut LZ4F_cctx, - version: ::std::os::raw::c_uint, - ) -> LZ4F_errorCode_t; -} -extern "C" { - pub fn LZ4F_freeCompressionContext(cctx: *mut LZ4F_cctx) -> LZ4F_errorCode_t; -} -extern "C" { - #[doc = " LZ4F_compressBegin() :\n will write the frame header into dstBuffer.\n dstCapacity must be >= LZ4F_HEADER_SIZE_MAX bytes.\n `prefsPtr` is optional : NULL can be provided to set all preferences to default.\n @return : number of bytes written into dstBuffer for the header\n or an error code (which can be tested using LZ4F_isError())"] - pub fn LZ4F_compressBegin( - cctx: *mut LZ4F_cctx, - dstBuffer: *mut ::std::os::raw::c_void, - dstCapacity: usize, - prefsPtr: *const LZ4F_preferences_t, - ) -> usize; -} -extern "C" { - #[doc = " LZ4F_compressBound() :\n Provides minimum dstCapacity required to guarantee success of\n LZ4F_compressUpdate(), given a srcSize and preferences, for a worst case scenario.\n When srcSize==0, LZ4F_compressBound() provides an upper bound for LZ4F_flush() and LZ4F_compressEnd() instead.\n Note that the result is only valid for a single invocation of LZ4F_compressUpdate().\n When invoking LZ4F_compressUpdate() multiple times,\n if the output buffer is gradually filled up instead of emptied and re-used from its start,\n one must check if there is enough remaining capacity before each invocation, using LZ4F_compressBound().\n @return is always the same for a srcSize and prefsPtr.\n prefsPtr is optional : when NULL is provided, preferences will be set to cover worst case scenario.\n tech details :\n @return if automatic flushing is not enabled, includes the possibility that internal buffer might already be filled by up to (blockSize-1) bytes.\n It also includes frame footer (ending + checksum), since it might be generated by LZ4F_compressEnd().\n @return doesn't include frame header, as it was already generated by LZ4F_compressBegin()."] - pub fn LZ4F_compressBound(srcSize: usize, prefsPtr: *const LZ4F_preferences_t) -> usize; -} -extern "C" { - #[doc = " LZ4F_compressUpdate() :\n LZ4F_compressUpdate() can be called repetitively to compress as much data as necessary.\n Important rule: dstCapacity MUST be large enough to ensure operation success even in worst case situations.\n This value is provided by LZ4F_compressBound().\n If this condition is not respected, LZ4F_compress() will fail (result is an errorCode).\n After an error, the state is left in a UB state, and must be re-initialized or freed.\n If previously an uncompressed block was written, buffered data is flushed\n before appending compressed data is continued.\n `cOptPtr` is optional : NULL can be provided, in which case all options are set to default.\n @return : number of bytes written into `dstBuffer` (it can be zero, meaning input data was just buffered).\n or an error code if it fails (which can be tested using LZ4F_isError())"] - pub fn LZ4F_compressUpdate( - cctx: *mut LZ4F_cctx, - dstBuffer: *mut ::std::os::raw::c_void, - dstCapacity: usize, - srcBuffer: *const ::std::os::raw::c_void, - srcSize: usize, - cOptPtr: *const LZ4F_compressOptions_t, - ) -> usize; -} -extern "C" { - #[doc = " LZ4F_flush() :\n When data must be generated and sent immediately, without waiting for a block to be completely filled,\n it's possible to call LZ4_flush(). It will immediately compress any data buffered within cctx.\n `dstCapacity` must be large enough to ensure the operation will be successful.\n `cOptPtr` is optional : it's possible to provide NULL, all options will be set to default.\n @return : nb of bytes written into dstBuffer (can be zero, when there is no data stored within cctx)\n or an error code if it fails (which can be tested using LZ4F_isError())\n Note : LZ4F_flush() is guaranteed to be successful when dstCapacity >= LZ4F_compressBound(0, prefsPtr)."] - pub fn LZ4F_flush( - cctx: *mut LZ4F_cctx, - dstBuffer: *mut ::std::os::raw::c_void, - dstCapacity: usize, - cOptPtr: *const LZ4F_compressOptions_t, - ) -> usize; -} -extern "C" { - #[doc = " LZ4F_compressEnd() :\n To properly finish an LZ4 frame, invoke LZ4F_compressEnd().\n It will flush whatever data remained within `cctx` (like LZ4_flush())\n and properly finalize the frame, with an endMark and a checksum.\n `cOptPtr` is optional : NULL can be provided, in which case all options will be set to default.\n @return : nb of bytes written into dstBuffer, necessarily >= 4 (endMark),\n or an error code if it fails (which can be tested using LZ4F_isError())\n Note : LZ4F_compressEnd() is guaranteed to be successful when dstCapacity >= LZ4F_compressBound(0, prefsPtr).\n A successful call to LZ4F_compressEnd() makes `cctx` available again for another compression task."] - pub fn LZ4F_compressEnd( - cctx: *mut LZ4F_cctx, - dstBuffer: *mut ::std::os::raw::c_void, - dstCapacity: usize, - cOptPtr: *const LZ4F_compressOptions_t, - ) -> usize; -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct LZ4F_dctx_s { - _unused: [u8; 0], -} -pub type LZ4F_dctx = LZ4F_dctx_s; -pub type LZ4F_decompressionContext_t = *mut LZ4F_dctx; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct LZ4F_decompressOptions_t { - pub stableDst: ::std::os::raw::c_uint, - pub skipChecksums: ::std::os::raw::c_uint, - pub reserved1: ::std::os::raw::c_uint, - pub reserved0: ::std::os::raw::c_uint, -} -#[test] -fn bindgen_test_layout_LZ4F_decompressOptions_t() { - const UNINIT: ::std::mem::MaybeUninit = - ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 16usize, - concat!("Size of: ", stringify!(LZ4F_decompressOptions_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(LZ4F_decompressOptions_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).stableDst) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_decompressOptions_t), - "::", - stringify!(stableDst) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).skipChecksums) as usize - ptr as usize }, - 4usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_decompressOptions_t), - "::", - stringify!(skipChecksums) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).reserved1) as usize - ptr as usize }, - 8usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_decompressOptions_t), - "::", - stringify!(reserved1) - ) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).reserved0) as usize - ptr as usize }, - 12usize, - concat!( - "Offset of field: ", - stringify!(LZ4F_decompressOptions_t), - "::", - stringify!(reserved0) - ) - ); -} -extern "C" { - #[doc = " LZ4F_createDecompressionContext() :\n Create an LZ4F_dctx object, to track all decompression operations.\n @version provided MUST be LZ4F_VERSION.\n @dctxPtr MUST be valid.\n The function fills @dctxPtr with the value of a pointer to an allocated and initialized LZ4F_dctx object.\n The @return is an errorCode, which can be tested using LZ4F_isError().\n dctx memory can be released using LZ4F_freeDecompressionContext();\n Result of LZ4F_freeDecompressionContext() indicates current state of decompressionContext when being released.\n That is, it should be == 0 if decompression has been completed fully and correctly."] - pub fn LZ4F_createDecompressionContext( - dctxPtr: *mut *mut LZ4F_dctx, - version: ::std::os::raw::c_uint, - ) -> LZ4F_errorCode_t; -} -extern "C" { - pub fn LZ4F_freeDecompressionContext(dctx: *mut LZ4F_dctx) -> LZ4F_errorCode_t; -} -extern "C" { - #[doc = " LZ4F_headerSize() : v1.9.0+\n Provide the header size of a frame starting at `src`.\n `srcSize` must be >= LZ4F_MIN_SIZE_TO_KNOW_HEADER_LENGTH,\n which is enough to decode the header length.\n @return : size of frame header\n or an error code, which can be tested using LZ4F_isError()\n note : Frame header size is variable, but is guaranteed to be\n >= LZ4F_HEADER_SIZE_MIN bytes, and <= LZ4F_HEADER_SIZE_MAX bytes."] - pub fn LZ4F_headerSize(src: *const ::std::os::raw::c_void, srcSize: usize) -> usize; -} -extern "C" { - #[doc = " LZ4F_getFrameInfo() :\n This function extracts frame parameters (max blockSize, dictID, etc.).\n Its usage is optional: user can also invoke LZ4F_decompress() directly.\n\n Extracted information will fill an existing LZ4F_frameInfo_t structure.\n This can be useful for allocation and dictionary identification purposes.\n\n LZ4F_getFrameInfo() can work in the following situations :\n\n 1) At the beginning of a new frame, before any invocation of LZ4F_decompress().\n It will decode header from `srcBuffer`,\n consuming the header and starting the decoding process.\n\n Input size must be large enough to contain the full frame header.\n Frame header size can be known beforehand by LZ4F_headerSize().\n Frame header size is variable, but is guaranteed to be >= LZ4F_HEADER_SIZE_MIN bytes,\n and not more than <= LZ4F_HEADER_SIZE_MAX bytes.\n Hence, blindly providing LZ4F_HEADER_SIZE_MAX bytes or more will always work.\n It's allowed to provide more input data than the header size,\n LZ4F_getFrameInfo() will only consume the header.\n\n If input size is not large enough,\n aka if it's smaller than header size,\n function will fail and return an error code.\n\n 2) After decoding has been started,\n it's possible to invoke LZ4F_getFrameInfo() anytime\n to extract already decoded frame parameters stored within dctx.\n\n Note that, if decoding has barely started,\n and not yet read enough information to decode the header,\n LZ4F_getFrameInfo() will fail.\n\n The number of bytes consumed from srcBuffer will be updated in *srcSizePtr (necessarily <= original value).\n LZ4F_getFrameInfo() only consumes bytes when decoding has not yet started,\n and when decoding the header has been successful.\n Decompression must then resume from (srcBuffer + *srcSizePtr).\n\n @return : a hint about how many srcSize bytes LZ4F_decompress() expects for next call,\n or an error code which can be tested using LZ4F_isError().\n note 1 : in case of error, dctx is not modified. Decoding operation can resume from beginning safely.\n note 2 : frame parameters are *copied into* an already allocated LZ4F_frameInfo_t structure."] - pub fn LZ4F_getFrameInfo( - dctx: *mut LZ4F_dctx, - frameInfoPtr: *mut LZ4F_frameInfo_t, - srcBuffer: *const ::std::os::raw::c_void, - srcSizePtr: *mut usize, - ) -> usize; -} -extern "C" { - #[doc = " LZ4F_decompress() :\n Call this function repetitively to regenerate data compressed in `srcBuffer`.\n\n The function requires a valid dctx state.\n It will read up to *srcSizePtr bytes from srcBuffer,\n and decompress data into dstBuffer, of capacity *dstSizePtr.\n\n The nb of bytes consumed from srcBuffer will be written into *srcSizePtr (necessarily <= original value).\n The nb of bytes decompressed into dstBuffer will be written into *dstSizePtr (necessarily <= original value).\n\n The function does not necessarily read all input bytes, so always check value in *srcSizePtr.\n Unconsumed source data must be presented again in subsequent invocations.\n\n `dstBuffer` can freely change between each consecutive function invocation.\n `dstBuffer` content will be overwritten.\n\n Note: if `LZ4F_getFrameInfo()` is called before `LZ4F_decompress()`, srcBuffer must be updated to reflect\n the number of bytes consumed after reading the frame header. Failure to update srcBuffer before calling\n `LZ4F_decompress()` will cause decompression failure or, even worse, successful but incorrect decompression.\n See the `LZ4F_getFrameInfo()` docs for details.\n\n @return : an hint of how many `srcSize` bytes LZ4F_decompress() expects for next call.\n Schematically, it's the size of the current (or remaining) compressed block + header of next block.\n Respecting the hint provides some small speed benefit, because it skips intermediate buffers.\n This is just a hint though, it's always possible to provide any srcSize.\n\n When a frame is fully decoded, @return will be 0 (no more data expected).\n When provided with more bytes than necessary to decode a frame,\n LZ4F_decompress() will stop reading exactly at end of current frame, and @return 0.\n\n If decompression failed, @return is an error code, which can be tested using LZ4F_isError().\n After a decompression error, the `dctx` context is not resumable.\n Use LZ4F_resetDecompressionContext() to return to clean state.\n\n After a frame is fully decoded, dctx can be used again to decompress another frame."] - pub fn LZ4F_decompress( - dctx: *mut LZ4F_dctx, - dstBuffer: *mut ::std::os::raw::c_void, - dstSizePtr: *mut usize, - srcBuffer: *const ::std::os::raw::c_void, - srcSizePtr: *mut usize, - dOptPtr: *const LZ4F_decompressOptions_t, - ) -> usize; -} -extern "C" { - #[doc = " LZ4F_resetDecompressionContext() : added in v1.8.0\n In case of an error, the context is left in \"undefined\" state.\n In which case, it's necessary to reset it, before re-using it.\n This method can also be used to abruptly stop any unfinished decompression,\n and start a new one using same context resources."] - pub fn LZ4F_resetDecompressionContext(dctx: *mut LZ4F_dctx); -} -pub const XXH_errorcode_XXH_OK: XXH_errorcode = 0; -pub const XXH_errorcode_XXH_ERROR: XXH_errorcode = 1; -pub type XXH_errorcode = ::std::os::raw::c_int; -extern "C" { - pub fn XXH_versionNumber() -> ::std::os::raw::c_uint; -} -pub type XXH32_hash_t = ::std::os::raw::c_uint; -extern "C" { - #[doc = " XXH32() :\nCalculate the 32-bit hash of sequence \"length\" bytes stored at memory address \"input\".\nThe memory between input & input+length must be valid (allocated and read-accessible).\n\"seed\" can be used to alter the result predictably.\nSpeed on Core 2 Duo @ 3 GHz (single thread, SMHasher benchmark) : 5.4 GB/s"] - pub fn XXH32( - input: *const ::std::os::raw::c_void, - length: usize, - seed: ::std::os::raw::c_uint, - ) -> XXH32_hash_t; -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct XXH32_state_s { - _unused: [u8; 0], -} -pub type XXH32_state_t = XXH32_state_s; -extern "C" { - pub fn XXH32_createState() -> *mut XXH32_state_t; -} -extern "C" { - pub fn XXH32_freeState(statePtr: *mut XXH32_state_t) -> XXH_errorcode; -} -extern "C" { - pub fn XXH32_copyState(dst_state: *mut XXH32_state_t, src_state: *const XXH32_state_t); -} -extern "C" { - pub fn XXH32_reset(statePtr: *mut XXH32_state_t, seed: ::std::os::raw::c_uint) - -> XXH_errorcode; -} -extern "C" { - pub fn XXH32_update( - statePtr: *mut XXH32_state_t, - input: *const ::std::os::raw::c_void, - length: usize, - ) -> XXH_errorcode; -} -extern "C" { - pub fn XXH32_digest(statePtr: *const XXH32_state_t) -> XXH32_hash_t; -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct XXH32_canonical_t { - pub digest: [::std::os::raw::c_uchar; 4usize], -} -#[test] -fn bindgen_test_layout_XXH32_canonical_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 4usize, - concat!("Size of: ", stringify!(XXH32_canonical_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(XXH32_canonical_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).digest) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(XXH32_canonical_t), - "::", - stringify!(digest) - ) - ); -} -extern "C" { - pub fn XXH32_canonicalFromHash(dst: *mut XXH32_canonical_t, hash: XXH32_hash_t); -} -extern "C" { - pub fn XXH32_hashFromCanonical(src: *const XXH32_canonical_t) -> XXH32_hash_t; -} -pub type XXH64_hash_t = ::std::os::raw::c_ulonglong; -extern "C" { - #[doc = " XXH64() :\nCalculate the 64-bit hash of sequence of length \"len\" stored at memory address \"input\".\n\"seed\" can be used to alter the result predictably.\nThis function runs faster on 64-bit systems, but slower on 32-bit systems (see benchmark)."] - pub fn XXH64( - input: *const ::std::os::raw::c_void, - length: usize, - seed: ::std::os::raw::c_ulonglong, - ) -> XXH64_hash_t; -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct XXH64_state_s { - _unused: [u8; 0], -} -pub type XXH64_state_t = XXH64_state_s; -extern "C" { - pub fn XXH64_createState() -> *mut XXH64_state_t; -} -extern "C" { - pub fn XXH64_freeState(statePtr: *mut XXH64_state_t) -> XXH_errorcode; -} -extern "C" { - pub fn XXH64_copyState(dst_state: *mut XXH64_state_t, src_state: *const XXH64_state_t); -} -extern "C" { - pub fn XXH64_reset( - statePtr: *mut XXH64_state_t, - seed: ::std::os::raw::c_ulonglong, - ) -> XXH_errorcode; -} -extern "C" { - pub fn XXH64_update( - statePtr: *mut XXH64_state_t, - input: *const ::std::os::raw::c_void, - length: usize, - ) -> XXH_errorcode; -} -extern "C" { - pub fn XXH64_digest(statePtr: *const XXH64_state_t) -> XXH64_hash_t; -} -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct XXH64_canonical_t { - pub digest: [::std::os::raw::c_uchar; 8usize], -} -#[test] -fn bindgen_test_layout_XXH64_canonical_t() { - const UNINIT: ::std::mem::MaybeUninit = ::std::mem::MaybeUninit::uninit(); - let ptr = UNINIT.as_ptr(); - assert_eq!( - ::std::mem::size_of::(), - 8usize, - concat!("Size of: ", stringify!(XXH64_canonical_t)) - ); - assert_eq!( - ::std::mem::align_of::(), - 1usize, - concat!("Alignment of ", stringify!(XXH64_canonical_t)) - ); - assert_eq!( - unsafe { ::std::ptr::addr_of!((*ptr).digest) as usize - ptr as usize }, - 0usize, - concat!( - "Offset of field: ", - stringify!(XXH64_canonical_t), - "::", - stringify!(digest) - ) - ); -} -extern "C" { - pub fn XXH64_canonicalFromHash(dst: *mut XXH64_canonical_t, hash: XXH64_hash_t); -} -extern "C" { - pub fn XXH64_hashFromCanonical(src: *const XXH64_canonical_t) -> XXH64_hash_t; -} diff --git a/csbindgen-tests/src/main.rs b/csbindgen-tests/src/main.rs deleted file mode 100644 index 745dd69..0000000 --- a/csbindgen-tests/src/main.rs +++ /dev/null @@ -1,13 +0,0 @@ -use std::env; - -fn main() { - - let path = env::current_dir().unwrap(); - println!("starting dir: {}", path.display()); - - csbindgen::run( - "csbindgen-tests/src/lz4/mod.rs", - "csbindgen-tests/src/ffi.rs", - "dotnet-sandbox/bindgen.cs", - ); -} diff --git a/csbindgen/src/builder.rs b/csbindgen/src/builder.rs new file mode 100644 index 0000000..4db0c7b --- /dev/null +++ b/csbindgen/src/builder.rs @@ -0,0 +1,128 @@ +use std::{ + error::Error, + fs::{File, OpenOptions}, + io::{self, Write}, + path::Path, +}; + +use crate::generate; + +pub struct Builder { + options: BindgenOptions, +} + +pub struct BindgenOptions { + pub input_bindgen_file: String, + + /// add original extern call type prefix to rust wrapper, + /// `return {rust_method_type_path}::foo()` + pub rust_method_type_path: String, + + /// add method prefix to rust wrapper, + /// `pub extern "C" fn {rust_method_prefix}foo()` + pub rust_method_prefix: String, + + /// add file header string to rust wrapper, + /// `mod lz4;`, `use super::lz4;` + pub rust_file_header: String, + + /// configure C# file namespace(default is `CsBindgen`), + /// "namespace {csharp_namespace}" + pub csharp_namespace: String, + + /// configure C# class name(default is `NativeMethods`), + /// `public static unsafe partial class {csharp_class_name}` + pub csharp_class_name: String, + + /// configure C# load dll name, + /// `[DllImport({csharp_dll_name})]` + pub csharp_dll_name: String, + + /// configure C# calling method name prefix, + /// `public static extern void {csharp_method_prefix}foo()` + pub csharp_method_prefix: String, + + /// configure c_long to {csharp_c_long_convert} type, + /// default is `Int32`. + pub csharp_c_long_convert: String, + + /// configure c_long to {csharp_c_long_convert} type, + /// default is `UInt32`. + pub csharp_c_ulong_convert: String, +} + +impl Builder { + pub fn new() -> Self { + Self { + options: BindgenOptions { + input_bindgen_file: "".to_string(), + rust_method_type_path: "".to_string(), + rust_method_prefix: "".to_string(), + rust_file_header: "".to_string(), + csharp_namespace: "CsBindgen".to_string(), + csharp_class_name: "NativeMethods".to_string(), + csharp_dll_name: "".to_string(), + csharp_method_prefix: "".to_string(), + csharp_c_long_convert: "Int32".to_string(), + csharp_c_ulong_convert: "UInt32".to_string(), + }, + } + } + + /// Change an input .rs file(such as generated from bindgen) to generate binding. + pub fn input_bindgen_file>(mut self, input_bindgen_file: T) -> Builder { + self.options.input_bindgen_file = input_bindgen_file.into(); + self + } + + // TODO:method chain methods... + + /// add method prefix to rust wrapper, + /// `pub extern "C" fn {rust_method_prefix}foo()` + pub fn rust_method_prefix>(mut self, rust_method_prefix: T) -> Builder { + self.options.rust_method_prefix = rust_method_prefix.into(); + self + } + + // pub fn generate_csharp_file>(&self, csharp_output_path: T) -> io::Result<()> { + // let mut file = OpenOptions::new() + // .write(true) + // .truncate(true) + // .create(true) + // .open(csharp_output_path.as_ref())?; + + // let code = self.generate(); + // file.write_all(code.as_bytes())?; + // file.flush()?; + + // Ok(()) + // } + + pub fn generate_to_file>( + &self, + rust_output_path: P, + csharp_output_path: P, + ) -> Result<(), Box> { + let mut rust_file = make_file(rust_output_path)?; + let mut csharp_file = make_file(csharp_output_path)?; + + let (rust, csharp) = generate(&self.options)?; + + rust_file.write_all(rust.as_bytes())?; + rust_file.flush()?; + + csharp_file.write_all(csharp.as_bytes())?; + csharp_file.flush()?; + + Ok(()) + } +} + +fn make_file>(path: P) -> io::Result { + let file = OpenOptions::new() + .write(true) + .truncate(true) + .create(true) + .open(path)?; + Ok(file) +} diff --git a/csbindgen/src/emitter.rs b/csbindgen/src/emitter.rs new file mode 100644 index 0000000..d94a93e --- /dev/null +++ b/csbindgen/src/emitter.rs @@ -0,0 +1,186 @@ +use std::collections::HashMap; + +use crate::builder::BindgenOptions; +use crate::type_meta::*; +use crate::util::*; + +pub fn emit_rust_method(list: &Vec, options: &BindgenOptions) -> String { + // configure + let method_type_path = &options.rust_method_type_path; + let method_prefix = &options.rust_method_prefix; + let file_header = &options.rust_file_header; + + let mut methods_string = String::new(); + + for item in list { + let method_name = item.method_name.as_str(); + let parameters = item + .parameters + .iter() + .map(|p| { + format!( + " {}: {}", + p.name, + p.rust_type.to_string(method_type_path) + ) + }) + .collect::>() + .join(",\n"); + + let return_line = match &item.return_type { + None => "".to_string(), + Some(v) => format!(" -> {}", v.to_string(method_type_path)), + }; + + let parameter_only_names = item + .parameters + .iter() + .map(|p| format!(" {}", p.name)) + .collect::>() + .join(",\n"); + + let template = format!( + " +#[no_mangle] +pub extern \"C\" fn {method_prefix}{method_name}( +{parameters} +){return_line} +{{ + unsafe {{ + return {method_type_path}{method_name}( +{parameter_only_names} + ) + }} +}} +" + ); + + methods_string.push_str(template.as_str()); + } + + let result = format!( + "// auto-generated via csbindgen + +#[allow(unused)] +use ::std::os::raw::*; + +{file_header} + +{methods_string} + " + ); + + return result; +} + +pub fn emit_csharp( + methods: &Vec, + aliases: &HashMap, + structs: &Vec, + options: &BindgenOptions +) -> String { + // configure + let namespace = &options.csharp_namespace; + let class_name = &options.csharp_class_name; + let dll_name = &options.csharp_dll_name; + let method_prefix = &options.csharp_method_prefix; + + let mut method_list_string = String::new(); + for item in methods { + let method_name = &item.method_name; + let return_type = match &item.return_type { + Some(x) => x.to_csharp_string(&options), + None => "void".to_string(), + }; + + let parameters = item + .parameters + .iter() + .map(|p| format!("{} {}", p.rust_type.to_csharp_string(&options), p.name)) + .collect::>() + .join(", "); + + method_list_string.push_str_ln( + " [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)]", + ); + method_list_string.push_str_ln( + format!(" public static extern {return_type} {method_prefix}{method_name}({parameters});").as_str(), + ); + method_list_string.push_str("\n"); + } + + let mut alias_string = String::new(); + let mut aliases: Vec<_> = aliases.iter().collect(); + aliases.sort_by_key(|x| x.0); + for (name, rust_type) in aliases { + alias_string.push_str_ln( + format!(" using {} = {};", name, rust_type.to_csharp_string(&options)).as_str(), + ); + } + + let mut structs_string = String::new(); + for item in structs { + let name = &item.struct_name; + let layout_kind = if item.is_union { + "Explicit" + } else { + "Sequential" + }; + + structs_string + .push_str_ln(format!(" [StructLayout(LayoutKind.{layout_kind})]").as_str()); + structs_string.push_str_ln(format!(" public unsafe struct {name}").as_str()); + structs_string.push_str_ln(" {"); + for field in &item.fields { + if item.is_union { + structs_string.push_str_ln(" [FieldOffset(0)]"); + } + structs_string.push_str( + format!( + " public {} {}", + field.rust_type.to_csharp_string(&options), + field.name + ) + .as_str(), + ); + if field.rust_type.is_fixed_array { + let mut digits = field.rust_type.fixed_array_digits.clone(); + if digits == "0" { + digits = "1".to_string(); // 0 fixed array is not allowed in C# + }; + + structs_string.push_str(format!("[{}]", digits).as_str()); + } + structs_string.push_str_ln(";"); + } + structs_string.push_str_ln(" }"); + structs_string.push_str("\n"); + } + + // TODO: for Unity, `__Intern`. + let result = format!( + "// +// This code is generated via csbindgen. +// DON'T CHANGE THIS DIRECTLY. +// +using System; +using System.Runtime.InteropServices; + +namespace {namespace} +{{ +{alias_string} + + public static unsafe partial class {class_name} + {{ + const string __DllName = \"{dll_name}\"; + +{method_list_string} + }} + +{structs_string} +}} + " + ); + + return result; +} diff --git a/csbindgen/src/lib.rs b/csbindgen/src/lib.rs index e8497a0..4b749b6 100644 --- a/csbindgen/src/lib.rs +++ b/csbindgen/src/lib.rs @@ -1,17 +1,20 @@ -use std::{ - collections::{HashMap, HashSet}, - fmt::Display, - fs::{self, File}, - io::Write, -}; +mod builder; +mod emitter; +mod parser; +mod type_meta; +mod util; -use syn::{ForeignItem, Item, Pat, ReturnType}; +pub use builder::Builder; -// mod lz4; +use builder::BindgenOptions; +use emitter::*; +use parser::*; +use std::{collections::HashSet, error::Error}; -pub fn run(rs_path: &str, output_path: &str, csharp_output_path: &str) { - let file_content = fs::read_to_string(rs_path).unwrap(); - let file_ast = syn::parse_file(file_content.as_str()).unwrap(); +pub(crate) fn generate(options: &BindgenOptions) -> Result<(String, String), Box> { + let path = &options.input_bindgen_file; + let file_content = std::fs::read_to_string(path)?; + let file_ast = syn::parse_file(file_content.as_str())?; let methods = collect_method(&file_ast); let aliases = collect_type_alias(&file_ast); @@ -39,551 +42,11 @@ pub fn run(rs_path: &str, output_path: &str, csharp_output_path: &str) { let structs = reduce_struct(&structs, &using_types); - let vecs = emit_rust_method(&methods); - // TODO: filter methods //if !(t.method_name.starts_with("_") || t.method_name == "") { - let mut file = File::create(output_path).unwrap(); - { - // TODO:modify here - // TODO:modify here - file.write_all("#[allow(unused)]\n".as_bytes()).unwrap(); - file.write_all("use ::std::os::raw::*;\n".as_bytes()) - .unwrap(); - file.write_all("use super::lz4;\n\n".as_bytes()).unwrap(); - for str in vecs { - file.write_all(str.as_bytes()).unwrap(); - } + let rust = emit_rust_method(&methods, &options); + let csharp = emit_csharp(&methods, &aliases, &structs, &options); - file.flush().unwrap(); - } - - let csharp = emit_csharp(&methods, &aliases, &structs); - let mut file = File::create(csharp_output_path).unwrap(); - file.write_all(csharp.as_bytes()).unwrap(); - file.flush().unwrap(); -} - -fn collect_method(ast: &syn::File) -> Vec { - let mut list: Vec = Vec::new(); - - for item in ast.items.iter() { - if let Item::ForeignMod(m) = item { - for item in m.items.iter() { - if let ForeignItem::Fn(m) = item { - let method_name = m.sig.ident.to_string(); - - let mut parameters: Vec = Vec::new(); - let mut retrun_type: Option = None; - - // argument - for arg in m.sig.inputs.iter() { - if let syn::FnArg::Typed(t) = arg { - let mut parameter_name: String = "".to_string(); - - if let Pat::Ident(ident) = &*t.pat { - parameter_name = ident.ident.to_string(); - } - - let rust_type = parse_type(&t.ty); - - parameters.push(Parameter { - name: parameter_name, - rust_type: rust_type, - }); - } - } - - // return - if let ReturnType::Type(_, b) = &m.sig.output { - let rust_type = parse_type(&b); - if rust_type.type_name == "" { - continue; - } - - retrun_type = Some(rust_type); - } - - let t = ExternMethod { - method_name: method_name.clone(), - parameters: parameters, - return_type: retrun_type, - }; - - list.push(t.clone()); - } - } - } - } - - return list; -} - -fn collect_type_alias(ast: &syn::File) -> Vec<(String, RustType)> { - let mut result = Vec::new(); - for item in ast.items.iter() { - if let Item::Type(t) = item { - let name = t.ident.to_string(); - let alias = parse_type(&t.ty); - - // pointer can not use alias. - if !alias.is_pointer || !alias.is_pointer_pointer { - result.push((name, alias)); - } - } - } - return result; -} - -fn collect_struct(ast: &syn::File) -> Vec { - // collect union or struct - - let mut result = Vec::new(); - - for item in ast.items.iter() { - if let Item::Union(t) = item { - let name = t.ident.to_string(); - let fields = collect_fields(&t.fields); - - result.push(RustStruct { - struct_name: name, - fields: fields, - is_union: true, - }); - } else if let Item::Struct(t) = item { - if let syn::Fields::Named(f) = &t.fields { - let name = t.ident.to_string(); - let fields = collect_fields(&f); - result.push(RustStruct { - struct_name: name, - fields: fields, - is_union: false, - }); - }; - } - } - - return result; -} - -fn collect_fields(fields: &syn::FieldsNamed) -> Vec { - let mut result = Vec::new(); - - for field in &fields.named { - if let Some(x) = &field.ident { - let t = parse_type(&field.ty); - result.push(FieldMember { - name: x.to_string(), - rust_type: t, - }); - } - } - - return result; -} - -fn reduce_type_alias( - aliases: &Vec<(String, RustType)>, - using_types: &HashSet, -) -> HashMap { - let mut map = HashMap::new(); - for (name, rust_type) in aliases { - if using_types.contains(name) { - map.insert(name.clone(), rust_type.clone()); - } - } - - for (name, rust_type) in aliases { - let pointed = map.get(rust_type.type_name.as_str()); - if let Some(x) = pointed { - map.insert(name.to_string(), x.clone()); - } - } - - return map; -} - -fn reduce_struct(structs: &Vec, using_types: &HashSet) -> Vec { - let mut result = Vec::new(); - for item in structs { - if using_types.contains(&item.struct_name) { - result.push(item.clone()); - } - } - - return result; -} - -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 { - syn::Type::Ptr(t) => { - has_star = true; - has_const = t.const_token.is_some(); - has_mut = t.mutability.is_some(); - - if let syn::Type::Path(path) = &*t.elem { - path.path.segments.last().unwrap().ident.to_string() - } 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() - } - } else { - "".to_string() - } - } - syn::Type::Path(t) => t.path.segments.last().unwrap().ident.to_string(), - syn::Type::Array(t) => { - 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 - } - _ => "".to_string(), - }; - - return RustType { - is_const: has_const, - is_mut: has_mut, - is_pointer: has_star, - is_pointer_pointer: has_star_star, - is_fixed_array: (digits != ""), - type_name: name, - fixed_array_digits: digits, - }; -} - -// TODO:rewrite -fn emit_rust_method(list: &Vec) -> Vec { - let mod_name = "lz4"; - - let mut result = Vec::new(); - - for item in list { - let method_name = item.method_name.as_str(); - let parameters = item.parameters.iter().map(|p| { - let mut sb = p.name.to_string(); - sb.push_str(": "); - sb.push_str(p.rust_type.to_string(mod_name).as_str()); - sb - }); - - let parameter_only_names = item.parameters.iter().map(|p| p.name.as_str()); - - let return_line = match &item.return_type { - None => "".to_string(), - Some(v) => { - let mut sb = " -> ".to_string(); - sb.push_str(v.to_string(mod_name).as_str()); - sb - } - }; - - let mut sb = String::new(); - sb.push_str("#[no_mangle]\n"); - sb.push_str(format!("pub extern \"C\" fn csbindgen_{method_name}(\n").as_str()); - for parameter in parameters { - sb.push_str(" "); - sb.push_str(parameter.as_str()); - sb.push_str(",\n"); - } - sb.push_str(")"); - if return_line != "" { - sb.push_str(return_line.as_str()); - } - sb.push_str("\n"); - sb.push_str("{\n"); - sb.push_str(" unsafe {\n"); - sb.push_str(format!(" return {mod_name}::{method_name}(\n").as_str()); - for p in parameter_only_names { - sb.push_str(" "); - sb.push_str(p); - sb.push_str(",\n"); - } - sb.push_str(" )\n"); - sb.push_str(" }\n"); - sb.push_str_ln("}\n"); - - result.push(sb); - } - - return result; -} - -fn emit_csharp( - methods: &Vec, - aliases: &HashMap, - structs: &Vec, -) -> String { - // TODO: options - let namespace = "Csbindgen"; - let class_name = "NativeMethods"; - let dll_name = "csbindgen_tests"; - let method_prefix = "csbindgen_"; - - let mut method_list_string = String::new(); - for item in methods { - let method_name = &item.method_name; - let return_type = match &item.return_type { - Some(x) => x.to_csharp_string(), - None => "void".to_string(), - }; - - let parameters = item - .parameters - .iter() - .map(|p| format!("{} {}", p.rust_type.to_csharp_string(), p.name)) - .collect::>() - .join(", "); - - method_list_string.push_str_ln( - " [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)]", - ); - method_list_string.push_str_ln( - format!(" public static extern {return_type} {method_prefix}{method_name}({parameters});").as_str(), - ); - method_list_string.push_str("\n"); - } - - let mut alias_string = String::new(); - let mut aliases: Vec<_> = aliases.iter().collect(); - aliases.sort_by_key(|x| x.0); - for (name, rust_type) in aliases { - alias_string.push_str_ln( - format!(" using {} = {};", name, rust_type.to_csharp_string()).as_str(), - ); - } - - let mut structs_string = String::new(); - for item in structs { - let name = &item.struct_name; - let layout_kind = if item.is_union { - "Explicit" - } else { - "Sequential" - }; - - structs_string - .push_str_ln(format!(" [StructLayout(LayoutKind.{layout_kind})]").as_str()); - structs_string.push_str_ln(format!(" public unsafe struct {name}").as_str()); - structs_string.push_str_ln(" {"); - for field in &item.fields { - if item.is_union { - structs_string.push_str_ln(" [FieldOffset(0)]"); - } - structs_string.push_str( - format!( - " public {} {}", - field.rust_type.to_csharp_string(), - field.name - ) - .as_str(), - ); - if field.rust_type.is_fixed_array { - let mut digits = field.rust_type.fixed_array_digits.clone(); - if digits == "0" { - digits = "1".to_string(); // 0 fixed array is not allowed in C# - }; - - structs_string.push_str(format!("[{}]", digits).as_str()); - } - structs_string.push_str_ln(";"); - } - structs_string.push_str_ln(" }"); - structs_string.push_str("\n"); - } - - let result = format!( - "// -// This code is generated via csbindgen. -// DON'T CHANGE THIS DIRECTLY. -// -using System; -using System.Runtime.InteropServices; - -namespace {namespace} -{{ -{alias_string} - - public static unsafe partial class {class_name} - {{ - const string __DllName = \"{dll_name}\"; - -{method_list_string} - }} - -{structs_string} -}} - " - ); - - return result; -} - -trait PushStrLn { - fn push_str_ln(&mut self, string: &str); -} - -impl PushStrLn for String { - fn push_str_ln(&mut self, string: &str) { - self.push_str(string); - self.push('\n'); - } -} - -#[derive(Clone, Debug)] -pub struct Parameter { - pub name: String, - pub rust_type: RustType, -} - -#[derive(Clone, Debug)] -pub struct FieldMember { - pub name: String, - pub rust_type: RustType, -} - -#[derive(Clone, Debug)] -pub struct ExternMethod { - pub method_name: String, - pub parameters: Vec, - pub return_type: Option, -} - -#[derive(Clone, Debug, PartialEq, Eq, Hash)] -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, -} - -#[derive(Clone, Debug)] -pub struct RustStruct { - pub struct_name: String, - pub fields: Vec, - pub is_union: bool, -} - -impl RustType { - pub fn to_string(&self, mod_prefix: &str) -> String { - let mut sb = String::new(); - - if self.is_pointer || self.is_pointer_pointer { - sb.push_str("*"); - } - 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"); - } - } - - sb.push_str(" "); - - if self.is_fixed_array { - sb.push_str("["); - sb.push_str(self.type_name.as_str()); - sb.push_str("; "); - sb.push_str(self.fixed_array_digits.as_str()); - sb.push_str("]"); - } else { - if !self.type_name.starts_with("c_") - && !(self.type_name == "usize" || self.type_name == "isize") - { - sb.push_str(mod_prefix); - sb.push_str("::"); - } - sb.push_str(self.type_name.as_str()); - } - - sb - } - - pub fn to_csharp_string(&self) -> String { - fn convert_type_name(type_name: &str) -> &str { - let name = match type_name { - // std::os::raw https://doc.rust-lang.org/std/os/raw/index.html - "c_char" => "Byte", - "c_schar" => "SByte", - "c_uchar" => "Byte", - "c_short" => "Int16", - "c_ushort" => "UInt16", - "c_int" => "Int32", - "c_uint" => "UInt32", - "c_long" => "Int32", // int? long? nint? TODO:configure - "c_ulong" => "UInt32", // uint? ulong? nuint? TODO:configure - "c_longlong" => "Int64", - "c_ulonglong" => "UInt64", - "c_float" => "Float", - "c_double" => "Double", - "c_void" => "void", - // rust primitives - "i8" => "SByte", - "i16" => "Int16", - "i32" => "Int32", - "i64" => "Int64", - "i128" => "Int128", // .NET 7 - "isize" => "IntPtr", - "u8" => "Byte", - "u16" => "UInt16", - "u32" => "UInt32", - "u64" => "UInt64", - "u128" => "UInt128", // .NET 7 - "f32" => "Float", - "f64" => "Double", - "bool" => "Boolean", - "usize" => "UIntPtr", - "()" => "void", // if type is parameter, can't use in C# - _ => type_name, // as is - }; - name - } - - let mut sb = String::new(); - - if self.is_fixed_array { - sb.push_str("fixed "); - sb.push_str(convert_type_name(self.type_name.as_str())); - } else { - sb.push_str(convert_type_name(self.type_name.as_str())); - if self.is_pointer { - sb.push_str("*"); - } - if self.is_pointer_pointer { - sb.push_str("**"); - } - } - - sb - } -} - -impl Display for RustType { - fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { - write!(f, "{}", self.to_string("")) - } + return Ok((rust, csharp)); } diff --git a/csbindgen/src/parser.rs b/csbindgen/src/parser.rs new file mode 100644 index 0000000..d7693f8 --- /dev/null +++ b/csbindgen/src/parser.rs @@ -0,0 +1,203 @@ +use std::collections::{HashSet, HashMap}; +use crate::type_meta::*; +use syn::{ForeignItem, Item, Pat, ReturnType}; + +pub fn collect_method(ast: &syn::File) -> Vec { + let mut list: Vec = Vec::new(); + + for item in ast.items.iter() { + if let Item::ForeignMod(m) = item { + for item in m.items.iter() { + if let ForeignItem::Fn(m) = item { + let method_name = m.sig.ident.to_string(); + + let mut parameters: Vec = Vec::new(); + let mut retrun_type: Option = None; + + // argument + for arg in m.sig.inputs.iter() { + if let syn::FnArg::Typed(t) = arg { + let mut parameter_name: String = "".to_string(); + + if let Pat::Ident(ident) = &*t.pat { + parameter_name = ident.ident.to_string(); + } + + let rust_type = parse_type(&t.ty); + + parameters.push(Parameter { + name: parameter_name, + rust_type: rust_type, + }); + } + } + + // return + if let ReturnType::Type(_, b) = &m.sig.output { + let rust_type = parse_type(&b); + if rust_type.type_name == "" { + continue; + } + + retrun_type = Some(rust_type); + } + + let t = ExternMethod { + method_name: method_name.clone(), + parameters: parameters, + return_type: retrun_type, + }; + + list.push(t.clone()); + } + } + } + } + + return list; +} + +pub fn collect_type_alias(ast: &syn::File) -> Vec<(String, RustType)> { + let mut result = Vec::new(); + for item in ast.items.iter() { + if let Item::Type(t) = item { + let name = t.ident.to_string(); + let alias = parse_type(&t.ty); + + // pointer can not use alias. + if !alias.is_pointer || !alias.is_pointer_pointer { + result.push((name, alias)); + } + } + } + return result; +} + +pub fn collect_struct(ast: &syn::File) -> Vec { + // collect union or struct + let mut result = Vec::new(); + + for item in ast.items.iter() { + if let Item::Union(t) = item { + let name = t.ident.to_string(); + let fields = collect_fields(&t.fields); + + result.push(RustStruct { + struct_name: name, + fields: fields, + is_union: true, + }); + } else if let Item::Struct(t) = item { + if let syn::Fields::Named(f) = &t.fields { + let name = t.ident.to_string(); + let fields = collect_fields(&f); + result.push(RustStruct { + struct_name: name, + fields: fields, + is_union: false, + }); + }; + } + } + + return result; +} + +fn collect_fields(fields: &syn::FieldsNamed) -> Vec { + let mut result = Vec::new(); + + for field in &fields.named { + if let Some(x) = &field.ident { + let t = parse_type(&field.ty); + result.push(FieldMember { + name: x.to_string(), + rust_type: t, + }); + } + } + + return result; +} + +pub fn reduce_type_alias( + aliases: &Vec<(String, RustType)>, + using_types: &HashSet, +) -> HashMap { + let mut map = HashMap::new(); + for (name, rust_type) in aliases { + if using_types.contains(name) { + map.insert(name.clone(), rust_type.clone()); + } + } + + for (name, rust_type) in aliases { + let pointed = map.get(rust_type.type_name.as_str()); + if let Some(x) = pointed { + map.insert(name.to_string(), x.clone()); + } + } + + return map; +} + +pub fn reduce_struct(structs: &Vec, using_types: &HashSet) -> Vec { + let mut result = Vec::new(); + for item in structs { + if using_types.contains(&item.struct_name) { + result.push(item.clone()); + } + } + + return result; +} + +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 { + syn::Type::Ptr(t) => { + has_star = true; + has_const = t.const_token.is_some(); + has_mut = t.mutability.is_some(); + + if let syn::Type::Path(path) = &*t.elem { + path.path.segments.last().unwrap().ident.to_string() + } 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() + } + } else { + "".to_string() + } + } + syn::Type::Path(t) => t.path.segments.last().unwrap().ident.to_string(), + syn::Type::Array(t) => { + 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 + } + _ => "".to_string(), + }; + + return RustType { + is_const: has_const, + is_mut: has_mut, + is_pointer: has_star, + is_pointer_pointer: has_star_star, + is_fixed_array: (digits != ""), + type_name: name, + fixed_array_digits: digits, + }; +} \ No newline at end of file diff --git a/csbindgen/src/type_meta.rs b/csbindgen/src/type_meta.rs new file mode 100644 index 0000000..8dade00 --- /dev/null +++ b/csbindgen/src/type_meta.rs @@ -0,0 +1,146 @@ +use crate::builder::BindgenOptions; + +#[derive(Clone, Debug)] +pub struct Parameter { + pub name: String, + pub rust_type: RustType, +} + +#[derive(Clone, Debug)] +pub struct FieldMember { + pub name: String, + pub rust_type: RustType, +} + +#[derive(Clone, Debug)] +pub struct ExternMethod { + pub method_name: String, + pub parameters: Vec, + pub return_type: Option, +} + +#[derive(Clone, Debug, PartialEq, Eq, Hash)] +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, +} + +#[derive(Clone, Debug)] +pub struct RustStruct { + pub struct_name: String, + pub fields: Vec, + 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_str("*"); + } + 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"); + } + } + + sb.push_str(" "); + + if self.is_fixed_array { + sb.push_str("["); + sb.push_str(self.type_name.as_str()); + sb.push_str("; "); + sb.push_str(self.fixed_array_digits.as_str()); + sb.push_str("]"); + } else { + if !self.type_name.starts_with("c_") + && !(self.type_name == "usize" || self.type_name == "isize") + && !(type_path == "") + { + sb.push_str(type_path); + sb.push_str("::"); + } + sb.push_str(self.type_name.as_str()); + } + + sb + } + + pub fn to_csharp_string(&self, options: &BindgenOptions) -> String { + 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 + "c_char" => "Byte", + "c_schar" => "SByte", + "c_uchar" => "Byte", + "c_short" => "Int16", + "c_ushort" => "UInt16", + "c_int" => "Int32", + "c_uint" => "UInt32", + "c_long" => &options.csharp_c_long_convert, + "c_ulong" => &options.csharp_c_ulong_convert, + "c_longlong" => "Int64", + "c_ulonglong" => "UInt64", + "c_float" => "Float", + "c_double" => "Double", + "c_void" => "void", + // rust primitives + "i8" => "SByte", + "i16" => "Int16", + "i32" => "Int32", + "i64" => "Int64", + "i128" => "Int128", // .NET 7 + "isize" => "IntPtr", + "u8" => "Byte", + "u16" => "UInt16", + "u32" => "UInt32", + "u64" => "UInt64", + "u128" => "UInt128", // .NET 7 + "f32" => "Float", + "f64" => "Double", + "bool" => "Boolean", + "usize" => "UIntPtr", + "()" => "void", // if type is parameter, can't use in C# + _ => type_name, // as is + }; + name.to_string() + } + + let mut sb = String::new(); + + if self.is_fixed_array { + sb.push_str("fixed "); + sb.push_str(convert_type_name(self.type_name.as_str(), &options).as_str()); + } else { + sb.push_str(convert_type_name(self.type_name.as_str(), &options).as_str()); + if self.is_pointer { + sb.push_str("*"); + } + if self.is_pointer_pointer { + sb.push_str("**"); + } + } + + sb + } +} + +impl std::fmt::Display for RustType { + fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { + write!(f, "{}", self.to_string("")) + } +} diff --git a/csbindgen/src/util.rs b/csbindgen/src/util.rs new file mode 100644 index 0000000..6f94e4c --- /dev/null +++ b/csbindgen/src/util.rs @@ -0,0 +1,10 @@ +pub trait PushStrLn { + fn push_str_ln(&mut self, string: &str); +} + +impl PushStrLn for String { + fn push_str_ln(&mut self, string: &str) { + self.push_str(string); + self.push('\n'); + } +} diff --git a/dotnet-sandbox/bindgen.cs b/dotnet-sandbox/bindgen.cs index 0572802..8385ad0 100644 --- a/dotnet-sandbox/bindgen.cs +++ b/dotnet-sandbox/bindgen.cs @@ -7,28 +7,10 @@ using System.Runtime.InteropServices; namespace Csbindgen { - using LZ4F_blockChecksum_t = Int32; - using LZ4F_blockMode_t = Int32; - using LZ4F_blockSizeID_t = Int32; - using LZ4F_cctx = LZ4F_cctx_s; - using LZ4F_compressionContext_t = LZ4F_cctx_s; - using LZ4F_contentChecksum_t = Int32; - using LZ4F_dctx = LZ4F_dctx_s; - using LZ4F_decompressionContext_t = LZ4F_dctx_s; - using LZ4F_errorCode_t = UIntPtr; - using LZ4F_frameType_t = Int32; using LZ4_byte = Byte; - using LZ4_i8 = SByte; using LZ4_streamDecode_t = LZ4_streamDecode_u; - using LZ4_streamHC_t = LZ4_streamHC_u; using LZ4_stream_t = LZ4_stream_u; - using LZ4_u16 = UInt16; using LZ4_u32 = UInt32; - using XXH32_hash_t = UInt32; - using XXH32_state_t = XXH32_state_s; - using XXH64_hash_t = UInt64; - using XXH64_state_t = XXH64_state_s; - using XXH_errorcode = Int32; public static unsafe partial class NativeMethods @@ -170,210 +152,6 @@ namespace Csbindgen [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] public static extern void csbindgen_LZ4_resetStream(LZ4_stream_t* streamPtr); - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compress_HC(Byte* src, Byte* dst, Int32 srcSize, Int32 dstCapacity, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_sizeofStateHC(); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compress_HC_extStateHC(void* stateHC, Byte* src, Byte* dst, Int32 srcSize, Int32 maxDstSize, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compress_HC_destSize(void* stateHC, Byte* src, Byte* dst, Int32* srcSizePtr, Int32 targetDstSize, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern LZ4_streamHC_t* csbindgen_LZ4_createStreamHC(); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_freeStreamHC(LZ4_streamHC_t* streamHCPtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern void csbindgen_LZ4_resetStreamHC_fast(LZ4_streamHC_t* streamHCPtr, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_loadDictHC(LZ4_streamHC_t* streamHCPtr, Byte* dictionary, Int32 dictSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compress_HC_continue(LZ4_streamHC_t* streamHCPtr, Byte* src, Byte* dst, Int32 srcSize, Int32 maxDstSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compress_HC_continue_destSize(LZ4_streamHC_t* LZ4_streamHCPtr, Byte* src, Byte* dst, Int32* srcSizePtr, Int32 targetDstSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_saveDictHC(LZ4_streamHC_t* streamHCPtr, Byte* safeBuffer, Int32 maxDictSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern LZ4_streamHC_t* csbindgen_LZ4_initStreamHC(void* buffer, UIntPtr size); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC(Byte* source, Byte* dest, Int32 inputSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC_limitedOutput(Byte* source, Byte* dest, Int32 inputSize, Int32 maxOutputSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC2(Byte* source, Byte* dest, Int32 inputSize, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC2_limitedOutput(Byte* source, Byte* dest, Int32 inputSize, Int32 maxOutputSize, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC_withStateHC(void* state, Byte* source, Byte* dest, Int32 inputSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC_limitedOutput_withStateHC(void* state, Byte* source, Byte* dest, Int32 inputSize, Int32 maxOutputSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC2_withStateHC(void* state, Byte* source, Byte* dest, Int32 inputSize, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC2_limitedOutput_withStateHC(void* state, Byte* source, Byte* dest, Int32 inputSize, Int32 maxOutputSize, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC_continue(LZ4_streamHC_t* LZ4_streamHCPtr, Byte* source, Byte* dest, Int32 inputSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC_limitedOutput_continue(LZ4_streamHC_t* LZ4_streamHCPtr, Byte* source, Byte* dest, Int32 inputSize, Int32 maxOutputSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern void* csbindgen_LZ4_createHC(Byte* inputBuffer); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_freeHC(void* LZ4HC_Data); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Byte* csbindgen_LZ4_slideInputBufferHC(void* LZ4HC_Data); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC2_continue(void* LZ4HC_Data, Byte* source, Byte* dest, Int32 inputSize, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_compressHC2_limitedOutput_continue(void* LZ4HC_Data, Byte* source, Byte* dest, Int32 inputSize, Int32 maxOutputSize, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_sizeofStreamStateHC(); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4_resetStreamStateHC(void* state, Byte* inputBuffer); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern void csbindgen_LZ4_resetStreamHC(LZ4_streamHC_t* streamHCPtr, Int32 compressionLevel); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UInt32 csbindgen_LZ4F_isError(LZ4F_errorCode_t code); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Byte* csbindgen_LZ4F_getErrorName(LZ4F_errorCode_t code); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern Int32 csbindgen_LZ4F_compressionLevel_max(); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_compressFrameBound(UIntPtr srcSize, LZ4F_preferences_t* preferencesPtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_compressFrame(void* dstBuffer, UIntPtr dstCapacity, void* srcBuffer, UIntPtr srcSize, LZ4F_preferences_t* preferencesPtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UInt32 csbindgen_LZ4F_getVersion(); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern LZ4F_errorCode_t csbindgen_LZ4F_createCompressionContext(LZ4F_cctx** cctxPtr, UInt32 version); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern LZ4F_errorCode_t csbindgen_LZ4F_freeCompressionContext(LZ4F_cctx* cctx); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_compressBegin(LZ4F_cctx* cctx, void* dstBuffer, UIntPtr dstCapacity, LZ4F_preferences_t* prefsPtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_compressBound(UIntPtr srcSize, LZ4F_preferences_t* prefsPtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_compressUpdate(LZ4F_cctx* cctx, void* dstBuffer, UIntPtr dstCapacity, void* srcBuffer, UIntPtr srcSize, LZ4F_compressOptions_t* cOptPtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_flush(LZ4F_cctx* cctx, void* dstBuffer, UIntPtr dstCapacity, LZ4F_compressOptions_t* cOptPtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_compressEnd(LZ4F_cctx* cctx, void* dstBuffer, UIntPtr dstCapacity, LZ4F_compressOptions_t* cOptPtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern LZ4F_errorCode_t csbindgen_LZ4F_createDecompressionContext(LZ4F_dctx** dctxPtr, UInt32 version); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern LZ4F_errorCode_t csbindgen_LZ4F_freeDecompressionContext(LZ4F_dctx* dctx); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_headerSize(void* src, UIntPtr srcSize); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_getFrameInfo(LZ4F_dctx* dctx, LZ4F_frameInfo_t* frameInfoPtr, void* srcBuffer, UIntPtr* srcSizePtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UIntPtr csbindgen_LZ4F_decompress(LZ4F_dctx* dctx, void* dstBuffer, UIntPtr* dstSizePtr, void* srcBuffer, UIntPtr* srcSizePtr, LZ4F_decompressOptions_t* dOptPtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern void csbindgen_LZ4F_resetDecompressionContext(LZ4F_dctx* dctx); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern UInt32 csbindgen_XXH_versionNumber(); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH32_hash_t csbindgen_XXH32(void* input, UIntPtr length, UInt32 seed); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH32_state_t* csbindgen_XXH32_createState(); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH_errorcode csbindgen_XXH32_freeState(XXH32_state_t* statePtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern void csbindgen_XXH32_copyState(XXH32_state_t* dst_state, XXH32_state_t* src_state); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH_errorcode csbindgen_XXH32_reset(XXH32_state_t* statePtr, UInt32 seed); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH_errorcode csbindgen_XXH32_update(XXH32_state_t* statePtr, void* input, UIntPtr length); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH32_hash_t csbindgen_XXH32_digest(XXH32_state_t* statePtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern void csbindgen_XXH32_canonicalFromHash(XXH32_canonical_t* dst, XXH32_hash_t hash); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH32_hash_t csbindgen_XXH32_hashFromCanonical(XXH32_canonical_t* src); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH64_hash_t csbindgen_XXH64(void* input, UIntPtr length, UInt64 seed); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH64_state_t* csbindgen_XXH64_createState(); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH_errorcode csbindgen_XXH64_freeState(XXH64_state_t* statePtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern void csbindgen_XXH64_copyState(XXH64_state_t* dst_state, XXH64_state_t* src_state); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH_errorcode csbindgen_XXH64_reset(XXH64_state_t* statePtr, UInt64 seed); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH_errorcode csbindgen_XXH64_update(XXH64_state_t* statePtr, void* input, UIntPtr length); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH64_hash_t csbindgen_XXH64_digest(XXH64_state_t* statePtr); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern void csbindgen_XXH64_canonicalFromHash(XXH64_canonical_t* dst, XXH64_hash_t hash); - - [DllImport(__DllName, CallingConvention = CallingConvention.Cdecl)] - public static extern XXH64_hash_t csbindgen_XXH64_hashFromCanonical(XXH64_canonical_t* src); - } @@ -415,106 +193,6 @@ namespace Csbindgen public LZ4_streamDecode_t_internal internal_donotuse; } - [StructLayout(LayoutKind.Sequential)] - public unsafe struct LZ4HC_CCtx_internal - { - public fixed LZ4_u32 hashTable[32768]; - public fixed LZ4_u16 chainTable[65536]; - public LZ4_byte* end; - public LZ4_byte* prefixStart; - public LZ4_byte* dictStart; - public LZ4_u32 dictLimit; - public LZ4_u32 lowLimit; - public LZ4_u32 nextToUpdate; - public Int16 compressionLevel; - public LZ4_i8 favorDecSpeed; - public LZ4_i8 dirty; - public LZ4HC_CCtx_internal* dictCtx; - } - - [StructLayout(LayoutKind.Explicit)] - public unsafe struct LZ4_streamHC_u - { - [FieldOffset(0)] - public fixed Byte minStateSize[262200]; - [FieldOffset(0)] - public LZ4HC_CCtx_internal internal_donotuse; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct LZ4F_frameInfo_t - { - public LZ4F_blockSizeID_t blockSizeID; - public LZ4F_blockMode_t blockMode; - public LZ4F_contentChecksum_t contentChecksumFlag; - public LZ4F_frameType_t frameType; - public UInt64 contentSize; - public UInt32 dictID; - public LZ4F_blockChecksum_t blockChecksumFlag; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct LZ4F_preferences_t - { - public LZ4F_frameInfo_t frameInfo; - public Int32 compressionLevel; - public UInt32 autoFlush; - public UInt32 favorDecSpeed; - public fixed UInt32 reserved[3]; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct LZ4F_cctx_s - { - public fixed Byte _unused[1]; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct LZ4F_compressOptions_t - { - public UInt32 stableSrc; - public fixed UInt32 reserved[3]; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct LZ4F_dctx_s - { - public fixed Byte _unused[1]; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct LZ4F_decompressOptions_t - { - public UInt32 stableDst; - public UInt32 skipChecksums; - public UInt32 reserved1; - public UInt32 reserved0; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct XXH32_state_s - { - public fixed Byte _unused[1]; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct XXH32_canonical_t - { - public fixed Byte digest[4]; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct XXH64_state_s - { - public fixed Byte _unused[1]; - } - - [StructLayout(LayoutKind.Sequential)] - public unsafe struct XXH64_canonical_t - { - public fixed Byte digest[8]; - } - } \ No newline at end of file