Skip to content

Commit b0ac427

Browse files
committed
Add deprecated attributes modelled off zstd.h definitions
1 parent d654444 commit b0ac427

File tree

5 files changed

+129
-2
lines changed

5 files changed

+129
-2
lines changed

c2rust-lib.rs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ pub use crate::lib::zstd::{
111111
ZSTD_WINDOWLOG_MAX_64,
112112
};
113113

114+
#[allow(deprecated)] // We still export deprecated functions
114115
pub use crate::lib::decompress::{
115116
zstd_ddict::{
116117
ZSTD_DDict, ZSTD_createDDict, ZSTD_createDDict_byReference, ZSTD_estimateDDictSize,
@@ -150,6 +151,7 @@ pub use crate::lib::zdict::{
150151
ZDICT_getDictID, ZDICT_getErrorName, ZDICT_isError, ZDICT_params_t, ZDICT_trainFromBuffer,
151152
};
152153

154+
#[allow(deprecated)] // We still export deprecated functions
153155
pub use crate::lib::compress::zstd_compress::{
154156
ZSTD_CCtx, ZSTD_CCtx_getParameter, ZSTD_CCtx_loadDictionary, ZSTD_CCtx_refCDict,
155157
ZSTD_CCtx_refPrefix, ZSTD_CCtx_reset, ZSTD_CCtx_setParameter, ZSTD_CCtx_setPledgedSrcSize,

lib/compress/zstd_compress.rs

Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4495,6 +4495,10 @@ unsafe fn ZSTD_copyCCtx_internal(
44954495
);
44964496
0
44974497
}
4498+
4499+
#[deprecated(
4500+
note = "This function will likely be removed in a future release. It is misleading and has very limited utility."
4501+
)]
44984502
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_copyCCtx))]
44994503
pub unsafe extern "C" fn ZSTD_copyCCtx(
45004504
dstCCtx: *mut ZSTD_CCtx,
@@ -5509,6 +5513,11 @@ pub unsafe extern "C" fn ZSTD_sequenceBound(srcSize: size_t) -> size_t {
55095513
let maxNbDelims = (srcSize / ZSTD_BLOCKSIZE_MAX_MIN as size_t).wrapping_add(1);
55105514
maxNbSeq.wrapping_add(maxNbDelims)
55115515
}
5516+
5517+
#[deprecated(
5518+
since = "1.5.6",
5519+
note = "For debugging only, will be replaced by [`ZSTD_extractSequences`]"
5520+
)]
55125521
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_generateSequences))]
55135522
pub unsafe extern "C" fn ZSTD_generateSequences(
55145523
zc: *mut ZSTD_CCtx,
@@ -7131,6 +7140,7 @@ unsafe extern "C" fn ZSTD_compressContinue_internal(
71317140
}
71327141
cSize.wrapping_add(fhSize)
71337142
}
7143+
71347144
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressContinue_public))]
71357145
pub unsafe extern "C" fn ZSTD_compressContinue_public(
71367146
cctx: *mut ZSTD_CCtx,
@@ -7141,6 +7151,11 @@ pub unsafe extern "C" fn ZSTD_compressContinue_public(
71417151
) -> size_t {
71427152
ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 1, 0)
71437153
}
7154+
7155+
#[deprecated(
7156+
since = "1.5.5",
7157+
note = "The buffer-less API is deprecated in favor of the normal streaming API. See docs."
7158+
)]
71447159
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressContinue))]
71457160
pub unsafe extern "C" fn ZSTD_compressContinue(
71467161
cctx: *mut ZSTD_CCtx,
@@ -7151,6 +7166,8 @@ pub unsafe extern "C" fn ZSTD_compressContinue(
71517166
) -> size_t {
71527167
ZSTD_compressContinue_public(cctx, dst, dstCapacity, src, srcSize)
71537168
}
7169+
7170+
#[deprecated]
71547171
unsafe fn ZSTD_getBlockSize_deprecated(cctx: *const ZSTD_CCtx) -> size_t {
71557172
let cParams = (*cctx).appliedParams.cParams;
71567173
if (*cctx).appliedParams.maxBlockSize < (1) << cParams.windowLog {
@@ -7159,10 +7176,17 @@ unsafe fn ZSTD_getBlockSize_deprecated(cctx: *const ZSTD_CCtx) -> size_t {
71597176
(1) << cParams.windowLog
71607177
}
71617178
}
7179+
7180+
#[deprecated(
7181+
note = "The block API is deprecated in favor of the normal compression API. See docs."
7182+
)]
71627183
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_getBlockSize))]
71637184
pub unsafe extern "C" fn ZSTD_getBlockSize(cctx: *const ZSTD_CCtx) -> size_t {
7185+
#[allow(deprecated)]
71647186
ZSTD_getBlockSize_deprecated(cctx)
71657187
}
7188+
7189+
#[deprecated(note = "Deprecated definitions that are still used internally.")]
71667190
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressBlock_deprecated))]
71677191
pub unsafe extern "C" fn ZSTD_compressBlock_deprecated(
71687192
cctx: *mut ZSTD_CCtx,
@@ -7171,12 +7195,17 @@ pub unsafe extern "C" fn ZSTD_compressBlock_deprecated(
71717195
src: *const core::ffi::c_void,
71727196
srcSize: size_t,
71737197
) -> size_t {
7198+
#[allow(deprecated)]
71747199
let blockSizeMax = ZSTD_getBlockSize_deprecated(cctx);
71757200
if srcSize > blockSizeMax {
71767201
return Error::srcSize_wrong.to_error_code();
71777202
}
71787203
ZSTD_compressContinue_internal(cctx, dst, dstCapacity, src, srcSize, 0, 0)
71797204
}
7205+
7206+
#[deprecated(
7207+
note = "The block API is deprecated in favor of the normal compression API. See docs."
7208+
)]
71807209
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressBlock))]
71817210
pub unsafe extern "C" fn ZSTD_compressBlock(
71827211
cctx: *mut ZSTD_CCtx,
@@ -7185,8 +7214,10 @@ pub unsafe extern "C" fn ZSTD_compressBlock(
71857214
src: *const core::ffi::c_void,
71867215
srcSize: size_t,
71877216
) -> size_t {
7217+
#[allow(deprecated)]
71887218
ZSTD_compressBlock_deprecated(cctx, dst, dstCapacity, src, srcSize)
71897219
}
7220+
71907221
unsafe fn ZSTD_loadDictionaryContent(
71917222
ms: &mut ZSTD_MatchState_t,
71927223
ls: *mut ldmState_t,
@@ -7670,6 +7701,8 @@ pub unsafe fn ZSTD_compressBegin_advanced_internal(
76707701
ZSTDb_not_buffered,
76717702
)
76727703
}
7704+
7705+
#[deprecated(since = "1.5.0", note = "use advanced API to access custom parameters")]
76737706
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressBegin_advanced))]
76747707
pub unsafe extern "C" fn ZSTD_compressBegin_advanced(
76757708
cctx: *mut ZSTD_CCtx,
@@ -7825,6 +7858,11 @@ unsafe fn ZSTD_compressBegin_usingDict_deprecated(
78257858
ZSTDb_not_buffered,
78267859
)
78277860
}
7861+
7862+
#[deprecated(
7863+
since = "1.5.5",
7864+
note = "The buffer-less API is deprecated in favor of the normal streaming API. See docs."
7865+
)]
78287866
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressBegin_usingDict))]
78297867
pub unsafe extern "C" fn ZSTD_compressBegin_usingDict(
78307868
cctx: *mut ZSTD_CCtx,
@@ -7834,6 +7872,11 @@ pub unsafe extern "C" fn ZSTD_compressBegin_usingDict(
78347872
) -> size_t {
78357873
ZSTD_compressBegin_usingDict_deprecated(cctx, dict, dictSize, compressionLevel)
78367874
}
7875+
7876+
#[deprecated(
7877+
since = "1.5.5",
7878+
note = "The buffer-less API is deprecated in favor of the normal streaming API. See docs."
7879+
)]
78377880
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressBegin))]
78387881
pub unsafe extern "C" fn ZSTD_compressBegin(
78397882
cctx: *mut ZSTD_CCtx,
@@ -7935,6 +7978,11 @@ pub unsafe extern "C" fn ZSTD_compressEnd_public(
79357978
ZSTD_CCtx_trace(cctx, endResult);
79367979
cSize.wrapping_add(endResult)
79377980
}
7981+
7982+
#[deprecated(
7983+
since = "1.5.5",
7984+
note = "The buffer-less API is deprecated in favor of the normal streaming API. See docs."
7985+
)]
79387986
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressEnd))]
79397987
pub unsafe extern "C" fn ZSTD_compressEnd(
79407988
cctx: *mut ZSTD_CCtx,
@@ -7945,6 +7993,11 @@ pub unsafe extern "C" fn ZSTD_compressEnd(
79457993
) -> size_t {
79467994
ZSTD_compressEnd_public(cctx, dst, dstCapacity, src, srcSize)
79477995
}
7996+
7997+
#[deprecated(
7998+
since = "1.5.0",
7999+
note = "It can be replaced by [`ZSTD_compress2`], in combination with [`ZSTD_CCtx_setParameter`] and other parameter setters."
8000+
)]
79488001
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compress_advanced))]
79498002
pub unsafe extern "C" fn ZSTD_compress_advanced(
79508003
cctx: *mut ZSTD_CCtx,
@@ -9128,6 +9181,11 @@ unsafe fn ZSTD_compressBegin_usingCDict_internal(
91289181
ZSTDb_not_buffered,
91299182
)
91309183
}
9184+
9185+
#[deprecated(
9186+
since = "1.5.0",
9187+
note = "use advanced API to access custom parameters."
9188+
)]
91319189
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressBegin_usingCDict_advanced))]
91329190
pub unsafe extern "C" fn ZSTD_compressBegin_usingCDict_advanced(
91339191
cctx: *mut ZSTD_CCtx,
@@ -9137,6 +9195,8 @@ pub unsafe extern "C" fn ZSTD_compressBegin_usingCDict_advanced(
91379195
) -> size_t {
91389196
ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, pledgedSrcSize)
91399197
}
9198+
9199+
#[deprecated(note = "Deprecated definitions that are still used internally.")]
91409200
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressBegin_usingCDict_deprecated))]
91419201
pub unsafe extern "C" fn ZSTD_compressBegin_usingCDict_deprecated(
91429202
cctx: *mut ZSTD_CCtx,
@@ -9151,13 +9211,20 @@ pub unsafe extern "C" fn ZSTD_compressBegin_usingCDict_deprecated(
91519211
};
91529212
ZSTD_compressBegin_usingCDict_internal(cctx, cdict, fParams, ZSTD_CONTENTSIZE_UNKNOWN)
91539213
}
9214+
9215+
#[deprecated(
9216+
since = "1.5.5",
9217+
note = "The buffer-less API is deprecated in favor of the normal streaming API. See docs."
9218+
)]
91549219
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compressBegin_usingCDict))]
91559220
pub unsafe extern "C" fn ZSTD_compressBegin_usingCDict(
91569221
cctx: *mut ZSTD_CCtx,
91579222
cdict: *const ZSTD_CDict,
91589223
) -> size_t {
9224+
#[allow(deprecated)]
91599225
ZSTD_compressBegin_usingCDict_deprecated(cctx, cdict)
91609226
}
9227+
91619228
unsafe fn ZSTD_compress_usingCDict_internal(
91629229
cctx: *mut ZSTD_CCtx,
91639230
dst: *mut core::ffi::c_void,
@@ -9178,6 +9245,11 @@ unsafe fn ZSTD_compress_usingCDict_internal(
91789245
}
91799246
ZSTD_compressEnd_public(cctx, dst, dstCapacity, src, srcSize)
91809247
}
9248+
9249+
#[deprecated(
9250+
since = "1.5.0",
9251+
note = "It can be replaced by [` ZSTD_compress2`], in combination with [`ZSTD_CCtx_loadDictionary`] and other parameter setters."
9252+
)]
91819253
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_compress_usingCDict_advanced))]
91829254
pub unsafe extern "C" fn ZSTD_compress_usingCDict_advanced(
91839255
cctx: *mut ZSTD_CCtx,
@@ -9250,6 +9322,11 @@ unsafe fn ZSTD_getCParamMode(
92509322
ZSTD_cpm_noAttachDict
92519323
}
92529324
}
9325+
9326+
#[deprecated(
9327+
since = "1.5.0",
9328+
note = "use [`ZSTD_CCtx_reset`], see zstd.h for detailed instructions"
9329+
)]
92539330
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_resetCStream))]
92549331
pub unsafe extern "C" fn ZSTD_resetCStream(
92559332
zcs: *mut ZSTD_CStream,
@@ -9300,6 +9377,11 @@ pub unsafe fn ZSTD_initCStream_internal(
93009377
}
93019378
0
93029379
}
9380+
9381+
#[deprecated(
9382+
since = "1.5.0",
9383+
note = "use [`ZSTD_CCtx_reset`] and [`ZSTD_CCtx_refCDict`], see zstd.h for detailed instructions"
9384+
)]
93039385
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_initCStream_usingCDict_advanced))]
93049386
pub unsafe extern "C" fn ZSTD_initCStream_usingCDict_advanced(
93059387
zcs: *mut ZSTD_CStream,
@@ -9322,6 +9404,10 @@ pub unsafe extern "C" fn ZSTD_initCStream_usingCDict_advanced(
93229404
}
93239405
0
93249406
}
9407+
9408+
#[deprecated(
9409+
note = "use ZSTD_CCtx_reset and ZSTD_CCtx_refCDict, see zstd.h for detailed instructions"
9410+
)]
93259411
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_initCStream_usingCDict))]
93269412
pub unsafe extern "C" fn ZSTD_initCStream_usingCDict(
93279413
zcs: *mut ZSTD_CStream,
@@ -9337,6 +9423,11 @@ pub unsafe extern "C" fn ZSTD_initCStream_usingCDict(
93379423
}
93389424
0
93399425
}
9426+
9427+
#[deprecated(
9428+
since = "1.5.0",
9429+
note = "use [`ZSTD_CCtx_reset`], see zstd.h for detailed instructions"
9430+
)]
93409431
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_initCStream_advanced))]
93419432
pub unsafe extern "C" fn ZSTD_initCStream_advanced(
93429433
zcs: *mut ZSTD_CStream,
@@ -9369,6 +9460,11 @@ pub unsafe extern "C" fn ZSTD_initCStream_advanced(
93699460
}
93709461
0
93719462
}
9463+
9464+
#[deprecated(
9465+
since = "1.5.0",
9466+
note = "use ZSTD_CCtx_reset, see zstd.h for detailed instructions"
9467+
)]
93729468
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_initCStream_usingDict))]
93739469
pub unsafe extern "C" fn ZSTD_initCStream_usingDict(
93749470
zcs: *mut ZSTD_CStream,
@@ -9394,6 +9490,11 @@ pub unsafe extern "C" fn ZSTD_initCStream_usingDict(
93949490
}
93959491
0
93969492
}
9493+
9494+
#[deprecated(
9495+
since = "1.5.0",
9496+
note = "use [`ZSTD_CCtx_reset`], see zstd.h for detailed instructions"
9497+
)]
93979498
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_initCStream_srcSize))]
93989499
pub unsafe extern "C" fn ZSTD_initCStream_srcSize(
93999500
zcs: *mut ZSTD_CStream,

lib/decompress/zstd_decompress.rs

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -829,6 +829,9 @@ pub unsafe extern "C" fn ZSTD_freeDCtx(dctx: *mut ZSTD_DCtx) -> size_t {
829829
}
830830

831831
/// No longer useful.
832+
#[deprecated(
833+
note = "This function will likely be removed in the next minor release. It is misleading and has very limited utility."
834+
)]
832835
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_copyDCtx))]
833836
pub unsafe extern "C" fn ZSTD_copyDCtx(dstDCtx: *mut ZSTD_DCtx, srcDCtx: *const ZSTD_DCtx) {
834837
core::ptr::copy_nonoverlapping(
@@ -1385,6 +1388,7 @@ fn find_decompressed_size(mut src: &[u8]) -> u64 {
13851388
/// - the decompressed size field is not present in frame header
13861389
/// - the frame header is unknown or not supported
13871390
/// - or the frame header is not complete (`srcSize` is too small)
1391+
#[deprecated(note = "Replaced by [`ZSTD_getFrameContentSize`]")]
13881392
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_getDecompressedSize))]
13891393
pub unsafe extern "C" fn ZSTD_getDecompressedSize(
13901394
src: *const core::ffi::c_void,
@@ -1658,6 +1662,9 @@ fn decompression_margin(mut src: &[u8]) -> Result<size_t, Error> {
16581662
}
16591663

16601664
/// Insert `src` block into `dctx` history. Useful to track uncompressed blocks.
1665+
#[deprecated(
1666+
note = "The block API is deprecated in favor of the normal compression API. See docs."
1667+
)]
16611668
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_insertBlock))]
16621669
pub unsafe extern "C" fn ZSTD_insertBlock(
16631670
dctx: *mut ZSTD_DCtx,
@@ -2808,6 +2815,9 @@ pub unsafe extern "C" fn ZSTD_DCtx_refPrefix(
28082815
///
28092816
/// - the expected size, aka [`Format::starting_input_length`]
28102817
/// - an error code, which can be tested with [`ZSTD_isError`]
2818+
#[deprecated(
2819+
note = "use [`ZSTD_DCtx_reset`] + [`ZSTD_DCtx_loadDictionary`], see zstd.h for detailed instructions"
2820+
)]
28112821
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_initDStream_usingDict))]
28122822
pub unsafe extern "C" fn ZSTD_initDStream_usingDict(
28132823
zds: *mut ZSTD_DStream,
@@ -2849,6 +2859,9 @@ pub unsafe extern "C" fn ZSTD_initDStream(zds: *mut ZSTD_DStream) -> size_t {
28492859
/// decompression context and then using [`ZSTD_DCtx_refDDict`] to reference the dictionary.
28502860
///
28512861
/// Note: DDict will just be referenced, and must outlive decompression session
2862+
#[deprecated(
2863+
note = "use [`ZSTD_DCtx_reset`] + [`ZSTD_DCtx_refDDict`], see zstd.h for detailed instructions"
2864+
)]
28522865
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_initDStream_usingDDict))]
28532866
pub unsafe extern "C" fn ZSTD_initDStream_usingDDict(
28542867
dctx: *mut ZSTD_DStream,
@@ -2872,6 +2885,7 @@ pub unsafe extern "C" fn ZSTD_initDStream_usingDDict(
28722885
///
28732886
/// - the expected size, aka [`Format::starting_input_length`]
28742887
/// - an error code, which can be tested with [`ZSTD_isError`]
2888+
#[deprecated(note = "use [`ZSTD_DCtx_reset`], see zstd.h for detailed instructions")]
28752889
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_resetDStream))]
28762890
pub unsafe extern "C" fn ZSTD_resetDStream(dctx: *mut ZSTD_DStream) -> size_t {
28772891
let err_code = ZSTD_DCtx_reset(dctx, ZSTD_ResetDirective::ZSTD_reset_session_only);
@@ -2985,6 +2999,7 @@ pub unsafe extern "C" fn ZSTD_DCtx_setMaxWindowSize(
29852999
///
29863000
/// - 0 if format was set successfully
29873001
/// - an error code, which can be tested with [`ZSTD_isError`]
3002+
#[deprecated(note = "use [`ZSTD_DCtx_setParameter`] instead")]
29883003
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_DCtx_setFormat))]
29893004
pub unsafe extern "C" fn ZSTD_DCtx_setFormat(
29903005
dctx: *mut ZSTD_DCtx,

lib/decompress/zstd_decompress_block.rs

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2404,6 +2404,9 @@ pub fn ZSTD_checkContinuity(dctx: &mut ZSTD_DCtx, range: Range<*const u8>) {
24042404
}
24052405
}
24062406

2407+
#[deprecated(
2408+
note = "The block API is deprecated in favor of the normal compression API. See docs."
2409+
)]
24072410
#[cfg_attr(feature = "export-symbols", export_name = crate::prefix!(ZSTD_decompressBlock))]
24082411
pub unsafe extern "C" fn ZSTD_decompressBlock(
24092412
dctx: *mut ZSTD_DCtx,

0 commit comments

Comments
 (0)