Skip to content

Commit b59becf

Browse files
committed
Propagate C API deprecations through Rust bindings and wrappers
1 parent d8a325a commit b59becf

3 files changed

Lines changed: 35 additions & 6 deletions

File tree

‎zstd-safe/src/lib.rs‎

Lines changed: 31 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -237,7 +237,7 @@ pub fn decompress<C: WriteBuf + ?Sized>(
237237
/// Wraps the `ZSTD_getDecompressedSize` function.
238238
///
239239
/// Returns `None` if the size could not be found, or if the content is actually empty.
240-
#[deprecated(note = "Use ZSTD_getFrameContentSize instead")]
240+
#[deprecated(note = "Use get_frame_content_size instead.")]
241241
pub fn get_decompressed_size(src: &[u8]) -> Option<NonZeroU64> {
242242
// Safety: Just FFI
243243
NonZeroU64::new(unsafe {
@@ -442,7 +442,9 @@ impl<'a> CCtx<'a> {
442442
/// Wraps the `ZSTD_initCStream_srcSize()` function.
443443
#[cfg(feature = "experimental")]
444444
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
445-
#[deprecated]
445+
#[deprecated(
446+
note = "Use reset, set_parameter, and set_pledged_src_size instead."
447+
)]
446448
pub fn init_src_size(
447449
&mut self,
448450
compression_level: CompressionLevel,
@@ -463,7 +465,9 @@ impl<'a> CCtx<'a> {
463465
/// Wraps the `ZSTD_initCStream_usingDict()` function.
464466
#[cfg(feature = "experimental")]
465467
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
466-
#[deprecated]
468+
#[deprecated(
469+
note = "Use reset, set_parameter, and load_dictionary instead."
470+
)]
467471
pub fn init_using_dict(
468472
&mut self,
469473
dict: &[u8],
@@ -486,7 +490,7 @@ impl<'a> CCtx<'a> {
486490
/// Wraps the `ZSTD_initCStream_usingCDict()` function.
487491
#[cfg(feature = "experimental")]
488492
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
489-
#[deprecated]
493+
#[deprecated(note = "Use reset and ref_cdict instead.")]
490494
pub fn init_using_cdict<'b>(&mut self, cdict: &CDict<'b>) -> SafeResult
491495
where
492496
'b: 'a, // Dictionary outlives the stream.
@@ -846,6 +850,9 @@ impl<'a> CCtx<'a> {
846850
/// A poisoned context cannot be cloned until its session is reset.
847851
#[cfg(feature = "experimental")]
848852
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
853+
#[deprecated(
854+
note = "Context copying is deprecated by zstd; create a new context and configure it instead."
855+
)]
849856
pub fn try_clone(
850857
&self,
851858
pledged_src_size: Option<u64>,
@@ -872,6 +879,9 @@ impl<'a> CCtx<'a> {
872879
/// Wraps the `ZSTD_getBlockSize()` function.
873880
#[cfg(feature = "experimental")]
874881
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
882+
#[deprecated(
883+
note = "The block API is deprecated; use the normal compression API instead."
884+
)]
875885
pub fn get_block_size(&self) -> usize {
876886
// Safety: Just FFI
877887
unsafe { zstd_sys::ZSTD_getBlockSize(self.0.as_ptr()) }
@@ -886,6 +896,9 @@ impl<'a> CCtx<'a> {
886896
/// following block is compressed against it.
887897
#[cfg(feature = "experimental")]
888898
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
899+
#[deprecated(
900+
note = "The block API is deprecated; use compress_stream2 instead."
901+
)]
889902
pub unsafe fn compress_block<C: WriteBuf + ?Sized>(
890903
&mut self,
891904
dst: &mut C,
@@ -1146,7 +1159,7 @@ impl<'a> DCtx<'a> {
11461159
/// Wraps the `ZSTD_initDStream_usingDict()` function.
11471160
#[cfg(feature = "experimental")]
11481161
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
1149-
#[deprecated]
1162+
#[deprecated(note = "Use reset and load_dictionary instead.")]
11501163
pub fn init_using_dict(&mut self, dict: &[u8]) -> SafeResult {
11511164
self.2.clear();
11521165
self.2.clear();
@@ -1163,7 +1176,7 @@ impl<'a> DCtx<'a> {
11631176
/// Wraps the `ZSTD_initDStream_usingDDict()` function.
11641177
#[cfg(feature = "experimental")]
11651178
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
1166-
#[deprecated]
1179+
#[deprecated(note = "Use reset and ref_ddict instead.")]
11671180
pub fn init_using_ddict<'b>(&mut self, ddict: &DDict<'b>) -> SafeResult
11681181
where
11691182
'b: 'a,
@@ -1358,6 +1371,9 @@ impl<'a> DCtx<'a> {
13581371
/// context (or until this context is dropped), as the following block is decoded against it.
13591372
#[cfg(feature = "experimental")]
13601373
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
1374+
#[deprecated(
1375+
note = "The block API is deprecated; use decompress_stream instead."
1376+
)]
13611377
pub unsafe fn decompress_block<C: WriteBuf + ?Sized>(
13621378
&mut self,
13631379
dst: &mut C,
@@ -1385,6 +1401,9 @@ impl<'a> DCtx<'a> {
13851401
/// context is dropped), as the following block is decoded against it.
13861402
#[cfg(feature = "experimental")]
13871403
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
1404+
#[deprecated(
1405+
note = "The block API is deprecated; use decompress_stream instead."
1406+
)]
13881407
pub unsafe fn insert_block(&mut self, block: &[u8]) -> usize {
13891408
unsafe {
13901409
zstd_sys::ZSTD_insertBlock(
@@ -1402,6 +1421,9 @@ impl<'a> DCtx<'a> {
14021421
/// A poisoned context cannot be cloned until its session is reset.
14031422
#[cfg(feature = "experimental")]
14041423
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
1424+
#[deprecated(
1425+
note = "Context copying is deprecated by zstd; create a new context and configure it instead."
1426+
)]
14051427
pub fn try_clone(&self) -> Result<Self, ErrorCode> {
14061428
// An error may leave the C context undefined; do not copy it.
14071429
self.2.guard()?;
@@ -2610,6 +2632,9 @@ pub fn get_dict_id(dict_buffer: &[u8]) -> Option<NonZeroU32> {
26102632
/// Wraps the `ZSTD_getBlockSize()` function.
26112633
#[cfg(feature = "experimental")]
26122634
#[cfg_attr(feature = "doc-cfg", doc(cfg(feature = "experimental")))]
2635+
#[deprecated(
2636+
note = "The block API is deprecated; use the normal compression API instead."
2637+
)]
26132638
pub fn get_block_size(cctx: &CCtx) -> usize {
26142639
unsafe { zstd_sys::ZSTD_getBlockSize(cctx.0.as_ptr()) }
26152640
}

‎zstd-safe/src/tests.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -420,6 +420,7 @@ fn test_poison_tracking() {
420420

421421
#[cfg(all(feature = "std", feature = "experimental"))]
422422
#[test]
423+
#[allow(deprecated)] // Exercises the deprecated context-copying API.
423424
fn test_cloning_poisoned_contexts_returns_the_original_error() {
424425
use crate::{CCtx, DCtx, InBuffer, OutBuffer};
425426

@@ -440,6 +441,7 @@ fn test_cloning_poisoned_contexts_returns_the_original_error() {
440441

441442
#[cfg(all(feature = "std", feature = "experimental"))]
442443
#[test]
444+
#[allow(deprecated)] // Exercises the deprecated context-copying API.
443445
fn test_cloning_initialized_compression_context() {
444446
use crate::{parse_code, zstd_sys, CCtx, DCtx};
445447

‎zstd-safe/tests/with_rust_allocator_clones.rs‎

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// These tests cover allocator safety of the deprecated context-copying API.
2+
#![allow(deprecated)]
13
#![cfg(all(feature = "with-rust-allocator", feature = "std"))]
24

35
mod support {

0 commit comments

Comments
 (0)