diff --git a/zstd-safe/zstd-sys/Cargo.toml b/zstd-safe/zstd-sys/Cargo.toml index 76a97490..ef1dafb0 100644 --- a/zstd-safe/zstd-sys/Cargo.toml +++ b/zstd-safe/zstd-sys/Cargo.toml @@ -12,7 +12,7 @@ readme = "Readme.md" links = "zstd" [build-dependencies] -bindgen = { version = "0.31", optional = true } +bindgen = { version = "0.32", optional = true } gcc = "0.3.51" glob = "0.2.11" diff --git a/zstd-safe/zstd-sys/build.rs b/zstd-safe/zstd-sys/build.rs index 0a7e8a58..2100f9cf 100644 --- a/zstd-safe/zstd-sys/build.rs +++ b/zstd-safe/zstd-sys/build.rs @@ -16,6 +16,7 @@ fn generate_bindings() { .header("zstd.h") .blacklist_type("max_align_t") .use_core() + .rustified_enum(".*") .ctypes_prefix("::libc") .clang_arg("-Izstd/lib") .clang_arg("-DZSTD_STATIC_LINKING_ONLY") diff --git a/zstd-safe/zstd-sys/src/bindings.rs b/zstd-safe/zstd-sys/src/bindings.rs index 9aecae4a..39d48a1c 100644 --- a/zstd-safe/zstd-sys/src/bindings.rs +++ b/zstd-safe/zstd-sys/src/bindings.rs @@ -2,8 +2,8 @@ pub const ZSTD_VERSION_MAJOR: ::libc::c_uint = 1; pub const ZSTD_VERSION_MINOR: ::libc::c_uint = 3; -pub const ZSTD_VERSION_RELEASE: ::libc::c_uint = 2; -pub const ZSTD_VERSION_NUMBER: ::libc::c_uint = 10302; +pub const ZSTD_VERSION_RELEASE: ::libc::c_uint = 3; +pub const ZSTD_VERSION_NUMBER: ::libc::c_uint = 10303; 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; @@ -28,7 +28,7 @@ pub const ZSTD_FRAMEHEADERSIZE_MIN: ::libc::c_uint = 6; pub const ZSTD_FRAMEHEADERSIZE_MAX: ::libc::c_uint = 18; pub const ZSTD_BLOCKSIZELOG_MAX: ::libc::c_uint = 17; pub const ZSTD_BLOCKSIZE_MAX: ::libc::c_uint = 131072; -pub const ZSTDMT_SECTION_SIZE_MIN: ::libc::c_uint = 1048576; +pub const ZSTDMT_JOBSIZE_MIN: ::libc::c_uint = 1048576; pub type wchar_t = ::libc::c_int; extern "C" { pub fn ZSTD_versionNumber() -> ::libc::c_uint; @@ -37,6 +37,7 @@ extern "C" { pub fn ZSTD_versionString() -> *const ::libc::c_char; } extern "C" { + /// Simple API /// / /// /*! ZSTD_compress() : @@ -53,6 +54,7 @@ extern "C" { ) -> 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 to regenerate. @@ -73,6 +75,7 @@ extern "C" { ) -> ::libc::c_ulonglong; } extern "C" { + /// ZSTD_getDecompressedSize() : /// NOTE: This function is now obsolete, in favor of ZSTD_getFrameContentSize(). /// Both functions work the same way, @@ -113,6 +116,7 @@ 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()). pub fn ZSTD_compressCCtx( @@ -137,6 +141,7 @@ 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( @@ -148,6 +153,7 @@ extern "C" { ) -> usize; } extern "C" { + /// Simple dictionary API /// / /// /*! ZSTD_compress_usingDict() : @@ -166,6 +172,7 @@ extern "C" { ) -> 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. @@ -189,6 +196,7 @@ pub struct ZSTD_CDict_s { /// 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. @@ -201,11 +209,13 @@ extern "C" { ) -> *mut ZSTD_CDict; } extern "C" { + /// 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. @@ -227,6 +237,7 @@ 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 @@ -236,11 +247,13 @@ extern "C" { ) -> *mut ZSTD_DDict; } extern "C" { + /// 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. @@ -255,7 +268,7 @@ extern "C" { } /// Streaming #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ZSTD_inBuffer_s { /// < start of input buffer pub src: *const ::libc::c_void, @@ -277,44 +290,48 @@ fn bindgen_test_layout_ZSTD_inBuffer_s() { concat!("Alignment of ", stringify!(ZSTD_inBuffer_s)) ); assert_eq!( - unsafe { &(*(0 as *const ZSTD_inBuffer_s)).src as *const _ as usize }, + unsafe { + &(*(::core::ptr::null::())).src as *const _ + as usize + }, 0usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_inBuffer_s), "::", stringify!(src) ) ); assert_eq!( - unsafe { &(*(0 as *const ZSTD_inBuffer_s)).size as *const _ as usize }, + unsafe { + &(*(::core::ptr::null::())).size as *const _ + as usize + }, 8usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_inBuffer_s), "::", stringify!(size) ) ); assert_eq!( - unsafe { &(*(0 as *const ZSTD_inBuffer_s)).pos as *const _ as usize }, + unsafe { + &(*(::core::ptr::null::())).pos as *const _ + as usize + }, 16usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_inBuffer_s), "::", stringify!(pos) ) ); } -impl Clone for ZSTD_inBuffer_s { - fn clone(&self) -> Self { - *self - } -} pub type ZSTD_inBuffer = ZSTD_inBuffer_s; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ZSTD_outBuffer_s { /// < start of output buffer pub dst: *mut ::libc::c_void, @@ -336,10 +353,13 @@ fn bindgen_test_layout_ZSTD_outBuffer_s() { concat!("Alignment of ", stringify!(ZSTD_outBuffer_s)) ); assert_eq!( - unsafe { &(*(0 as *const ZSTD_outBuffer_s)).dst as *const _ as usize }, + unsafe { + &(*(::core::ptr::null::())).dst as *const _ + as usize + }, 0usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_outBuffer_s), "::", stringify!(dst) @@ -347,32 +367,31 @@ fn bindgen_test_layout_ZSTD_outBuffer_s() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_outBuffer_s)).size as *const _ as usize + &(*(::core::ptr::null::())).size as *const _ + as usize }, 8usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_outBuffer_s), "::", stringify!(size) ) ); assert_eq!( - unsafe { &(*(0 as *const ZSTD_outBuffer_s)).pos as *const _ as usize }, + unsafe { + &(*(::core::ptr::null::())).pos as *const _ + as usize + }, 16usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_outBuffer_s), "::", stringify!(pos) ) ); } -impl Clone for ZSTD_outBuffer_s { - fn clone(&self) -> Self { - *self - } -} pub type ZSTD_outBuffer = ZSTD_outBuffer_s; pub type ZSTD_CStream = ZSTD_CCtx; extern "C" { @@ -440,6 +459,7 @@ pub const ZSTD_frameHeaderSize_min: usize = 6; pub const ZSTD_frameHeaderSize_max: usize = 18; pub const ZSTD_skippableHeaderSize: usize = 8; #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_strategy { ZSTD_fast = 1, @@ -452,7 +472,7 @@ pub enum ZSTD_strategy { ZSTD_btultra = 8, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ZSTD_compressionParameters { /// < largest match distance : larger == more compression, more memory needed during decompression pub windowLog: ::libc::c_uint, @@ -482,12 +502,12 @@ fn bindgen_test_layout_ZSTD_compressionParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_compressionParameters)).windowLog as *const _ - as usize + &(*(::core::ptr::null::())).windowLog + as *const _ as usize }, 0usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_compressionParameters), "::", stringify!(windowLog) @@ -495,12 +515,12 @@ fn bindgen_test_layout_ZSTD_compressionParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_compressionParameters)).chainLog as *const _ - as usize + &(*(::core::ptr::null::())).chainLog + as *const _ as usize }, 4usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_compressionParameters), "::", stringify!(chainLog) @@ -508,12 +528,12 @@ fn bindgen_test_layout_ZSTD_compressionParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_compressionParameters)).hashLog as *const _ - as usize + &(*(::core::ptr::null::())).hashLog + as *const _ as usize }, 8usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_compressionParameters), "::", stringify!(hashLog) @@ -521,12 +541,12 @@ fn bindgen_test_layout_ZSTD_compressionParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_compressionParameters)).searchLog as *const _ - as usize + &(*(::core::ptr::null::())).searchLog + as *const _ as usize }, 12usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_compressionParameters), "::", stringify!(searchLog) @@ -534,12 +554,12 @@ fn bindgen_test_layout_ZSTD_compressionParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_compressionParameters)).searchLength - as *const _ as usize + &(*(::core::ptr::null::())) + .searchLength as *const _ as usize }, 16usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_compressionParameters), "::", stringify!(searchLength) @@ -547,12 +567,12 @@ fn bindgen_test_layout_ZSTD_compressionParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_compressionParameters)).targetLength - as *const _ as usize + &(*(::core::ptr::null::())) + .targetLength as *const _ as usize }, 20usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_compressionParameters), "::", stringify!(targetLength) @@ -560,25 +580,20 @@ fn bindgen_test_layout_ZSTD_compressionParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_compressionParameters)).strategy as *const _ - as usize + &(*(::core::ptr::null::())).strategy + as *const _ as usize }, 24usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_compressionParameters), "::", stringify!(strategy) ) ); } -impl Clone for ZSTD_compressionParameters { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ZSTD_frameParameters { /// < 1: content size will be in frame header (when known) pub contentSizeFlag: ::libc::c_uint, @@ -601,12 +616,12 @@ fn bindgen_test_layout_ZSTD_frameParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameParameters)).contentSizeFlag as *const _ - as usize + &(*(::core::ptr::null::())).contentSizeFlag + as *const _ as usize }, 0usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameParameters), "::", stringify!(contentSizeFlag) @@ -614,12 +629,12 @@ fn bindgen_test_layout_ZSTD_frameParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameParameters)).checksumFlag as *const _ - as usize + &(*(::core::ptr::null::())).checksumFlag + as *const _ as usize }, 4usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameParameters), "::", stringify!(checksumFlag) @@ -627,25 +642,20 @@ fn bindgen_test_layout_ZSTD_frameParameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameParameters)).noDictIDFlag as *const _ - as usize + &(*(::core::ptr::null::())).noDictIDFlag + as *const _ as usize }, 8usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameParameters), "::", stringify!(noDictIDFlag) ) ); } -impl Clone for ZSTD_frameParameters { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ZSTD_parameters { pub cParams: ZSTD_compressionParameters, pub fParams: ZSTD_frameParameters, @@ -664,11 +674,12 @@ fn bindgen_test_layout_ZSTD_parameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_parameters)).cParams as *const _ as usize + &(*(::core::ptr::null::())).cParams as *const _ + as usize }, 0usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_parameters), "::", stringify!(cParams) @@ -676,22 +687,18 @@ fn bindgen_test_layout_ZSTD_parameters() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_parameters)).fParams as *const _ as usize + &(*(::core::ptr::null::())).fParams as *const _ + as usize }, 28usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_parameters), "::", stringify!(fParams) ) ); } -impl Clone for ZSTD_parameters { - fn clone(&self) -> Self { - *self - } -} #[repr(C)] #[derive(Debug, Copy, Clone)] pub struct ZSTD_CCtx_params_s { @@ -709,7 +716,7 @@ pub type ZSTD_freeFunction = ::core::option::Option< ), >; #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ZSTD_customMem { pub customAlloc: ZSTD_allocFunction, pub customFree: ZSTD_freeFunction, @@ -729,11 +736,12 @@ fn bindgen_test_layout_ZSTD_customMem() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_customMem)).customAlloc as *const _ as usize + &(*(::core::ptr::null::())).customAlloc as *const _ + as usize }, 0usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_customMem), "::", stringify!(customAlloc) @@ -741,11 +749,12 @@ fn bindgen_test_layout_ZSTD_customMem() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_customMem)).customFree as *const _ as usize + &(*(::core::ptr::null::())).customFree as *const _ + as usize }, 8usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_customMem), "::", stringify!(customFree) @@ -753,30 +762,27 @@ fn bindgen_test_layout_ZSTD_customMem() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_customMem)).opaque as *const _ as usize + &(*(::core::ptr::null::())).opaque as *const _ + as usize }, 16usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_customMem), "::", stringify!(opaque) ) ); } -impl Clone for ZSTD_customMem { - fn clone(&self) -> Self { - *self - } -} extern "C" { - #[link_name = "ZSTD_defaultCMem"] - pub static ZSTD_defaultCMem: ZSTD_customMem; + #[link_name = "\u{1}ZSTD_defaultCMem"] + pub static mut ZSTD_defaultCMem: ZSTD_customMem; } 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 + /// `srcSize` must be >= first frame size /// @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 @@ -786,6 +792,7 @@ extern "C" { ) -> 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 @@ -813,6 +820,7 @@ extern "C" { ) -> ::libc::c_ulonglong; } extern "C" { + /// ZSTD_frameHeaderSize() : /// `src` should point to the start of a ZSTD frame /// `srcSize` must be >= ZSTD_frameHeaderSize_prefix. @@ -823,6 +831,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_sizeof_*() : /// These functions give the current memory usage of selected object. /// Object memory usage can evolve when re-used multiple times. @@ -844,6 +853,7 @@ 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. @@ -869,6 +879,7 @@ extern "C" { pub fn ZSTD_estimateDCtxSize() -> usize; } extern "C" { + /// ZSTD_estimateCStreamSize() : /// 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. @@ -904,12 +915,14 @@ extern "C" { ) -> usize; } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_dictLoadMethod_e { ZSTD_dlm_byCopy = 0, ZSTD_dlm_byRef = 1, } 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_usingCParams() makes it possible to control precisely compression parameters, like ZSTD_createCDict_advanced(). @@ -933,6 +946,7 @@ extern "C" { ) -> usize; } extern "C" { + /// Advanced compression functions /// / /// /*! ZSTD_createCCtx_advanced() : @@ -942,13 +956,15 @@ extern "C" { ) -> *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) + /// @return : pointer to ZSTD_CCtx* (same address as workspace, but different type), + /// or NULL if error (typically 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. @@ -962,6 +978,7 @@ extern "C" { ) -> *mut ZSTD_CCtx; } extern "C" { + /// ZSTD_createCDict_byReference() : /// Create a digested dictionary for compression /// Dictionary content is simply referenced, and therefore stays in dictBuffer. @@ -973,6 +990,7 @@ extern "C" { ) -> *mut ZSTD_CDict; } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_dictMode_e { ZSTD_dm_auto = 0, @@ -980,6 +998,7 @@ pub enum ZSTD_dictMode_e { ZSTD_dm_fullDict = 2, } extern "C" { + /// ZSTD_createCDict_advanced() : /// Create a ZSTD_CDict using external alloc and free, and customized compression parameters pub fn ZSTD_createCDict_advanced( @@ -992,7 +1011,8 @@ extern "C" { ) -> *mut ZSTD_CDict; } extern "C" { - /// ZSTD_initStaticCDict_advanced() : + + /// ZSTD_initStaticCDict() : /// Generate a digested dictionary in provided memory area. /// workspace: The memory area to emplace the dictionary into. /// Provided pointer must 8-bytes aligned. @@ -1001,7 +1021,8 @@ extern "C" { /// 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) + /// @return : pointer to ZSTD_CDict* (same address as workspace, but different type), + /// or NULL if error (typically, size too small). /// Note : there is no corresponding "free" function. /// Since workspace was allocated externally, it must be freed externally. pub fn ZSTD_initStaticCDict( @@ -1015,6 +1036,7 @@ extern "C" { ) -> *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 @@ -1025,9 +1047,10 @@ extern "C" { ) -> 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) + /// All fields of `ZSTD_frameParameters` are set to default : contentSize=1, checksum=0, noDictID=0 pub fn ZSTD_getParams( compressionLevel: ::libc::c_int, estimatedSrcSize: ::libc::c_ulonglong, @@ -1035,11 +1058,13 @@ extern "C" { ) -> ZSTD_parameters; } extern "C" { + /// 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. @@ -1050,6 +1075,7 @@ extern "C" { ) -> ZSTD_compressionParameters; } extern "C" { + /// ZSTD_compress_advanced() : /// Same as ZSTD_compress_usingDict(), with fine-tune control over each compression parameter pub fn ZSTD_compress_advanced( @@ -1064,6 +1090,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_compress_usingCDict_advanced() : /// Same as ZSTD_compress_usingCDict(), with fine-tune control over frame parameters pub fn ZSTD_compress_usingCDict_advanced( @@ -1077,6 +1104,7 @@ extern "C" { ) -> 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. @@ -1088,6 +1116,7 @@ extern "C" { ) -> ::libc::c_uint; } extern "C" { + /// ZSTD_createDCtx_advanced() : /// Create a ZSTD decompression context using external alloc and free functions pub fn ZSTD_createDCtx_advanced( @@ -1095,13 +1124,15 @@ extern "C" { ) -> *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) + /// @return : pointer to ZSTD_DCtx* (same address as workspace, but different type), + /// or NULL if error (typically 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 @@ -1115,6 +1146,7 @@ extern "C" { ) -> *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. @@ -1126,6 +1158,7 @@ extern "C" { ) -> *mut ZSTD_DDict; } extern "C" { + /// ZSTD_createDDict_advanced() : /// Create a ZSTD_DDict using external alloc and free, optionally by reference pub fn ZSTD_createDDict_advanced( @@ -1136,6 +1169,7 @@ extern "C" { ) -> *mut ZSTD_DDict; } extern "C" { + /// ZSTD_initStaticDDict() : /// Generate a digested dictionary in provided memory area. /// workspace: The memory area to emplace the dictionary into. @@ -1155,6 +1189,7 @@ extern "C" { ) -> *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. @@ -1165,6 +1200,7 @@ extern "C" { ) -> ::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. @@ -1174,6 +1210,7 @@ extern "C" { ) -> ::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. @@ -1190,6 +1227,7 @@ extern "C" { ) -> ::libc::c_uint; } extern "C" { + /// Advanced streaming functions pub fn ZSTD_createCStream_advanced( customMem: ZSTD_customMem, @@ -1240,12 +1278,15 @@ extern "C" { ) -> 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 is not known at reset time, use macro ZSTD_CONTENTSIZE_UNKNOWN. /// If pledgedSrcSize > 0, its value must be correct, as it will be written in header, and controlled at the end. + /// For the time being, pledgedSrcSize==0 is interpreted as "srcSize unknown" for compatibility with older programs, + /// but it may change to mean "empty" in some future version, so prefer using macro ZSTD_CONTENTSIZE_UNKNOWN. /// @return : 0, or an error code (which can be tested using ZSTD_isError()) pub fn ZSTD_resetCStream( zcs: *mut ZSTD_CStream, @@ -1264,6 +1305,7 @@ extern "C" { ) -> *mut ZSTD_DStream; } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_DStreamParameter_e { DStream_p_maxWindowSize = 0, @@ -1292,6 +1334,7 @@ extern "C" { pub fn ZSTD_resetDStream(zds: *mut ZSTD_DStream) -> usize; } extern "C" { + /// Buffer-less streaming compression (synchronous mode) /// /// A ZSTD_CCtx object is required to track streaming operations. @@ -1382,13 +1425,14 @@ extern "C" { ) -> usize; } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_frameType_e { ZSTD_frame = 0, ZSTD_skippableFrame = 1, } #[repr(C)] -#[derive(Debug, Copy)] +#[derive(Debug, Copy, Clone)] pub struct ZSTD_frameHeader { pub frameContentSize: ::libc::c_ulonglong, pub windowSize: ::libc::c_ulonglong, @@ -1412,12 +1456,12 @@ fn bindgen_test_layout_ZSTD_frameHeader() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameHeader)).frameContentSize as *const _ - as usize + &(*(::core::ptr::null::())).frameContentSize + as *const _ as usize }, 0usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameHeader), "::", stringify!(frameContentSize) @@ -1425,11 +1469,12 @@ fn bindgen_test_layout_ZSTD_frameHeader() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameHeader)).windowSize as *const _ as usize + &(*(::core::ptr::null::())).windowSize + as *const _ as usize }, 8usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameHeader), "::", stringify!(windowSize) @@ -1437,12 +1482,12 @@ fn bindgen_test_layout_ZSTD_frameHeader() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameHeader)).blockSizeMax as *const _ - as usize + &(*(::core::ptr::null::())).blockSizeMax + as *const _ as usize }, 16usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameHeader), "::", stringify!(blockSizeMax) @@ -1450,11 +1495,12 @@ fn bindgen_test_layout_ZSTD_frameHeader() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameHeader)).frameType as *const _ as usize + &(*(::core::ptr::null::())).frameType as *const _ + as usize }, 20usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameHeader), "::", stringify!(frameType) @@ -1462,11 +1508,12 @@ fn bindgen_test_layout_ZSTD_frameHeader() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameHeader)).headerSize as *const _ as usize + &(*(::core::ptr::null::())).headerSize + as *const _ as usize }, 24usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameHeader), "::", stringify!(headerSize) @@ -1474,11 +1521,12 @@ fn bindgen_test_layout_ZSTD_frameHeader() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameHeader)).dictID as *const _ as usize + &(*(::core::ptr::null::())).dictID as *const _ + as usize }, 28usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameHeader), "::", stringify!(dictID) @@ -1486,23 +1534,18 @@ fn bindgen_test_layout_ZSTD_frameHeader() { ); assert_eq!( unsafe { - &(*(0 as *const ZSTD_frameHeader)).checksumFlag as *const _ - as usize + &(*(::core::ptr::null::())).checksumFlag + as *const _ as usize }, 32usize, concat!( - "Alignment of field: ", + "Offset of field: ", stringify!(ZSTD_frameHeader), "::", stringify!(checksumFlag) ) ); } -impl Clone for ZSTD_frameHeader { - fn clone(&self) -> Self { - *self - } -} extern "C" { pub fn ZSTD_getFrameHeader( zfhPtr: *mut ZSTD_frameHeader, @@ -1548,6 +1591,7 @@ extern "C" { pub fn ZSTD_copyDCtx(dctx: *mut ZSTD_DCtx, preparedDCtx: *const ZSTD_DCtx); } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_nextInputType_e { ZSTDnit_frameHeader = 0, @@ -1561,6 +1605,7 @@ extern "C" { pub fn ZSTD_nextInputType(dctx: *mut ZSTD_DCtx) -> ZSTD_nextInputType_e; } #[repr(u32)] +#[repr(C)] /// New advanced API (experimental) #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_format_e { @@ -1568,6 +1613,7 @@ pub enum ZSTD_format_e { ZSTD_f_zstd1_magicless = 1, } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_cParameter { ZSTD_p_format = 10, @@ -1593,10 +1639,12 @@ pub enum ZSTD_cParameter { ZSTD_p_ldmHashEveryLog = 1204, } 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()). + /// @result : informational value (typically, the one being set, possibly corrected), + /// or an error code (which can be tested with ZSTD_isError()). pub fn ZSTD_CCtx_setParameter( cctx: *mut ZSTD_CCtx, param: ZSTD_cParameter, @@ -1604,13 +1652,14 @@ extern "C" { ) -> 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. + /// ZSTD_CONTENTSIZE_UNKNOWN is default value for any new compression job. /// 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( @@ -1619,6 +1668,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_CCtx_loadDictionary() : /// Create an internal CDict from dict buffer. /// Decompression will have to use same buffer. @@ -1659,6 +1709,7 @@ extern "C" { ) -> 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, @@ -1675,6 +1726,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_CCtx_refPrefix() : /// Reference a prefix (single-usage dictionary) for next compression job. /// Decompression need same prefix to properly regenerate data. @@ -1704,6 +1756,7 @@ extern "C" { ) -> usize; } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTD_EndDirective { ZSTD_e_continue = 0, @@ -1711,19 +1764,26 @@ pub enum ZSTD_EndDirective { 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. /// - outpot->pos must be <= dstCapacity, input->pos must be <= srcSize /// - outpot->pos and input->pos 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 + /// - In single-thread mode (default), function is blocking : it completed its job before returning to caller. + /// - In multi-thread mode, function is non-blocking : it just acquires a copy of input, and distribute job to internal worker threads, + /// and then immediately returns, just indicating that there is some data remaining to be flushed. + /// The function nonetheless guarantees forward progress : it will return only after it reads or write at least 1+ byte. + /// - Exception : in multi-threading mode, if the first call requests a ZSTD_e_end directive, it is blocking : it will complete compression before giving back control to caller. + /// - @return provides the minimum amount of data remaining to be flushed 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, + /// if @return != 0, flush is not fully completed, there is still some data left within internal buffers. + /// This is useful to determine if a ZSTD_e_flush or ZSTD_e_end directive is completed. + /// - after a ZSTD_e_end directive, if internal buffer is not fully flushed (@return != 0), /// 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. + /// Before starting a new compression job, or changing compression parameters, + /// it is required to fully flush internal buffers. pub fn ZSTD_compress_generic( cctx: *mut ZSTD_CCtx, output: *mut ZSTD_outBuffer, @@ -1732,6 +1792,7 @@ extern "C" { ) -> 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. @@ -1742,6 +1803,7 @@ extern "C" { 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. @@ -1760,6 +1822,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_CCtx_params : /// Quick howto : /// - ZSTD_createCCtxParams() : Create a ZSTD_CCtx_params structure @@ -1779,11 +1842,13 @@ extern "C" { pub fn ZSTD_createCCtxParams() -> *mut ZSTD_CCtx_params; } extern "C" { + /// ZSTD_resetCCtxParams() : /// Reset params to default, with the default compression level. pub fn ZSTD_resetCCtxParams(params: *mut ZSTD_CCtx_params) -> usize; } extern "C" { + /// ZSTD_initCCtxParams() : /// Initializes the compression parameters of cctxParams according to /// compression level. All other parameters are reset to their default values. @@ -1793,6 +1858,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_initCCtxParams_advanced() : /// Initializes the compression and frame parameters of cctxParams according to /// params. All other parameters are reset to their default values. @@ -1805,6 +1871,7 @@ extern "C" { pub fn ZSTD_freeCCtxParams(params: *mut ZSTD_CCtx_params) -> usize; } extern "C" { + /// ZSTD_CCtxParam_setParameter() : /// Similar to ZSTD_CCtx_setParameter. /// Set one compression parameter, selected by enum ZSTD_cParameter. @@ -1818,6 +1885,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_CCtx_setParametersUsingCCtxParams() : /// Apply a set of ZSTD_CCtx_params to the compression context. /// This must be done before the dictionary is loaded. @@ -1829,6 +1897,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_DCtx_loadDictionary() : /// Create an internal DDict from dict buffer, /// to be used to decompress next frames. @@ -1866,6 +1935,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_DCtx_refDDict() : /// Reference a prepared dictionary, to be used to decompress next frames. /// The dictionary remains active for decompression of future frames using same DCtx. @@ -1880,6 +1950,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_DCtx_refPrefix() : /// Reference a prefix (single-usage dictionary) for next compression job. /// Prefix is **only used once**. It must be explicitly referenced before each frame. @@ -1905,6 +1976,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_DCtx_setMaxWindowSize() : /// Refuses allocating internal buffers for frames requiring a window size larger than provided limit. /// This is useful to prevent a decoder context from reserving too much memory for itself (potential attack scenario). @@ -1917,6 +1989,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_DCtx_setFormat() : /// Instruct the decoder context about what kind of data to decode next. /// This instruction is mandatory to decode data without a fully-formed header, @@ -1928,6 +2001,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_decompress_generic() : /// Behave the same as ZSTD_decompressStream. /// Decompression parameters cannot be changed once decompression is started. @@ -1941,6 +2015,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_decompress_generic_simpleArgs() : /// Same as ZSTD_decompress_generic(), /// but using only integral types as arguments. @@ -1958,6 +2033,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTD_DCtx_reset() : /// Return a DCtx to clean state. /// If a decompression was ongoing, any internal data not yet flushed is cancelled. @@ -1995,6 +2071,7 @@ extern "C" { ) -> 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. @@ -2120,9 +2197,10 @@ extern "C" { ) -> usize; } #[repr(u32)] +#[repr(C)] #[derive(Debug, Copy, Clone, PartialEq, Eq, Hash)] pub enum ZSTDMT_parameter { - ZSTDMT_p_sectionSize = 0, + ZSTDMT_p_jobSize = 0, ZSTDMT_p_overlapSectionLog = 1, } extern "C" { @@ -2133,6 +2211,7 @@ extern "C" { ) -> usize; } extern "C" { + /// ZSTDMT_compressStream_generic() : /// Combines ZSTDMT_compressStream() with ZSTDMT_flushStream() or ZSTDMT_endStream() /// depending on flush directive. @@ -2154,12 +2233,16 @@ extern "C" { ) -> usize; } extern "C" { - pub fn ZSTDMT_initializeCCtxParameters( + pub fn ZSTDMT_CCtxParam_setNbThreads( params: *mut ZSTD_CCtx_params, nbThreads: ::libc::c_uint, ) -> usize; } extern "C" { + pub fn ZSTDMT_getNbThreads(mtctx: *const ZSTDMT_CCtx) -> usize; +} +extern "C" { + /// ZSTDMT_initCStream_internal() : /// Private use only. Init streaming operation. /// expects params to be valid. diff --git a/zstd-safe/zstd-sys/zstd.h b/zstd-safe/zstd-sys/zstd.h index 26e23ca1..370ca217 100644 --- a/zstd-safe/zstd-sys/zstd.h +++ b/zstd-safe/zstd-sys/zstd.h @@ -5,7 +5,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 --use-core -o src/bindings.rs -- -DZSTD_STATIC_LINKING_ONLY +bindgen zstd.h --rustified-enum '.*' --ctypes-prefix ::libc --blacklist-type max_align_t --use-core -o src/bindings.rs -- -DZSTD_STATIC_LINKING_ONLY Or use the `bindgen` feature, which will create the bindings automatically.