Skip to content

Commit c1fa597

Browse files
committed
global: remove use of deprecated ZSTD_copyDCtx()
It was deprecated in 1.5.4. So we started seeing compiler warnings post upgrade. The C change was pretty straightforward. The Rust change not so much, as we had to teach Rust to load the dictionary on the created dctx. Since Rust didn't have this code before, it appears this was actually optional as `ZSTD_copyDCtx()` had the same effect of copying any referenced dictionary data?
1 parent de93ee0 commit c1fa597

File tree

5 files changed

+19
-18
lines changed

5 files changed

+19
-18
lines changed

c-ext/decompressor.c

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1248,8 +1248,6 @@ decompress_from_framesources(ZstdDecompressor *decompressor,
12481248
goto finally;
12491249
}
12501250

1251-
ZSTD_copyDCtx(workerStates[i].dctx, decompressor->dctx);
1252-
12531251
if (decompressor->dict) {
12541252
zresult = ZSTD_DCtx_refDDict(workerStates[i].dctx,
12551253
decompressor->dict->ddict);

docs/news.rst

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,8 @@ Changes
8686
-------
8787

8888
* Bundled zstd library upgraded from 1.5.2 to 1.5.4.
89+
* Use of the deprecated ``ZSTD_copyDCtx()`` was removed from the C and
90+
Rust backends.
8991

9092
0.19.0 (released 2022-10-29)
9193
============================

rust-ext/src/decompressor.rs

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -410,7 +410,13 @@ impl ZstdDecompressor {
410410
) -> PyResult<ZstdBufferWithSegmentsCollection> {
411411
self.setup_dctx(py, true)?;
412412

413-
multi_decompress_to_buffer(py, &self.dctx, frames, decompressed_sizes, threads)
413+
multi_decompress_to_buffer(
414+
py,
415+
self.dict_data.as_ref(),
416+
frames,
417+
decompressed_sizes,
418+
threads,
419+
)
414420
}
415421

416422
#[args(reader, read_size = "None", write_size = "None", skip_bytes = "None")]

rust-ext/src/decompressor_multi.rs

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
use {
88
crate::{
99
buffers::{BufferSegment, ZstdBufferWithSegments, ZstdBufferWithSegmentsCollection},
10+
compression_dict::ZstdCompressionDict,
1011
exceptions::ZstdError,
1112
zstd_safe::DCtx,
1213
},
@@ -27,7 +28,7 @@ struct DataSource<'a> {
2728

2829
pub fn multi_decompress_to_buffer(
2930
py: Python,
30-
dctx: &DCtx,
31+
dict_data: Option<&Py<ZstdCompressionDict>>,
3132
frames: &PyAny,
3233
decompressed_sizes: Option<&PyAny>,
3334
threads: isize,
@@ -129,7 +130,7 @@ pub fn multi_decompress_to_buffer(
129130
));
130131
}
131132

132-
decompress_from_datasources(py, dctx, sources, threads)
133+
decompress_from_datasources(py, dict_data, sources, threads)
133134
}
134135

135136
#[derive(Debug, PartialEq)]
@@ -148,7 +149,7 @@ struct WorkerResult {
148149

149150
fn decompress_from_datasources(
150151
py: Python,
151-
dctx: &DCtx,
152+
dict_data: Option<&Py<ZstdCompressionDict>>,
152153
sources: Vec<DataSource>,
153154
thread_count: usize,
154155
) -> PyResult<ZstdBufferWithSegmentsCollection> {
@@ -165,7 +166,12 @@ fn decompress_from_datasources(
165166
// to the C backend.
166167

167168
for _ in 0..thread_count {
168-
let dctx = dctx.try_clone().map_err(ZstdError::new_err)?;
169+
let dctx = DCtx::new().map_err(ZstdError::new_err)?;
170+
171+
if let Some(dict_data) = dict_data {
172+
dict_data.borrow_mut(py).load_into_dctx(&dctx)?;
173+
}
174+
169175
dctxs.push(dctx);
170176
}
171177

rust-ext/src/zstd_safe.rs

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -357,17 +357,6 @@ impl<'a> DCtx<'a> {
357357
Ok(Self(dctx, PhantomData))
358358
}
359359

360-
/// Attempt to create a copy of this instance.
361-
pub fn try_clone(&self) -> Result<Self, &'static str> {
362-
let dctx = Self::new()?;
363-
364-
unsafe {
365-
zstd_sys::ZSTD_copyDCtx(dctx.0, self.0);
366-
}
367-
368-
Ok(dctx)
369-
}
370-
371360
pub fn dctx(&self) -> *mut zstd_sys::ZSTD_DCtx {
372361
self.0
373362
}

0 commit comments

Comments
 (0)