From 8e47cd17a57e41b1418bfe237001f019da9393d8 Mon Sep 17 00:00:00 2001 From: Alexandre Bury Date: Tue, 4 Jul 2017 19:48:12 -0700 Subject: [PATCH] Fix for bindgen 0.26 --- Cargo.toml | 4 +- zstd-safe/Cargo.toml | 4 +- zstd-safe/src/lib.rs | 4 +- zstd-safe/zstd-sys/Cargo.toml | 4 +- zstd-safe/zstd-sys/build.rs | 1 - zstd-safe/zstd-sys/src/bindings.rs | 1516 +++++++++++++++------------- zstd-safe/zstd-sys/zstd.h | 2 +- 7 files changed, 829 insertions(+), 706 deletions(-) diff --git a/Cargo.toml b/Cargo.toml index 927996bd..57c792a7 100644 --- a/Cargo.toml +++ b/Cargo.toml @@ -7,7 +7,7 @@ categories = ["compression", "api-bindings"] license = "MIT" name = "zstd" repository = "https://github.com/gyscos/zstd-rs" -version = "0.4.12" +version = "0.4.13" exclude = ["assets"] readme = "Readme.md" @@ -16,7 +16,7 @@ travis-ci = { repository = "gyscos/zstd-rs" } [dependencies] libc = "0.2" -zstd-safe = { path="zstd-safe", version = "1.3.0", default-features = false } +zstd-safe = { path="zstd-safe", version = "1.3.1", default-features = false } tokio-io = { version = "0.1", optional = true } futures = { version = "0.1", optional = true } diff --git a/zstd-safe/Cargo.toml b/zstd-safe/Cargo.toml index adf083e8..99651564 100644 --- a/zstd-safe/Cargo.toml +++ b/zstd-safe/Cargo.toml @@ -1,7 +1,7 @@ [package] authors = ["Alexandre Bury "] name = "zstd-safe" -version = "1.3.0" +version = "1.3.1" description = "Safe low-level bindings for the zstd compression library." keywords = ["zstd", "zstandard", "compression"] categories = ["api-bindings", "compression"] @@ -10,7 +10,7 @@ license = "MIT/Apache-2.0" readme = "Readme.md" [dependencies] -zstd-sys = { path="zstd-sys", version = "1.3.0", default-features = false } +zstd-sys = { path="zstd-sys", version = "1.3.1", default-features = false } libc = "0.2.21" [features] diff --git a/zstd-safe/src/lib.rs b/zstd-safe/src/lib.rs index c24bd2a1..8f7d3b2b 100644 --- a/zstd-safe/src/lib.rs +++ b/zstd-safe/src/lib.rs @@ -830,8 +830,8 @@ pub fn train_from_buffer(dict_buffer: &mut [u8], samples_buffer: &[u8], samples_sizes.len() as u32) } } -pub fn get_block_size_max(cctx: &mut CCtx) -> usize { - unsafe { zstd_sys::ZSTD_getBlockSizeMax(cctx.0) } +pub fn get_block_size(cctx: &mut CCtx) -> usize { + unsafe { zstd_sys::ZSTD_getBlockSize(cctx.0) } } pub fn compress_block(cctx: &mut CCtx, dst: &mut [u8], src: &[u8]) -> usize { unsafe { diff --git a/zstd-safe/zstd-sys/Cargo.toml b/zstd-safe/zstd-sys/Cargo.toml index 584f040e..511177ff 100644 --- a/zstd-safe/zstd-sys/Cargo.toml +++ b/zstd-safe/zstd-sys/Cargo.toml @@ -2,7 +2,7 @@ authors = ["Alexandre Bury "] name = "zstd-sys" build = "build.rs" -version = "1.3.0" +version = "1.3.1" description = "Low-level bindings for the zstd compression library." keywords = ["zstd", "zstandard", "compression"] categories = ["api-bindings", "compression"] @@ -12,7 +12,7 @@ readme = "Readme.md" [build-dependencies] bindgen = { version = "0.26", optional = true } -gcc = "0.3.45" +gcc = "0.3.51" glob = "0.2.11" [dependencies] diff --git a/zstd-safe/zstd-sys/build.rs b/zstd-safe/zstd-sys/build.rs index 3420c781..56003614 100644 --- a/zstd-safe/zstd-sys/build.rs +++ b/zstd-safe/zstd-sys/build.rs @@ -11,7 +11,6 @@ fn generate_bindings() { use std::path::PathBuf; let bindings = bindgen::Builder::default() - .no_unstable_rust() .header("zstd.h") .generate_comments(false) //< remove this when it works .hide_type("max_align_t") diff --git a/zstd-safe/zstd-sys/src/bindings.rs b/zstd-safe/zstd-sys/src/bindings.rs index f0d71d19..4bf53738 100644 --- a/zstd-safe/zstd-sys/src/bindings.rs +++ b/zstd-safe/zstd-sys/src/bindings.rs @@ -1,13 +1,14 @@ /* automatically generated by rust-bindgen */ pub const ZSTD_VERSION_MAJOR: ::libc::c_uint = 1; -pub const ZSTD_VERSION_MINOR: ::libc::c_uint = 2; +pub const ZSTD_VERSION_MINOR: ::libc::c_uint = 3; pub const ZSTD_VERSION_RELEASE: ::libc::c_uint = 0; -pub const ZSTD_VERSION_NUMBER: ::libc::c_uint = 10200; -pub const ZSTD_MAGICNUMBER: ::libc::c_uint = 4247762216; -pub const ZSTD_MAGIC_SKIPPABLE_START: ::libc::c_uint = 407710288; +pub const ZSTD_VERSION_NUMBER: ::libc::c_uint = 10300; pub const ZSTD_CONTENTSIZE_UNKNOWN: ::libc::c_int = -1; pub const ZSTD_CONTENTSIZE_ERROR: ::libc::c_int = -2; +pub const ZSTD_MAGICNUMBER: ::libc::c_uint = 4247762216; +pub const ZSTD_MAGIC_SKIPPABLE_START: ::libc::c_uint = 407710288; +pub const ZSTD_MAGIC_DICTIONARY: ::libc::c_uint = 3962610743; pub const ZSTD_WINDOWLOG_MAX_32: ::libc::c_uint = 27; pub const ZSTD_WINDOWLOG_MAX_64: ::libc::c_uint = 27; pub const ZSTD_WINDOWLOG_MIN: ::libc::c_uint = 10; @@ -21,65 +22,55 @@ pub const ZSTD_TARGETLENGTH_MIN: ::libc::c_uint = 4; pub const ZSTD_TARGETLENGTH_MAX: ::libc::c_uint = 999; pub const ZSTD_FRAMEHEADERSIZE_MAX: ::libc::c_uint = 18; pub const ZSTD_FRAMEHEADERSIZE_MIN: ::libc::c_uint = 6; -pub const ZSTD_BLOCKSIZE_ABSOLUTEMAX: ::libc::c_uint = 131072; +pub const ZSTD_BLOCKSIZELOG_MAX: ::libc::c_uint = 17; +pub const ZSTD_BLOCKSIZE_MAX: ::libc::c_uint = 131072; pub type wchar_t = ::libc::c_int; extern "C" { pub fn ZSTD_versionNumber() -> ::libc::c_uint; } +extern "C" { + pub fn ZSTD_versionString() -> *const ::libc::c_char; +} extern "C" { /*************************************** - * Simple API - ***************************************/ - /** ZSTD_compress() : - * Compresses `src` content as a single zstd compressed frame into already allocated `dst`. - * Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`. - * @return : compressed size written into `dst` (<= `dstCapacity), - * or an error code if it fails (which can be tested using ZSTD_isError()). */ +* Simple API +***************************************/ +/*! ZSTD_compress() : + * Compresses `src` content as a single zstd compressed frame into already allocated `dst`. + * Hint : compression runs faster if `dstCapacity` >= `ZSTD_compressBound(srcSize)`. + * @return : compressed size written into `dst` (<= `dstCapacity), + * or an error code if it fails (which can be tested using ZSTD_isError()). */ pub fn ZSTD_compress(dst: *mut ::libc::c_void, dstCapacity: usize, src: *const ::libc::c_void, srcSize: usize, - compressionLevel: ::libc::c_int) - -> usize; + compressionLevel: ::libc::c_int) -> usize; } extern "C" { - /** ZSTD_decompress() : - * `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames. - * `dstCapacity` is an upper bound of originalSize. - * If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data. - * @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), - * or an errorCode if it fails (which can be tested using ZSTD_isError()). */ + /*! ZSTD_decompress() : + * `compressedSize` : must be the _exact_ size of some number of compressed and/or skippable frames. + * `dstCapacity` is an upper bound of originalSize to regenerate. + * If user cannot imply a maximum upper bound, it's better to use streaming mode to decompress data. + * @return : the number of bytes decompressed into `dst` (<= `dstCapacity`), + * or an errorCode if it fails (which can be tested using ZSTD_isError()). */ pub fn ZSTD_decompress(dst: *mut ::libc::c_void, dstCapacity: usize, src: *const ::libc::c_void, compressedSize: usize) - -> usize; -} -extern "C" { - /** ZSTD_getDecompressedSize() : - * NOTE: This function is planned to be obsolete, in favour of ZSTD_getFrameContentSize. - * ZSTD_getFrameContentSize functions the same way, returning the decompressed size of a single - * frame, but distinguishes empty frames from frames with an unknown size, or errors. - * - * Additionally, ZSTD_findDecompressedSize can be used instead. It can handle multiple - * concatenated frames in one buffer, and so is more general. - * As a result however, it requires more computation and entire frames to be passed to it, - * as opposed to ZSTD_getFrameContentSize which requires only a single frame's header. - * - * 'src' is the start of a zstd compressed frame. - * @return : content size to be decompressed, as a 64-bits value _if known_, 0 otherwise. - * note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode. - * When `return==0`, data to decompress could be any size. - * In which case, it's necessary to use streaming mode to decompress data. - * Optionally, application can still use ZSTD_decompress() while relying on implied limits. - * (For example, data may be necessarily cut into blocks <= 16 KB). - * note 2 : decompressed size is always present when compression is done with ZSTD_compress() - * note 3 : decompressed size can be very large (64-bits value), - * potentially larger than what local system can handle as a single memory segment. - * In which case, it's necessary to use streaming mode to decompress data. - * note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified. - * Always ensure result fits within application's authorized limits. - * Each application can set its own limits. - * note 5 : when `return==0`, if precise failure cause is needed, use ZSTD_getFrameParams() to know more. */ + -> usize; +} +extern "C" { + pub fn ZSTD_getFrameContentSize(src: *const ::libc::c_void, + srcSize: usize) -> ::libc::c_ulonglong; +} +extern "C" { + /*! ZSTD_getDecompressedSize() : + * NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize(). + * Both functions work the same way, + * but ZSTD_getDecompressedSize() blends + * "empty", "unknown" and "error" results in the same return value (0), + * while ZSTD_getFrameContentSize() distinguishes them. + * + * 'src' is the start of a zstd compressed frame. + * @return : content size to be decompressed, as a 64-bits value _if known and not empty_, 0 otherwise. */ pub fn ZSTD_getDecompressedSize(src: *const ::libc::c_void, - srcSize: usize) - -> ::libc::c_ulonglong; + srcSize: usize) -> ::libc::c_ulonglong; } extern "C" { pub fn ZSTD_maxCLevel() -> ::libc::c_int; @@ -109,12 +100,12 @@ extern "C" { pub fn ZSTD_freeCCtx(cctx: *mut ZSTD_CCtx) -> usize; } extern "C" { - /** ZSTD_compressCCtx() : - * Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). */ + /*! ZSTD_compressCCtx() : + * Same as ZSTD_compress(), requires an allocated ZSTD_CCtx (see ZSTD_createCCtx()). */ pub fn ZSTD_compressCCtx(ctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void, dstCapacity: usize, src: *const ::libc::c_void, srcSize: usize, compressionLevel: ::libc::c_int) - -> usize; + -> usize; } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -129,82 +120,78 @@ extern "C" { pub fn ZSTD_freeDCtx(dctx: *mut ZSTD_DCtx) -> usize; } extern "C" { - /** ZSTD_decompressDCtx() : - * Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()). */ - pub fn ZSTD_decompressDCtx(ctx: *mut ZSTD_DCtx, - dst: *mut ::libc::c_void, dstCapacity: usize, - src: *const ::libc::c_void, srcSize: usize) - -> usize; + /*! ZSTD_decompressDCtx() : + * Same as ZSTD_decompress(), requires an allocated ZSTD_DCtx (see ZSTD_createDCtx()) */ + pub fn ZSTD_decompressDCtx(ctx: *mut ZSTD_DCtx, dst: *mut ::libc::c_void, + dstCapacity: usize, src: *const ::libc::c_void, + srcSize: usize) -> usize; } extern "C" { /************************** - * Simple dictionary API - ***************************/ - /** ZSTD_compress_usingDict() : - * Compression using a predefined Dictionary (see dictBuilder/zdict.h). - * Note : This function loads the dictionary, resulting in significant startup delay. - * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ +* Simple dictionary API +***************************/ +/*! ZSTD_compress_usingDict() : + * Compression using a predefined Dictionary (see dictBuilder/zdict.h). + * Note : This function loads the dictionary, resulting in significant startup delay. + * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ pub fn ZSTD_compress_usingDict(ctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void, dstCapacity: usize, - src: *const ::libc::c_void, - srcSize: usize, + src: *const ::libc::c_void, srcSize: usize, dict: *const ::libc::c_void, dictSize: usize, - compressionLevel: ::libc::c_int) - -> usize; + compressionLevel: ::libc::c_int) -> usize; } extern "C" { - /** ZSTD_decompress_usingDict() : - * Decompression using a predefined Dictionary (see dictBuilder/zdict.h). - * Dictionary must be identical to the one used during compression. - * Note : This function loads the dictionary, resulting in significant startup delay. - * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ + /*! ZSTD_decompress_usingDict() : + * Decompression using a predefined Dictionary (see dictBuilder/zdict.h). + * Dictionary must be identical to the one used during compression. + * Note : This function loads the dictionary, resulting in significant startup delay. + * Note : When `dict == NULL || dictSize < 8` no dictionary is used. */ pub fn ZSTD_decompress_usingDict(dctx: *mut ZSTD_DCtx, dst: *mut ::libc::c_void, dstCapacity: usize, src: *const ::libc::c_void, srcSize: usize, dict: *const ::libc::c_void, - dictSize: usize) - -> usize; + dictSize: usize) -> usize; } #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ZSTD_CDict_s { _unused: [u8; 0], } -/**************************** -* Fast dictionary API -****************************/ +/********************************** + * Bulk processing dictionary API + *********************************/ pub type ZSTD_CDict = ZSTD_CDict_s; extern "C" { - /** ZSTD_createCDict() : - * When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. - * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. - * ZSTD_CDict can be created once and used by multiple threads concurrently, as its usage is read-only. - * `dictBuffer` can be released after ZSTD_CDict creation, as its content is copied within CDict */ + /*! ZSTD_createCDict() : + * When compressing multiple messages / blocks with the same dictionary, it's recommended to load it just once. + * ZSTD_createCDict() will create a digested dictionary, ready to start future compression operations without startup delay. + * ZSTD_CDict can be created once and shared by multiple threads concurrently, since its usage is read-only. + * `dictBuffer` can be released after ZSTD_CDict creation, since its content is copied within CDict */ pub fn ZSTD_createCDict(dictBuffer: *const ::libc::c_void, dictSize: usize, compressionLevel: ::libc::c_int) - -> *mut ZSTD_CDict; + -> *mut ZSTD_CDict; } extern "C" { - /** ZSTD_freeCDict() : - * Function frees memory allocated by ZSTD_createCDict(). */ + /*! ZSTD_freeCDict() : + * Function frees memory allocated by ZSTD_createCDict(). */ pub fn ZSTD_freeCDict(CDict: *mut ZSTD_CDict) -> usize; } extern "C" { - /** ZSTD_compress_usingCDict() : - * Compression using a digested Dictionary. - * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. - * Note that compression level is decided during dictionary creation. - * Frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no) */ + /*! ZSTD_compress_usingCDict() : + * Compression using a digested Dictionary. + * Faster startup than ZSTD_compress_usingDict(), recommended when same dictionary is used multiple times. + * Note that compression level is decided during dictionary creation. + * Frame parameters are hardcoded (dictID=yes, contentSize=yes, checksum=no) */ pub fn ZSTD_compress_usingCDict(cctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void, dstCapacity: usize, src: *const ::libc::c_void, srcSize: usize, cdict: *const ZSTD_CDict) - -> usize; + -> usize; } #[repr(C)] #[derive(Debug, Copy, Clone)] @@ -213,29 +200,27 @@ pub struct ZSTD_DDict_s { } pub type ZSTD_DDict = ZSTD_DDict_s; extern "C" { - /** ZSTD_createDDict() : - * Create a digested dictionary, ready to start decompression operation without startup delay. - * dictBuffer can be released after DDict creation, as its content is copied inside DDict */ + /*! ZSTD_createDDict() : + * Create a digested dictionary, ready to start decompression operation without startup delay. + * dictBuffer can be released after DDict creation, as its content is copied inside DDict */ pub fn ZSTD_createDDict(dictBuffer: *const ::libc::c_void, - dictSize: usize) - -> *mut ZSTD_DDict; + dictSize: usize) -> *mut ZSTD_DDict; } extern "C" { - /** ZSTD_freeDDict() : - * Function frees memory allocated with ZSTD_createDDict() */ + /*! ZSTD_freeDDict() : + * Function frees memory allocated with ZSTD_createDDict() */ pub fn ZSTD_freeDDict(ddict: *mut ZSTD_DDict) -> usize; } extern "C" { - /** ZSTD_decompress_usingDDict() : - * Decompression using a digested Dictionary. - * Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times. */ + /*! ZSTD_decompress_usingDDict() : + * Decompression using a digested Dictionary. + * Faster startup than ZSTD_decompress_usingDict(), recommended when same dictionary is used multiple times. */ pub fn ZSTD_decompress_usingDDict(dctx: *mut ZSTD_DCtx, dst: *mut ::libc::c_void, dstCapacity: usize, src: *const ::libc::c_void, srcSize: usize, - ddict: *const ZSTD_DDict) - -> usize; + ddict: *const ZSTD_DDict) -> usize; } /**************************** * Streaming @@ -252,41 +237,28 @@ pub struct ZSTD_inBuffer_s { } #[test] fn bindgen_test_layout_ZSTD_inBuffer_s() { - assert_eq!(::core::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ZSTD_inBuffer_s))); - assert_eq!(::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ZSTD_inBuffer_s))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_inBuffer_s)).src as *const _ as usize - }, - 0usize, - concat!("Alignment of field: ", - stringify!(ZSTD_inBuffer_s), - "::", - stringify!(src))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_inBuffer_s)).size as *const _ as usize - }, - 8usize, - concat!("Alignment of field: ", - stringify!(ZSTD_inBuffer_s), - "::", - stringify!(size))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_inBuffer_s)).pos as *const _ as usize - }, - 16usize, - concat!("Alignment of field: ", - stringify!(ZSTD_inBuffer_s), - "::", - stringify!(pos))); + assert_eq!(::core::mem::size_of::() , 24usize , concat ! + ( "Size of: " , stringify ! ( ZSTD_inBuffer_s ) )); + assert_eq! (::core::mem::align_of::() , 8usize , concat ! + ( "Alignment of " , stringify ! ( ZSTD_inBuffer_s ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_inBuffer_s ) ) . src as * const _ as + usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_inBuffer_s ) , + "::" , stringify ! ( src ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_inBuffer_s ) ) . size as * const _ + as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_inBuffer_s ) , + "::" , stringify ! ( size ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_inBuffer_s ) ) . pos as * const _ as + usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_inBuffer_s ) , + "::" , stringify ! ( pos ) )); } impl Clone for ZSTD_inBuffer_s { - fn clone(&self) -> Self { - *self - } + fn clone(&self) -> Self { *self } } pub type ZSTD_inBuffer = ZSTD_inBuffer_s; #[repr(C)] @@ -301,49 +273,31 @@ pub struct ZSTD_outBuffer_s { } #[test] fn bindgen_test_layout_ZSTD_outBuffer_s() { - assert_eq!(::core::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ZSTD_outBuffer_s))); - assert_eq!(::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ZSTD_outBuffer_s))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_outBuffer_s)).dst as *const _ as usize - }, - 0usize, - concat!("Alignment of field: ", - stringify!(ZSTD_outBuffer_s), - "::", - stringify!(dst))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_outBuffer_s)).size as *const _ as usize - }, - 8usize, - concat!("Alignment of field: ", - stringify!(ZSTD_outBuffer_s), - "::", - stringify!(size))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_outBuffer_s)).pos as *const _ as usize - }, - 16usize, - concat!("Alignment of field: ", - stringify!(ZSTD_outBuffer_s), - "::", - stringify!(pos))); + assert_eq!(::core::mem::size_of::() , 24usize , concat ! + ( "Size of: " , stringify ! ( ZSTD_outBuffer_s ) )); + assert_eq! (::core::mem::align_of::() , 8usize , concat + ! ( "Alignment of " , stringify ! ( ZSTD_outBuffer_s ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_outBuffer_s ) ) . dst as * const _ + as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_outBuffer_s ) , + "::" , stringify ! ( dst ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_outBuffer_s ) ) . size as * const _ + as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_outBuffer_s ) , + "::" , stringify ! ( size ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_outBuffer_s ) ) . pos as * const _ + as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_outBuffer_s ) , + "::" , stringify ! ( pos ) )); } impl Clone for ZSTD_outBuffer_s { - fn clone(&self) -> Self { - *self - } + fn clone(&self) -> Self { *self } } pub type ZSTD_outBuffer = ZSTD_outBuffer_s; -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ZSTD_CStream_s { - _unused: [u8; 0], -} -pub type ZSTD_CStream = ZSTD_CStream_s; +pub type ZSTD_CStream = ZSTD_CCtx; extern "C" { pub fn ZSTD_createCStream() -> *mut ZSTD_CStream; } @@ -352,24 +306,20 @@ extern "C" { } extern "C" { pub fn ZSTD_initCStream(zcs: *mut ZSTD_CStream, - compressionLevel: ::libc::c_int) - -> usize; + compressionLevel: ::libc::c_int) -> usize; } extern "C" { pub fn ZSTD_compressStream(zcs: *mut ZSTD_CStream, output: *mut ZSTD_outBuffer, - input: *mut ZSTD_inBuffer) - -> usize; + input: *mut ZSTD_inBuffer) -> usize; } extern "C" { pub fn ZSTD_flushStream(zcs: *mut ZSTD_CStream, - output: *mut ZSTD_outBuffer) - -> usize; + output: *mut ZSTD_outBuffer) -> usize; } extern "C" { - pub fn ZSTD_endStream(zcs: *mut ZSTD_CStream, - output: *mut ZSTD_outBuffer) - -> usize; + pub fn ZSTD_endStream(zcs: *mut ZSTD_CStream, output: *mut ZSTD_outBuffer) + -> usize; } extern "C" { pub fn ZSTD_CStreamInSize() -> usize; @@ -377,12 +327,7 @@ extern "C" { extern "C" { pub fn ZSTD_CStreamOutSize() -> usize; } -#[repr(C)] -#[derive(Debug, Copy, Clone)] -pub struct ZSTD_DStream_s { - _unused: [u8; 0], -} -pub type ZSTD_DStream = ZSTD_DStream_s; +pub type ZSTD_DStream = ZSTD_DCtx; extern "C" { pub fn ZSTD_createDStream() -> *mut ZSTD_DStream; } @@ -395,8 +340,7 @@ extern "C" { extern "C" { pub fn ZSTD_decompressStream(zds: *mut ZSTD_DStream, output: *mut ZSTD_outBuffer, - input: *mut ZSTD_inBuffer) - -> usize; + input: *mut ZSTD_inBuffer) -> usize; } extern "C" { pub fn ZSTD_DStreamInSize() -> usize; @@ -405,20 +349,20 @@ extern "C" { pub fn ZSTD_DStreamOutSize() -> usize; } pub const ZSTD_frameHeaderSize_prefix: usize = 5; -pub const ZSTD_frameHeaderSize_min: usize = 6; pub const ZSTD_frameHeaderSize_max: usize = 18; +pub const ZSTD_frameHeaderSize_min: usize = 6; pub const ZSTD_skippableHeaderSize: usize = 8; #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_strategy { - ZSTD_fast = 0, - ZSTD_dfast = 1, - ZSTD_greedy = 2, - ZSTD_lazy = 3, - ZSTD_lazy2 = 4, - ZSTD_btlazy2 = 5, - ZSTD_btopt = 6, - ZSTD_btopt2 = 7, + ZSTD_fast = 1, + ZSTD_dfast = 2, + ZSTD_greedy = 3, + ZSTD_lazy = 4, + ZSTD_lazy2 = 5, + ZSTD_btlazy2 = 6, + ZSTD_btopt = 7, + ZSTD_btultra = 8, } #[repr(C)] #[derive(Debug, Copy)] @@ -439,81 +383,58 @@ pub struct ZSTD_compressionParameters { } #[test] fn bindgen_test_layout_ZSTD_compressionParameters() { - assert_eq!(::core::mem::size_of::(), - 28usize, - concat!("Size of: ", stringify!(ZSTD_compressionParameters))); - assert_eq!(::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", - stringify!(ZSTD_compressionParameters))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_compressionParameters)).windowLog as - *const _ as usize - }, - 0usize, - concat!("Alignment of field: ", - stringify!(ZSTD_compressionParameters), - "::", - stringify!(windowLog))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_compressionParameters)).chainLog as - *const _ as usize - }, - 4usize, - concat!("Alignment of field: ", - stringify!(ZSTD_compressionParameters), - "::", - stringify!(chainLog))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_compressionParameters)).hashLog as - *const _ as usize - }, - 8usize, - concat!("Alignment of field: ", - stringify!(ZSTD_compressionParameters), - "::", - stringify!(hashLog))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_compressionParameters)).searchLog as - *const _ as usize - }, - 12usize, - concat!("Alignment of field: ", - stringify!(ZSTD_compressionParameters), - "::", - stringify!(searchLog))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_compressionParameters)).searchLength as - *const _ as usize - }, - 16usize, - concat!("Alignment of field: ", - stringify!(ZSTD_compressionParameters), - "::", - stringify!(searchLength))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_compressionParameters)).targetLength as - *const _ as usize - }, - 20usize, - concat!("Alignment of field: ", - stringify!(ZSTD_compressionParameters), - "::", - stringify!(targetLength))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_compressionParameters)).strategy as - *const _ as usize - }, - 24usize, - concat!("Alignment of field: ", - stringify!(ZSTD_compressionParameters), - "::", - stringify!(strategy))); + assert_eq!(::core::mem::size_of::() , 28usize + , concat ! ( + "Size of: " , stringify ! ( ZSTD_compressionParameters ) )); + assert_eq! (::core::mem::align_of::() , 4usize + , concat ! ( + "Alignment of " , stringify ! ( ZSTD_compressionParameters ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_compressionParameters ) ) . + windowLog as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( + ZSTD_compressionParameters ) , "::" , stringify ! ( windowLog + ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_compressionParameters ) ) . chainLog + as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( + ZSTD_compressionParameters ) , "::" , stringify ! ( chainLog ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_compressionParameters ) ) . hashLog + as * const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( + ZSTD_compressionParameters ) , "::" , stringify ! ( hashLog ) + )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_compressionParameters ) ) . + searchLog as * const _ as usize } , 12usize , concat ! ( + "Alignment of field: " , stringify ! ( + ZSTD_compressionParameters ) , "::" , stringify ! ( searchLog + ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_compressionParameters ) ) . + searchLength as * const _ as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( + ZSTD_compressionParameters ) , "::" , stringify ! ( + searchLength ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_compressionParameters ) ) . + targetLength as * const _ as usize } , 20usize , concat ! ( + "Alignment of field: " , stringify ! ( + ZSTD_compressionParameters ) , "::" , stringify ! ( + targetLength ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_compressionParameters ) ) . strategy + as * const _ as usize } , 24usize , concat ! ( + "Alignment of field: " , stringify ! ( + ZSTD_compressionParameters ) , "::" , stringify ! ( strategy ) + )); } impl Clone for ZSTD_compressionParameters { - fn clone(&self) -> Self { - *self - } + fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] @@ -527,44 +448,30 @@ pub struct ZSTD_frameParameters { } #[test] fn bindgen_test_layout_ZSTD_frameParameters() { - assert_eq!(::core::mem::size_of::(), - 12usize, - concat!("Size of: ", stringify!(ZSTD_frameParameters))); - assert_eq!(::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ZSTD_frameParameters))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_frameParameters)).contentSizeFlag as - *const _ as usize - }, - 0usize, - concat!("Alignment of field: ", - stringify!(ZSTD_frameParameters), - "::", - stringify!(contentSizeFlag))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_frameParameters)).checksumFlag as - *const _ as usize - }, - 4usize, - concat!("Alignment of field: ", - stringify!(ZSTD_frameParameters), - "::", - stringify!(checksumFlag))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_frameParameters)).noDictIDFlag as - *const _ as usize - }, - 8usize, - concat!("Alignment of field: ", - stringify!(ZSTD_frameParameters), - "::", - stringify!(noDictIDFlag))); + assert_eq!(::core::mem::size_of::() , 12usize , + concat ! ( "Size of: " , stringify ! ( ZSTD_frameParameters ) + )); + assert_eq! (::core::mem::align_of::() , 4usize , + concat ! ( + "Alignment of " , stringify ! ( ZSTD_frameParameters ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_frameParameters ) ) . + contentSizeFlag as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_frameParameters ) + , "::" , stringify ! ( contentSizeFlag ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_frameParameters ) ) . checksumFlag + as * const _ as usize } , 4usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_frameParameters ) + , "::" , stringify ! ( checksumFlag ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_frameParameters ) ) . noDictIDFlag + as * const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_frameParameters ) + , "::" , stringify ! ( noDictIDFlag ) )); } impl Clone for ZSTD_frameParameters { - fn clone(&self) -> Self { - *self - } + fn clone(&self) -> Self { *self } } #[repr(C)] #[derive(Debug, Copy)] @@ -574,43 +481,70 @@ pub struct ZSTD_parameters { } #[test] fn bindgen_test_layout_ZSTD_parameters() { - assert_eq!(::core::mem::size_of::(), - 40usize, - concat!("Size of: ", stringify!(ZSTD_parameters))); - assert_eq!(::core::mem::align_of::(), - 4usize, - concat!("Alignment of ", stringify!(ZSTD_parameters))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_parameters)).cParams as *const _ as - usize - }, - 0usize, - concat!("Alignment of field: ", - stringify!(ZSTD_parameters), - "::", - stringify!(cParams))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_parameters)).fParams as *const _ as - usize - }, - 28usize, - concat!("Alignment of field: ", - stringify!(ZSTD_parameters), - "::", - stringify!(fParams))); + assert_eq!(::core::mem::size_of::() , 40usize , concat ! + ( "Size of: " , stringify ! ( ZSTD_parameters ) )); + assert_eq! (::core::mem::align_of::() , 4usize , concat ! + ( "Alignment of " , stringify ! ( ZSTD_parameters ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_parameters ) ) . cParams as * const + _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_parameters ) , + "::" , stringify ! ( cParams ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_parameters ) ) . fParams as * const + _ as usize } , 28usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_parameters ) , + "::" , stringify ! ( fParams ) )); } impl Clone for ZSTD_parameters { - fn clone(&self) -> Self { - *self - } + fn clone(&self) -> Self { *self } +} +#[repr(C)] +#[derive(Debug, Copy)] +pub struct ZSTD_frameHeader { + pub frameContentSize: ::libc::c_ulonglong, + pub windowSize: usize, + pub dictID: ::libc::c_uint, + pub checksumFlag: ::libc::c_uint, +} +#[test] +fn bindgen_test_layout_ZSTD_frameHeader() { + assert_eq!(::core::mem::size_of::() , 24usize , concat ! + ( "Size of: " , stringify ! ( ZSTD_frameHeader ) )); + assert_eq! (::core::mem::align_of::() , 8usize , concat + ! ( "Alignment of " , stringify ! ( ZSTD_frameHeader ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_frameHeader ) ) . frameContentSize + as * const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_frameHeader ) , + "::" , stringify ! ( frameContentSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_frameHeader ) ) . windowSize as * + const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_frameHeader ) , + "::" , stringify ! ( windowSize ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_frameHeader ) ) . dictID as * const + _ as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_frameHeader ) , + "::" , stringify ! ( dictID ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_frameHeader ) ) . checksumFlag as * + const _ as usize } , 20usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_frameHeader ) , + "::" , stringify ! ( checksumFlag ) )); +} +impl Clone for ZSTD_frameHeader { + fn clone(&self) -> Self { *self } } pub type ZSTD_allocFunction = ::core::option::Option *mut ::libc::c_void>; + -> *mut ::libc::c_void>; pub type ZSTD_freeFunction = ::core::option::Option; + address: + *mut ::libc::c_void)>; #[repr(C)] #[derive(Debug, Copy)] pub struct ZSTD_customMem { @@ -620,117 +554,188 @@ pub struct ZSTD_customMem { } #[test] fn bindgen_test_layout_ZSTD_customMem() { - assert_eq!(::core::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ZSTD_customMem))); - assert_eq!(::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ZSTD_customMem))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_customMem)).customAlloc as *const _ as - usize - }, - 0usize, - concat!("Alignment of field: ", - stringify!(ZSTD_customMem), - "::", - stringify!(customAlloc))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_customMem)).customFree as *const _ as - usize - }, - 8usize, - concat!("Alignment of field: ", - stringify!(ZSTD_customMem), - "::", - stringify!(customFree))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_customMem)).opaque as *const _ as usize - }, - 16usize, - concat!("Alignment of field: ", - stringify!(ZSTD_customMem), - "::", - stringify!(opaque))); + assert_eq!(::core::mem::size_of::() , 24usize , concat ! ( + "Size of: " , stringify ! ( ZSTD_customMem ) )); + assert_eq! (::core::mem::align_of::() , 8usize , concat ! + ( "Alignment of " , stringify ! ( ZSTD_customMem ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_customMem ) ) . customAlloc as * + const _ as usize } , 0usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_customMem ) , "::" + , stringify ! ( customAlloc ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_customMem ) ) . customFree as * + const _ as usize } , 8usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_customMem ) , "::" + , stringify ! ( customFree ) )); + assert_eq! (unsafe { + & ( * ( 0 as * const ZSTD_customMem ) ) . opaque as * const _ + as usize } , 16usize , concat ! ( + "Alignment of field: " , stringify ! ( ZSTD_customMem ) , "::" + , stringify ! ( opaque ) )); } impl Clone for ZSTD_customMem { - fn clone(&self) -> Self { - *self - } + fn clone(&self) -> Self { *self } } extern "C" { - /** ZSTD_findFrameCompressedSize() : - * `src` should point to the start of a ZSTD encoded frame or skippable frame - * `srcSize` must be at least as large as the frame - * @return : the compressed size of the frame pointed to by `src`, suitable to pass to - * `ZSTD_decompress` or similar, or an error code if given invalid input. */ - pub fn ZSTD_findFrameCompressedSize(src: *const ::libc::c_void, - srcSize: usize) - -> usize; + #[link_name = "ZSTD_defaultCMem"] + pub static ZSTD_defaultCMem: ZSTD_customMem; } extern "C" { - /*************************************** - * Decompressed size functions - ***************************************/ - /** ZSTD_getFrameContentSize() : - * `src` should point to the start of a ZSTD encoded frame - * `srcSize` must be at least as large as the frame header. A value greater than or equal - * to `ZSTD_frameHeaderSize_max` is guaranteed to be large enough in all cases. - * @return : decompressed size of the frame pointed to be `src` if known, otherwise - * - ZSTD_CONTENTSIZE_UNKNOWN if the size cannot be determined - * - ZSTD_CONTENTSIZE_ERROR if an error occurred (e.g. invalid magic number, srcSize too small) */ - pub fn ZSTD_getFrameContentSize(src: *const ::libc::c_void, - srcSize: usize) - -> ::libc::c_ulonglong; -} -extern "C" { - /** ZSTD_findDecompressedSize() : - * `src` should point the start of a series of ZSTD encoded and/or skippable frames - * `srcSize` must be the _exact_ size of this series - * (i.e. there should be a frame boundary exactly `srcSize` bytes after `src`) - * @return : the decompressed size of all data in the contained frames, as a 64-bit value _if known_ - * - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN - * - if an error occurred: ZSTD_CONTENTSIZE_ERROR - * - * note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode. - * When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size. - * In which case, it's necessary to use streaming mode to decompress data. - * Optionally, application can still use ZSTD_decompress() while relying on implied limits. - * (For example, data may be necessarily cut into blocks <= 16 KB). - * note 2 : decompressed size is always present when compression is done with ZSTD_compress() - * note 3 : decompressed size can be very large (64-bits value), - * potentially larger than what local system can handle as a single memory segment. - * In which case, it's necessary to use streaming mode to decompress data. - * note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified. - * Always ensure result fits within application's authorized limits. - * Each application can set its own limits. - * note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to - * read each contained frame header. This is efficient as most of the data is skipped, - * however it does mean that all frame data must be present and valid. */ + /*! ZSTD_findFrameCompressedSize() : + * `src` should point to the start of a ZSTD encoded frame or skippable frame + * `srcSize` must be at least as large as the frame + * @return : the compressed size of the first frame starting at `src`, + * suitable to pass to `ZSTD_decompress` or similar, + * or an error code if input is invalid */ + pub fn ZSTD_findFrameCompressedSize(src: *const ::libc::c_void, + srcSize: usize) -> usize; +} +extern "C" { + /*! ZSTD_findDecompressedSize() : + * `src` should point the start of a series of ZSTD encoded and/or skippable frames + * `srcSize` must be the _exact_ size of this series + * (i.e. there should be a frame boundary exactly at `srcSize` bytes after `src`) + * @return : - decompressed size of all data in all successive frames + * - if the decompressed size cannot be determined: ZSTD_CONTENTSIZE_UNKNOWN + * - if an error occurred: ZSTD_CONTENTSIZE_ERROR + * + * note 1 : decompressed size is an optional field, that may not be present, especially in streaming mode. + * When `return==ZSTD_CONTENTSIZE_UNKNOWN`, data to decompress could be any size. + * In which case, it's necessary to use streaming mode to decompress data. + * note 2 : decompressed size is always present when compression is done with ZSTD_compress() + * note 3 : decompressed size can be very large (64-bits value), + * potentially larger than what local system can handle as a single memory segment. + * In which case, it's necessary to use streaming mode to decompress data. + * note 4 : If source is untrusted, decompressed size could be wrong or intentionally modified. + * Always ensure result fits within application's authorized limits. + * Each application can set its own limits. + * note 5 : ZSTD_findDecompressedSize handles multiple frames, and so it must traverse the input to + * read each contained frame header. This is fast as most of the data is skipped, + * however it does mean that all frame data must be present and valid. */ pub fn ZSTD_findDecompressedSize(src: *const ::libc::c_void, - srcSize: usize) - -> ::libc::c_ulonglong; + srcSize: usize) -> ::libc::c_ulonglong; } extern "C" { - /*************************************** - * Advanced compression functions - ***************************************/ - /** ZSTD_estimateCCtxSize() : - * Gives the amount of memory allocated for a ZSTD_CCtx given a set of compression parameters. - * `frameContentSize` is an optional parameter, provide `0` if unknown */ - pub fn ZSTD_estimateCCtxSize(cParams: ZSTD_compressionParameters) - -> usize; + /*! ZSTD_frameHeaderSize() : +* `src` should point to the start of a ZSTD frame +* `srcSize` must be >= ZSTD_frameHeaderSize_prefix. +* @return : size of the Frame Header */ + pub fn ZSTD_frameHeaderSize(src: *const ::libc::c_void, srcSize: usize) + -> usize; } extern "C" { - /** ZSTD_createCCtx_advanced() : - * Create a ZSTD compression context using external alloc and free functions */ - pub fn ZSTD_createCCtx_advanced(customMem: ZSTD_customMem) - -> *mut ZSTD_CCtx; + /*! ZSTD_sizeof_*() : + * These functions give the current memory usage of selected object. + * Object memory usage can evolve if it's re-used multiple times. */ + pub fn ZSTD_sizeof_CCtx(cctx: *const ZSTD_CCtx) -> usize; } extern "C" { - /** ZSTD_sizeofCCtx() : - * Gives the amount of memory used by a given ZSTD_CCtx */ - pub fn ZSTD_sizeof_CCtx(cctx: *const ZSTD_CCtx) -> usize; + pub fn ZSTD_sizeof_DCtx(dctx: *const ZSTD_DCtx) -> usize; +} +extern "C" { + pub fn ZSTD_sizeof_CStream(zcs: *const ZSTD_CStream) -> usize; +} +extern "C" { + pub fn ZSTD_sizeof_DStream(zds: *const ZSTD_DStream) -> usize; +} +extern "C" { + pub fn ZSTD_sizeof_CDict(cdict: *const ZSTD_CDict) -> usize; +} +extern "C" { + pub fn ZSTD_sizeof_DDict(ddict: *const ZSTD_DDict) -> usize; +} +extern "C" { + /*! ZSTD_estimate*() : + * These functions make it possible to estimate memory usage + * of a future {D,C}Ctx, before its creation. + * ZSTD_estimateCCtxSize() will provide a budget large enough for any compression level up to selected one. + * It will also consider src size to be arbitrarily "large", which is worst case. + * If srcSize is known to always be small, ZSTD_estimateCCtxSize_advanced() can provide a tighter estimation. + * ZSTD_estimateCCtxSize_advanced() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. + * Note : CCtx estimation is only correct for single-threaded compression */ + pub fn ZSTD_estimateCCtxSize(compressionLevel: ::libc::c_int) -> usize; +} +extern "C" { + pub fn ZSTD_estimateCCtxSize_advanced(cParams: ZSTD_compressionParameters) + -> usize; +} +extern "C" { + pub fn ZSTD_estimateDCtxSize() -> usize; +} +extern "C" { + /*! ZSTD_estimate?StreamSize() : + * ZSTD_estimateCStreamSize() will provide a budget large enough for any compression level up to selected one. + * It will also consider src size to be arbitrarily "large", which is worst case. + * If srcSize is known to always be small, ZSTD_estimateCStreamSize_advanced() can provide a tighter estimation. + * ZSTD_estimateCStreamSize_advanced() can be used in tandem with ZSTD_getCParams() to create cParams from compressionLevel. + * Note : CStream estimation is only correct for single-threaded compression. + * ZSTD_DStream memory budget depends on window Size. + * This information can be passed manually, using ZSTD_estimateDStreamSize, + * or deducted from a valid frame Header, using ZSTD_estimateDStreamSize_fromFrame(); + * Note : if streaming is init with function ZSTD_init?Stream_usingDict(), + * an internal ?Dict will be created, which additional size is not estimated here. + * In this case, get total size by adding ZSTD_estimate?DictSize */ + pub fn ZSTD_estimateCStreamSize(compressionLevel: ::libc::c_int) -> usize; +} +extern "C" { + pub fn ZSTD_estimateCStreamSize_advanced(cParams: + ZSTD_compressionParameters) + -> usize; +} +extern "C" { + pub fn ZSTD_estimateDStreamSize(windowSize: usize) -> usize; +} +extern "C" { + pub fn ZSTD_estimateDStreamSize_fromFrame(src: *const ::libc::c_void, + srcSize: usize) -> usize; +} +extern "C" { + /*! ZSTD_estimate?DictSize() : + * ZSTD_estimateCDictSize() will bet that src size is relatively "small", and content is copied, like ZSTD_createCDict(). + * ZSTD_estimateCStreamSize_advanced() makes it possible to control precisely compression parameters, like ZSTD_createCDict_advanced(). + * Note : dictionary created "byReference" are smaller */ + pub fn ZSTD_estimateCDictSize(dictSize: usize, + compressionLevel: ::libc::c_int) -> usize; +} +extern "C" { + pub fn ZSTD_estimateCDictSize_advanced(dictSize: usize, + cParams: + ZSTD_compressionParameters, + byReference: ::libc::c_uint) + -> usize; +} +extern "C" { + pub fn ZSTD_estimateDDictSize(dictSize: usize, + byReference: ::libc::c_uint) -> usize; +} +extern "C" { + /*************************************** +* Advanced compression functions +***************************************/ +/*! ZSTD_createCCtx_advanced() : + * Create a ZSTD compression context using external alloc and free functions */ + pub fn ZSTD_createCCtx_advanced(customMem: ZSTD_customMem) + -> *mut ZSTD_CCtx; +} +extern "C" { + /*! ZSTD_initStaticCCtx() : initialize a fixed-size zstd compression context + * workspace: The memory area to emplace the context into. + * Provided pointer must 8-bytes aligned. + * It must outlive context usage. + * workspaceSize: Use ZSTD_estimateCCtxSize() or ZSTD_estimateCStreamSize() + * to determine how large workspace must be to support scenario. + * @return : pointer to ZSTD_CCtx*, or NULL if error (size too small) + * Note : zstd will never resize nor malloc() when using a static cctx. + * If it needs more memory than available, it will simply error out. + * Note 2 : there is no corresponding "free" function. + * Since workspace was allocated externally, it must be freed externally too. + * Limitation 1 : currently not compatible with internal CDict creation, such as + * ZSTD_CCtx_loadDictionary() or ZSTD_initCStream_usingDict(). + * Limitation 2 : currently not compatible with multi-threading + */ + pub fn ZSTD_initStaticCCtx(workspace: *mut ::libc::c_void, + workspaceSize: usize) -> *mut ZSTD_CCtx; } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -739,85 +744,106 @@ pub enum ZSTD_CCtxParameter { ZSTD_p_forceRawDict = 1, } extern "C" { - /** ZSTD_setCCtxParameter() : - * Set advanced parameters, selected through enum ZSTD_CCtxParameter - * @result : 0, or an error code (which can be tested with ZSTD_isError()) */ + /*! ZSTD_setCCtxParameter() : + * Set advanced parameters, selected through enum ZSTD_CCtxParameter + * @result : 0, or an error code (which can be tested with ZSTD_isError()) */ pub fn ZSTD_setCCtxParameter(cctx: *mut ZSTD_CCtx, param: ZSTD_CCtxParameter, - value: ::libc::c_uint) - -> usize; + value: ::libc::c_uint) -> usize; } extern "C" { - /** ZSTD_createCDict_byReference() : - * Create a digested dictionary for compression - * Dictionary content is simply referenced, and therefore stays in dictBuffer. - * It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict */ + /*! ZSTD_createCDict_byReference() : + * Create a digested dictionary for compression + * Dictionary content is simply referenced, and therefore stays in dictBuffer. + * It is important that dictBuffer outlives CDict, it must remain read accessible throughout the lifetime of CDict */ pub fn ZSTD_createCDict_byReference(dictBuffer: *const ::libc::c_void, dictSize: usize, compressionLevel: ::libc::c_int) - -> *mut ZSTD_CDict; + -> *mut ZSTD_CDict; +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum ZSTD_dictMode_e { + ZSTD_dm_auto = 0, + ZSTD_dm_rawContent = 1, + ZSTD_dm_fullDict = 2, } extern "C" { - /** ZSTD_createCDict_advanced() : - * Create a ZSTD_CDict using external alloc and free, and customized compression parameters */ + /*! ZSTD_createCDict_advanced() : + * Create a ZSTD_CDict using external alloc and free, and customized compression parameters */ pub fn ZSTD_createCDict_advanced(dict: *const ::libc::c_void, dictSize: usize, byReference: ::libc::c_uint, + dictMode: ZSTD_dictMode_e, cParams: ZSTD_compressionParameters, customMem: ZSTD_customMem) - -> *mut ZSTD_CDict; -} -extern "C" { - /** ZSTD_sizeof_CDict() : - * Gives the amount of memory used by a given ZSTD_sizeof_CDict */ - pub fn ZSTD_sizeof_CDict(cdict: *const ZSTD_CDict) -> usize; -} -extern "C" { - /** ZSTD_getCParams() : - * @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize. - * `estimatedSrcSize` value is optional, select 0 if not known */ + -> *mut ZSTD_CDict; +} +extern "C" { + /*! ZSTD_initStaticCDict_advanced() : + * Generate a digested dictionary in provided memory area. + * workspace: The memory area to emplace the dictionary into. + * Provided pointer must 8-bytes aligned. + * It must outlive dictionary usage. + * workspaceSize: Use ZSTD_estimateCDictSize() + * to determine how large workspace must be. + * cParams : use ZSTD_getCParams() to transform a compression level + * into its relevants cParams. + * @return : pointer to ZSTD_CDict*, or NULL if error (size too small) + * Note : there is no corresponding "free" function. + * Since workspace was allocated externally, it must be freed externally. + */ + pub fn ZSTD_initStaticCDict(workspace: *mut ::libc::c_void, + workspaceSize: usize, + dict: *const ::libc::c_void, dictSize: usize, + byReference: ::libc::c_uint, + dictMode: ZSTD_dictMode_e, + cParams: ZSTD_compressionParameters) + -> *mut ZSTD_CDict; +} +extern "C" { + /*! ZSTD_getCParams() : +* @return ZSTD_compressionParameters structure for a selected compression level and estimated srcSize. +* `estimatedSrcSize` value is optional, select 0 if not known */ pub fn ZSTD_getCParams(compressionLevel: ::libc::c_int, estimatedSrcSize: ::libc::c_ulonglong, - dictSize: usize) - -> ZSTD_compressionParameters; + dictSize: usize) -> ZSTD_compressionParameters; } extern "C" { - /** ZSTD_getParams() : - * same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`. - * All fields of `ZSTD_frameParameters` are set to default (0) */ + /*! ZSTD_getParams() : +* same as ZSTD_getCParams(), but @return a full `ZSTD_parameters` object instead of sub-component `ZSTD_compressionParameters`. +* All fields of `ZSTD_frameParameters` are set to default (0) */ pub fn ZSTD_getParams(compressionLevel: ::libc::c_int, estimatedSrcSize: ::libc::c_ulonglong, - dictSize: usize) - -> ZSTD_parameters; + dictSize: usize) -> ZSTD_parameters; } extern "C" { - /** ZSTD_checkCParams() : - * Ensure param values remain within authorized range */ + /*! ZSTD_checkCParams() : +* Ensure param values remain within authorized range */ pub fn ZSTD_checkCParams(params: ZSTD_compressionParameters) -> usize; } extern "C" { - /** ZSTD_adjustCParams() : - * optimize params for a given `srcSize` and `dictSize`. - * both values are optional, select `0` if unknown. */ + /*! ZSTD_adjustCParams() : + * optimize params for a given `srcSize` and `dictSize`. + * both values are optional, select `0` if unknown. */ pub fn ZSTD_adjustCParams(cPar: ZSTD_compressionParameters, srcSize: ::libc::c_ulonglong, dictSize: usize) - -> ZSTD_compressionParameters; + -> ZSTD_compressionParameters; } extern "C" { - /** ZSTD_compress_advanced() : - * Same as ZSTD_compress_usingDict(), with fine-tune control over each compression parameter */ + /*! ZSTD_compress_advanced() : +* Same as ZSTD_compress_usingDict(), with fine-tune control over each compression parameter */ pub fn ZSTD_compress_advanced(cctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void, dstCapacity: usize, - src: *const ::libc::c_void, - srcSize: usize, + src: *const ::libc::c_void, srcSize: usize, dict: *const ::libc::c_void, dictSize: usize, params: ZSTD_parameters) - -> usize; + -> usize; } extern "C" { - /** ZSTD_compress_usingCDict_advanced() : - * Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */ + /*! ZSTD_compress_usingCDict_advanced() : +* Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters */ pub fn ZSTD_compress_usingCDict_advanced(cctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void, dstCapacity: usize, @@ -825,175 +851,189 @@ extern "C" { srcSize: usize, cdict: *const ZSTD_CDict, fParams: ZSTD_frameParameters) - -> usize; + -> usize; } extern "C" { - /** ZSTD_isFrame() : - * Tells if the content of `buffer` starts with a valid Frame Identifier. - * Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0. - * Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled. - * Note 3 : Skippable Frame Identifiers are considered valid. */ + /*! ZSTD_isFrame() : + * Tells if the content of `buffer` starts with a valid Frame Identifier. + * Note : Frame Identifier is 4 bytes. If `size < 4`, @return will always be 0. + * Note 2 : Legacy Frame Identifiers are considered valid only if Legacy Support is enabled. + * Note 3 : Skippable Frame Identifiers are considered valid. */ pub fn ZSTD_isFrame(buffer: *const ::libc::c_void, size: usize) - -> ::libc::c_uint; + -> ::libc::c_uint; } extern "C" { - /** ZSTD_estimateDCtxSize() : - * Gives the potential amount of memory allocated to create a ZSTD_DCtx */ - pub fn ZSTD_estimateDCtxSize() -> usize; -} -extern "C" { - /** ZSTD_createDCtx_advanced() : - * Create a ZSTD decompression context using external alloc and free functions */ + /*! ZSTD_createDCtx_advanced() : + * Create a ZSTD decompression context using external alloc and free functions */ pub fn ZSTD_createDCtx_advanced(customMem: ZSTD_customMem) - -> *mut ZSTD_DCtx; -} -extern "C" { - /** ZSTD_sizeof_DCtx() : - * Gives the amount of memory used by a given ZSTD_DCtx */ - pub fn ZSTD_sizeof_DCtx(dctx: *const ZSTD_DCtx) -> usize; -} -extern "C" { - /** ZSTD_createDDict_byReference() : - * Create a digested dictionary, ready to start decompression operation without startup delay. - * Dictionary content is simply referenced, and therefore stays in dictBuffer. - * It is important that dictBuffer outlives DDict, it must remain read accessible throughout the lifetime of DDict */ + -> *mut ZSTD_DCtx; +} +extern "C" { + /*! ZSTD_initStaticDCtx() : initialize a fixed-size zstd decompression context + * workspace: The memory area to emplace the context into. + * Provided pointer must 8-bytes aligned. + * It must outlive context usage. + * workspaceSize: Use ZSTD_estimateDCtxSize() or ZSTD_estimateDStreamSize() + * to determine how large workspace must be to support scenario. + * @return : pointer to ZSTD_DCtx*, or NULL if error (size too small) + * Note : zstd will never resize nor malloc() when using a static dctx. + * If it needs more memory than available, it will simply error out. + * Note 2 : static dctx is incompatible with legacy support + * Note 3 : there is no corresponding "free" function. + * Since workspace was allocated externally, it must be freed externally. + * Limitation : currently not compatible with internal DDict creation, + * such as ZSTD_initDStream_usingDict(). + */ + pub fn ZSTD_initStaticDCtx(workspace: *mut ::libc::c_void, + workspaceSize: usize) -> *mut ZSTD_DCtx; +} +extern "C" { + /*! ZSTD_createDDict_byReference() : + * Create a digested dictionary, ready to start decompression operation without startup delay. + * Dictionary content is referenced, and therefore stays in dictBuffer. + * It is important that dictBuffer outlives DDict, + * it must remain read accessible throughout the lifetime of DDict */ pub fn ZSTD_createDDict_byReference(dictBuffer: *const ::libc::c_void, - dictSize: usize) - -> *mut ZSTD_DDict; + dictSize: usize) -> *mut ZSTD_DDict; } extern "C" { - /** ZSTD_createDDict_advanced() : - * Create a ZSTD_DDict using external alloc and free, optionally by reference */ + /*! ZSTD_createDDict_advanced() : + * Create a ZSTD_DDict using external alloc and free, optionally by reference */ pub fn ZSTD_createDDict_advanced(dict: *const ::libc::c_void, dictSize: usize, byReference: ::libc::c_uint, customMem: ZSTD_customMem) - -> *mut ZSTD_DDict; -} -extern "C" { - /** ZSTD_sizeof_DDict() : - * Gives the amount of memory used by a given ZSTD_DDict */ - pub fn ZSTD_sizeof_DDict(ddict: *const ZSTD_DDict) -> usize; -} -extern "C" { - /** ZSTD_getDictID_fromDict() : - * Provides the dictID stored within dictionary. - * if @return == 0, the dictionary is not conformant with Zstandard specification. - * It can still be loaded, but as a content-only dictionary. */ + -> *mut ZSTD_DDict; +} +extern "C" { + /*! ZSTD_initStaticDDict() : + * Generate a digested dictionary in provided memory area. + * workspace: The memory area to emplace the dictionary into. + * Provided pointer must 8-bytes aligned. + * It must outlive dictionary usage. + * workspaceSize: Use ZSTD_estimateDDictSize() + * to determine how large workspace must be. + * @return : pointer to ZSTD_DDict*, or NULL if error (size too small) + * Note : there is no corresponding "free" function. + * Since workspace was allocated externally, it must be freed externally. + */ + pub fn ZSTD_initStaticDDict(workspace: *mut ::libc::c_void, + workspaceSize: usize, + dict: *const ::libc::c_void, dictSize: usize, + byReference: ::libc::c_uint) + -> *mut ZSTD_DDict; +} +extern "C" { + /*! ZSTD_getDictID_fromDict() : + * Provides the dictID stored within dictionary. + * if @return == 0, the dictionary is not conformant with Zstandard specification. + * It can still be loaded, but as a content-only dictionary. */ pub fn ZSTD_getDictID_fromDict(dict: *const ::libc::c_void, - dictSize: usize) - -> ::libc::c_uint; + dictSize: usize) -> ::libc::c_uint; } extern "C" { - /** ZSTD_getDictID_fromDDict() : - * Provides the dictID of the dictionary loaded into `ddict`. - * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty. - * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */ + /*! ZSTD_getDictID_fromDDict() : + * Provides the dictID of the dictionary loaded into `ddict`. + * If @return == 0, the dictionary is not conformant to Zstandard specification, or empty. + * Non-conformant dictionaries can still be loaded, but as content-only dictionaries. */ pub fn ZSTD_getDictID_fromDDict(ddict: *const ZSTD_DDict) - -> ::libc::c_uint; -} -extern "C" { - /** ZSTD_getDictID_fromFrame() : - * Provides the dictID required to decompressed the frame stored within `src`. - * If @return == 0, the dictID could not be decoded. - * This could for one of the following reasons : - * - The frame does not require a dictionary to be decoded (most common case). - * - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information. - * Note : this use case also happens when using a non-conformant dictionary. - * - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`). - * - This is not a Zstandard frame. - * When identifying the exact failure cause, it's possible to use ZSTD_getFrameParams(), which will provide a more precise error code. */ + -> ::libc::c_uint; +} +extern "C" { + /*! ZSTD_getDictID_fromFrame() : + * Provides the dictID required to decompressed the frame stored within `src`. + * If @return == 0, the dictID could not be decoded. + * This could for one of the following reasons : + * - The frame does not require a dictionary to be decoded (most common case). + * - The frame was built with dictID intentionally removed. Whatever dictionary is necessary is a hidden information. + * Note : this use case also happens when using a non-conformant dictionary. + * - `srcSize` is too small, and as a result, the frame header could not be decoded (only possible if `srcSize < ZSTD_FRAMEHEADERSIZE_MAX`). + * - This is not a Zstandard frame. + * When identifying the exact failure cause, it's possible to use ZSTD_getFrameHeader(), which will provide a more precise error code. */ pub fn ZSTD_getDictID_fromFrame(src: *const ::libc::c_void, - srcSize: usize) - -> ::libc::c_uint; + srcSize: usize) -> ::libc::c_uint; } extern "C" { /******************************************************************** - * Advanced streaming functions - ********************************************************************/ +* Advanced streaming functions +********************************************************************/ pub fn ZSTD_createCStream_advanced(customMem: ZSTD_customMem) - -> *mut ZSTD_CStream; + -> *mut ZSTD_CStream; } extern "C" { - pub fn ZSTD_sizeof_CStream(zcs: *const ZSTD_CStream) -> usize; + pub fn ZSTD_initStaticCStream(workspace: *mut ::libc::c_void, + workspaceSize: usize) -> *mut ZSTD_CStream; } extern "C" { pub fn ZSTD_initCStream_srcSize(zcs: *mut ZSTD_CStream, compressionLevel: ::libc::c_int, pledgedSrcSize: ::libc::c_ulonglong) - -> usize; + -> usize; } extern "C" { pub fn ZSTD_initCStream_usingDict(zcs: *mut ZSTD_CStream, dict: *const ::libc::c_void, dictSize: usize, compressionLevel: ::libc::c_int) - -> usize; + -> usize; } extern "C" { pub fn ZSTD_initCStream_advanced(zcs: *mut ZSTD_CStream, dict: *const ::libc::c_void, - dictSize: usize, - params: ZSTD_parameters, + dictSize: usize, params: ZSTD_parameters, pledgedSrcSize: ::libc::c_ulonglong) - -> usize; + -> usize; } extern "C" { pub fn ZSTD_initCStream_usingCDict(zcs: *mut ZSTD_CStream, - cdict: *const ZSTD_CDict) - -> usize; + cdict: *const ZSTD_CDict) -> usize; } extern "C" { pub fn ZSTD_initCStream_usingCDict_advanced(zcs: *mut ZSTD_CStream, cdict: *const ZSTD_CDict, + fParams: ZSTD_frameParameters, pledgedSrcSize: - ::libc::c_ulonglong, - fParams: ZSTD_frameParameters) --> usize; -} -extern "C" { - /** ZSTD_resetCStream() : - * start a new compression job, using same parameters from previous job. - * This is typically useful to skip dictionary loading stage, since it will re-use it in-place.. - * Note that zcs must be init at least once before using ZSTD_resetCStream(). - * pledgedSrcSize==0 means "srcSize unknown". - * If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end. - * @return : 0, or an error code (which can be tested using ZSTD_isError()) */ + ::libc::c_ulonglong) + -> usize; +} +extern "C" { + /*! ZSTD_resetCStream() : + * start a new compression job, using same parameters from previous job. + * This is typically useful to skip dictionary loading stage, since it will re-use it in-place.. + * Note that zcs must be init at least once before using ZSTD_resetCStream(). + * pledgedSrcSize==0 means "srcSize unknown". + * If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end. + * @return : 0, or an error code (which can be tested using ZSTD_isError()) */ pub fn ZSTD_resetCStream(zcs: *mut ZSTD_CStream, - pledgedSrcSize: ::libc::c_ulonglong) - -> usize; + pledgedSrcSize: ::libc::c_ulonglong) -> usize; } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] -pub enum ZSTD_DStreamParameter_e { - DStream_p_maxWindowSize = 0, -} +pub enum ZSTD_DStreamParameter_e { DStream_p_maxWindowSize = 0, } extern "C" { pub fn ZSTD_createDStream_advanced(customMem: ZSTD_customMem) - -> *mut ZSTD_DStream; + -> *mut ZSTD_DStream; } extern "C" { - pub fn ZSTD_initDStream_usingDict(zds: *mut ZSTD_DStream, - dict: *const ::libc::c_void, - dictSize: usize) - -> usize; + pub fn ZSTD_initStaticDStream(workspace: *mut ::libc::c_void, + workspaceSize: usize) -> *mut ZSTD_DStream; } extern "C" { pub fn ZSTD_setDStreamParameter(zds: *mut ZSTD_DStream, paramType: ZSTD_DStreamParameter_e, - paramValue: ::libc::c_uint) - -> usize; + paramValue: ::libc::c_uint) -> usize; } extern "C" { - pub fn ZSTD_initDStream_usingDDict(zds: *mut ZSTD_DStream, - ddict: *const ZSTD_DDict) - -> usize; + pub fn ZSTD_initDStream_usingDict(zds: *mut ZSTD_DStream, + dict: *const ::libc::c_void, + dictSize: usize) -> usize; } extern "C" { - pub fn ZSTD_resetDStream(zds: *mut ZSTD_DStream) -> usize; + pub fn ZSTD_initDStream_usingDDict(zds: *mut ZSTD_DStream, + ddict: *const ZSTD_DDict) -> usize; } extern "C" { - pub fn ZSTD_sizeof_DStream(zds: *const ZSTD_DStream) -> usize; + pub fn ZSTD_resetDStream(zds: *mut ZSTD_DStream) -> usize; } extern "C" { /** @@ -1027,15 +1067,14 @@ extern "C" { `ZSTD_CCtx` object can be re-used (ZSTD_compressBegin()) to compress some new frame. */ pub fn ZSTD_compressBegin(cctx: *mut ZSTD_CCtx, - compressionLevel: ::libc::c_int) - -> usize; + compressionLevel: ::libc::c_int) -> usize; } extern "C" { pub fn ZSTD_compressBegin_usingDict(cctx: *mut ZSTD_CCtx, dict: *const ::libc::c_void, dictSize: usize, compressionLevel: ::libc::c_int) - -> usize; + -> usize; } extern "C" { pub fn ZSTD_compressBegin_advanced(cctx: *mut ZSTD_CCtx, @@ -1043,12 +1082,11 @@ extern "C" { dictSize: usize, params: ZSTD_parameters, pledgedSrcSize: ::libc::c_ulonglong) - -> usize; + -> usize; } extern "C" { pub fn ZSTD_compressBegin_usingCDict(cctx: *mut ZSTD_CCtx, - cdict: *const ZSTD_CDict) - -> usize; + cdict: *const ZSTD_CDict) -> usize; } extern "C" { pub fn ZSTD_compressBegin_usingCDict_advanced(cctx: *const ZSTD_CCtx, @@ -1057,89 +1095,27 @@ extern "C" { ZSTD_frameParameters, pledgedSrcSize: ::libc::c_ulonglong) --> usize; + -> usize; } extern "C" { - pub fn ZSTD_copyCCtx(cctx: *mut ZSTD_CCtx, - preparedCCtx: *const ZSTD_CCtx, - pledgedSrcSize: ::libc::c_ulonglong) - -> usize; + pub fn ZSTD_copyCCtx(cctx: *mut ZSTD_CCtx, preparedCCtx: *const ZSTD_CCtx, + pledgedSrcSize: ::libc::c_ulonglong) -> usize; } extern "C" { pub fn ZSTD_compressContinue(cctx: *mut ZSTD_CCtx, - dst: *mut ::libc::c_void, - dstCapacity: usize, + dst: *mut ::libc::c_void, dstCapacity: usize, src: *const ::libc::c_void, srcSize: usize) - -> usize; + -> usize; } extern "C" { pub fn ZSTD_compressEnd(cctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void, dstCapacity: usize, src: *const ::libc::c_void, - srcSize: usize) - -> usize; -} -#[repr(C)] -#[derive(Debug, Copy)] -pub struct ZSTD_frameParams { - pub frameContentSize: ::libc::c_ulonglong, - pub windowSize: ::libc::c_uint, - pub dictID: ::libc::c_uint, - pub checksumFlag: ::libc::c_uint, + srcSize: usize) -> usize; } -#[test] -fn bindgen_test_layout_ZSTD_frameParams() { - assert_eq!(::core::mem::size_of::(), - 24usize, - concat!("Size of: ", stringify!(ZSTD_frameParams))); - assert_eq!(::core::mem::align_of::(), - 8usize, - concat!("Alignment of ", stringify!(ZSTD_frameParams))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_frameParams)).frameContentSize as - *const _ as usize - }, - 0usize, - concat!("Alignment of field: ", - stringify!(ZSTD_frameParams), - "::", - stringify!(frameContentSize))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_frameParams)).windowSize as - *const _ as usize - }, - 8usize, - concat!("Alignment of field: ", - stringify!(ZSTD_frameParams), - "::", - stringify!(windowSize))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_frameParams)).dictID as *const _ as - usize - }, - 12usize, - concat!("Alignment of field: ", - stringify!(ZSTD_frameParams), - "::", - stringify!(dictID))); - assert_eq!(unsafe { - &(*(0 as *const ZSTD_frameParams)).checksumFlag as - *const _ as usize - }, - 16usize, - concat!("Alignment of field: ", - stringify!(ZSTD_frameParams), - "::", - stringify!(checksumFlag))); -} -impl Clone for ZSTD_frameParams { - fn clone(&self) -> Self { - *self - } -} -extern "C" { - pub fn ZSTD_getFrameParams(fparamsPtr: *mut ZSTD_frameParams, +extern "C" { + pub fn ZSTD_getFrameHeader(zfhPtr: *mut ZSTD_frameHeader, src: *const ::libc::c_void, srcSize: usize) - -> usize; + -> usize; } extern "C" { pub fn ZSTD_decompressBegin(dctx: *mut ZSTD_DCtx) -> usize; @@ -1147,8 +1123,11 @@ extern "C" { extern "C" { pub fn ZSTD_decompressBegin_usingDict(dctx: *mut ZSTD_DCtx, dict: *const ::libc::c_void, - dictSize: usize) - -> usize; + dictSize: usize) -> usize; +} +extern "C" { + pub fn ZSTD_decompressBegin_usingDDict(dctx: *mut ZSTD_DCtx, + ddict: *const ZSTD_DDict) -> usize; } extern "C" { pub fn ZSTD_copyDCtx(dctx: *mut ZSTD_DCtx, @@ -1161,9 +1140,8 @@ extern "C" { pub fn ZSTD_decompressContinue(dctx: *mut ZSTD_DCtx, dst: *mut ::libc::c_void, dstCapacity: usize, - src: *const ::libc::c_void, - srcSize: usize) - -> usize; + src: *const ::libc::c_void, srcSize: usize) + -> usize; } #[repr(u32)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] @@ -1178,52 +1156,198 @@ pub enum ZSTD_nextInputType_e { extern "C" { pub fn ZSTD_nextInputType(dctx: *mut ZSTD_DCtx) -> ZSTD_nextInputType_e; } +#[repr(u32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum ZSTD_cParameter { + ZSTD_p_compressionLevel = 100, + ZSTD_p_windowLog = 101, + ZSTD_p_hashLog = 102, + ZSTD_p_chainLog = 103, + ZSTD_p_searchLog = 104, + ZSTD_p_minMatch = 105, + ZSTD_p_targetLength = 106, + ZSTD_p_compressionStrategy = 107, + ZSTD_p_contentSizeFlag = 200, + ZSTD_p_checksumFlag = 201, + ZSTD_p_dictIDFlag = 202, + ZSTD_p_dictMode = 300, + ZSTD_p_refDictContent = 301, + ZSTD_p_nbThreads = 400, + ZSTD_p_jobSize = 401, + ZSTD_p_overlapSizeLog = 402, + ZSTD_p_forceMaxWindow = 1100, +} +extern "C" { + /*! ZSTD_CCtx_setParameter() : + * Set one compression parameter, selected by enum ZSTD_cParameter. + * Note : when `value` is an enum, cast it to unsigned for proper type checking. + * @result : 0, or an error code (which can be tested with ZSTD_isError()). */ + pub fn ZSTD_CCtx_setParameter(cctx: *mut ZSTD_CCtx, + param: ZSTD_cParameter, + value: ::libc::c_uint) -> usize; +} +extern "C" { + /*! ZSTD_CCtx_setPledgedSrcSize() : + * Total input data size to be compressed as a single frame. + * This value will be controlled at the end, and result in error if not respected. + * @result : 0, or an error code (which can be tested with ZSTD_isError()). + * Note 1 : 0 means zero, empty. + * In order to mean "unknown content size", pass constant ZSTD_CONTENTSIZE_UNKNOWN. + * Note that ZSTD_CONTENTSIZE_UNKNOWN is default value for new compression jobs. + * Note 2 : If all data is provided and consumed in a single round, + * this value is overriden by srcSize instead. */ + pub fn ZSTD_CCtx_setPledgedSrcSize(cctx: *mut ZSTD_CCtx, + pledgedSrcSize: ::libc::c_ulonglong) + -> usize; +} +extern "C" { + /*! ZSTD_CCtx_loadDictionary() : + * Create an internal CDict from dict buffer. + * Decompression will have to use same buffer. + * @result : 0, or an error code (which can be tested with ZSTD_isError()). + * Special : Adding a NULL (or 0-size) dictionary invalidates any previous dictionary, + * meaning "return to no-dictionary mode". + * Note 1 : `dict` content will be copied internally, + * except if ZSTD_p_refDictContent is set before loading. + * Note 2 : Loading a dictionary involves building tables, which are dependent on compression parameters. + * For this reason, compression parameters cannot be changed anymore after loading a dictionary. + * It's also a CPU-heavy operation, with non-negligible impact on latency. + * Note 3 : Dictionary will be used for all future compression jobs. + * To return to "no-dictionary" situation, load a NULL dictionary */ + pub fn ZSTD_CCtx_loadDictionary(cctx: *mut ZSTD_CCtx, + dict: *const ::libc::c_void, + dictSize: usize) -> usize; +} +extern "C" { + /*! ZSTD_CCtx_refCDict() : + * Reference a prepared dictionary, to be used for all next compression jobs. + * Note that compression parameters are enforced from within CDict, + * and supercede any compression parameter previously set within CCtx. + * The dictionary will remain valid for future compression jobs using same CCtx. + * @result : 0, or an error code (which can be tested with ZSTD_isError()). + * Special : adding a NULL CDict means "return to no-dictionary mode". + * Note 1 : Currently, only one dictionary can be managed. + * Adding a new dictionary effectively "discards" any previous one. + * Note 2 : CDict is just referenced, its lifetime must outlive CCtx. + */ + pub fn ZSTD_CCtx_refCDict(cctx: *mut ZSTD_CCtx, cdict: *const ZSTD_CDict) + -> usize; +} +extern "C" { + /*! ZSTD_CCtx_refPrefix() : + * Reference a prefix (single-usage dictionary) for next compression job. + * Decompression need same prefix to properly regenerate data. + * Prefix is **only used once**. Tables are discarded at end of compression job. + * Subsequent compression jobs will be done without prefix (if none is explicitly referenced). + * If there is a need to use same prefix multiple times, consider embedding it into a ZSTD_CDict instead. + * @result : 0, or an error code (which can be tested with ZSTD_isError()). + * Special : Adding any prefix (including NULL) invalidates any previous prefix or dictionary + * Note 1 : Prefix buffer is referenced. It must outlive compression job. + * Note 2 : Referencing a prefix involves building tables, which are dependent on compression parameters. + * It's a CPU-heavy operation, with non-negligible impact on latency. + * Note 3 : it's possible to alter ZSTD_p_dictMode using ZSTD_CCtx_setParameter() */ + pub fn ZSTD_CCtx_refPrefix(cctx: *mut ZSTD_CCtx, + prefix: *const ::libc::c_void, + prefixSize: usize) -> usize; +} +#[repr(u32)] +#[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] +pub enum ZSTD_EndDirective { + ZSTD_e_continue = 0, + ZSTD_e_flush = 1, + ZSTD_e_end = 2, +} +extern "C" { + /*! ZSTD_compress_generic() : + * Behave about the same as ZSTD_compressStream. To note : + * - Compression parameters are pushed into CCtx before starting compression, using ZSTD_CCtx_setParameter() + * - Compression parameters cannot be changed once compression is started. + * - *dstPos must be <= dstCapacity, *srcPos must be <= srcSize + * - *dspPos and *srcPos will be updated. They are guaranteed to remain below their respective limit. + * - @return provides the minimum amount of data still to flush from internal buffers + * or an error code, which can be tested using ZSTD_isError(). + * if @return != 0, flush is not fully completed, there is some data left within internal buffers. + * - after a ZSTD_e_end directive, if internal buffer is not fully flushed, + * only ZSTD_e_end or ZSTD_e_flush operations are allowed. + * It is necessary to fully flush internal buffers + * before starting a new compression job, or changing compression parameters. + */ + pub fn ZSTD_compress_generic(cctx: *mut ZSTD_CCtx, + output: *mut ZSTD_outBuffer, + input: *mut ZSTD_inBuffer, + endOp: ZSTD_EndDirective) -> usize; +} +extern "C" { + /*! ZSTD_CCtx_reset() : + * Return a CCtx to clean state. + * Useful after an error, or to interrupt an ongoing compression job and start a new one. + * Any internal data not yet flushed is cancelled. + * Dictionary (if any) is dropped. + * It's possible to modify compression parameters after a reset. + */ + pub fn ZSTD_CCtx_reset(cctx: *mut ZSTD_CCtx); +} +extern "C" { + /*! ZSTD_compress_generic_simpleArgs() : + * Same as ZSTD_compress_generic(), + * but using only integral types as arguments. + * Argument list is larger and less expressive than ZSTD_{in,out}Buffer, + * but can be helpful for binders from dynamic languages + * which have troubles handling structures containing memory pointers. + */ + pub fn ZSTD_compress_generic_simpleArgs(cctx: *mut ZSTD_CCtx, + dst: *mut ::libc::c_void, + dstCapacity: usize, + dstPos: *mut usize, + src: *const ::libc::c_void, + srcSize: usize, + srcPos: *mut usize, + endOp: ZSTD_EndDirective) + -> usize; +} extern "C" { - pub fn ZSTD_getBlockSizeMax(cctx: *mut ZSTD_CCtx) -> usize; + pub fn ZSTD_getBlockSize(cctx: *const ZSTD_CCtx) -> usize; } extern "C" { - pub fn ZSTD_compressBlock(cctx: *mut ZSTD_CCtx, - dst: *mut ::libc::c_void, dstCapacity: usize, - src: *const ::libc::c_void, srcSize: usize) - -> usize; + pub fn ZSTD_compressBlock(cctx: *mut ZSTD_CCtx, dst: *mut ::libc::c_void, + dstCapacity: usize, src: *const ::libc::c_void, + srcSize: usize) -> usize; } extern "C" { pub fn ZSTD_decompressBlock(dctx: *mut ZSTD_DCtx, - dst: *mut ::libc::c_void, - dstCapacity: usize, + dst: *mut ::libc::c_void, dstCapacity: usize, src: *const ::libc::c_void, srcSize: usize) - -> usize; + -> usize; } extern "C" { pub fn ZSTD_insertBlock(dctx: *mut ZSTD_DCtx, blockStart: *const ::libc::c_void, - blockSize: usize) - -> usize; -} -extern "C" { - /** ZDICT_trainFromBuffer() : - Train a dictionary from an array of samples. - Samples must be stored concatenated in a single flat buffer `samplesBuffer`, - supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order. - The resulting dictionary will be saved into `dictBuffer`. - @return : size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`) - or an error code, which can be tested with ZDICT_isError(). - Tips : In general, a reasonable dictionary has a size of ~ 100 KB. - It's obviously possible to target smaller or larger ones, just by specifying different `dictBufferCapacity`. - In general, it's recommended to provide a few thousands samples, but this can vary a lot. - It's recommended that total size of all samples be about ~x100 times the target size of dictionary. -*/ + blockSize: usize) -> usize; +} +extern "C" { + /*! ZDICT_trainFromBuffer(): + * Train a dictionary from an array of samples. + * Uses ZDICT_optimizeTrainFromBuffer_cover() single-threaded, with d=8 and steps=4. + * Samples must be stored concatenated in a single flat buffer `samplesBuffer`, + * supplied with an array of sizes `samplesSizes`, providing the size of each sample, in order. + * The resulting dictionary will be saved into `dictBuffer`. + * @return: size of dictionary stored into `dictBuffer` (<= `dictBufferCapacity`) + * or an error code, which can be tested with ZDICT_isError(). + * Note: ZDICT_trainFromBuffer() requires about 9 bytes of memory for each input byte. + * Tips: In general, a reasonable dictionary has a size of ~ 100 KB. + * It's obviously possible to target smaller or larger ones, just by specifying different `dictBufferCapacity`. + * In general, it's recommended to provide a few thousands samples, but this can vary a lot. + * It's recommended that total size of all samples be about ~x100 times the target size of dictionary. + */ pub fn ZDICT_trainFromBuffer(dictBuffer: *mut ::libc::c_void, dictBufferCapacity: usize, samplesBuffer: *const ::libc::c_void, samplesSizes: *const usize, - nbSamples: ::libc::c_uint) - -> usize; + nbSamples: ::libc::c_uint) -> usize; } extern "C" { - pub fn ZDICT_getDictID(dictBuffer: *const ::libc::c_void, - dictSize: usize) - -> ::libc::c_uint; + pub fn ZDICT_getDictID(dictBuffer: *const ::libc::c_void, dictSize: usize) + -> ::libc::c_uint; } extern "C" { pub fn ZDICT_isError(errorCode: usize) -> ::libc::c_uint; diff --git a/zstd-safe/zstd-sys/zstd.h b/zstd-safe/zstd-sys/zstd.h index b23caadd..58833d82 100644 --- a/zstd-safe/zstd-sys/zstd.h +++ b/zstd-safe/zstd-sys/zstd.h @@ -4,7 +4,7 @@ /* This file is used to generate bindings for both headers. * Just run the following command to generate the bindings: -bindgen zstd.h --ctypes-prefix ::libc --blacklist-type max_align_t --no-unstable-rust --use-core -- -DZSTD_STATIC_LINKING_ONLY > src/bindings.rs +bindgen zstd.h --ctypes-prefix ::libc --blacklist-type max_align_t --use-core -- -DZSTD_STATIC_LINKING_ONLY > src/bindings.rs Or use the `bindgen` feature, which will create the bindings automatically.