Visitar URL original
Add a pure-Rust _zstd module by youknowone · Pull Request #8917 · RustPython/RustPython · GitHub
Skip to content
Draft
Changes from 1 commit
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
4d68d0e
Add _zstd stdlib module backing compression.zstd
JamesClarke7283 May 23, 2026
9b517da
Fix iOS build by removing static PyMutex<PyTypeRef>
JamesClarke7283 May 23, 2026
5720b10
Fix clippy errors in zstd module
JamesClarke7283 May 23, 2026
d5037be
Retrigger CI
JamesClarke7283 May 23, 2026
6a67eaf
chore: format zstd module
JamesClarke7283 May 23, 2026
0ceea4a
Update crates/stdlib/src/zstd.rs
JamesClarke7283 May 24, 2026
e3b6888
chore: remove rustdoc comments from zstd module
JamesClarke7283 May 24, 2026
72b718c
commit message
JamesClarke7283 May 25, 2026
2575363
commit message
JamesClarke7283 May 25, 2026
c812dd8
Identify zstd parameter enums by type identity, not name
JamesClarke7283 Jun 3, 2026
4fa3ca9
Match CPython error behavior in _zstd ZstdCompressor
JamesClarke7283 Jun 3, 2026
dd03057
Address review: drop decorative separators and unused zstd crate
JamesClarke7283 Aug 9, 2026
1593954
Switch _zstd backend from zstd-safe to pure-Rust libzstd-rs-sys
JamesClarke7283 Aug 9, 2026
6d936c6
Fix data loss in ZstdDecompressor.decompress(max_length=0)
JamesClarke7283 Aug 9, 2026
12b96d8
Drop duplicate spell-checker line in zstd.rs
JamesClarke7283 Aug 9, 2026
1f5b219
Address review on _zstd constants, version attrs and dict markers
JamesClarke7283 Aug 19, 2026
116783a
Replace the _zstd flush-mode constants with a CompressMode enum
JamesClarke7283 Aug 19, 2026
692cbe6
Correct the _zstd explanatory comments and raise MemoryError on OOM
JamesClarke7283 Aug 19, 2026
97b63c5
Fix CPython divergences and a crash in the _zstd module
JamesClarke7283 Aug 19, 2026
14aeaee
Restore Lib/test/test_zstd.py to its vendored CPython state
JamesClarke7283 Aug 19, 2026
c5962fb
Rewrite _zstd against rusty_zstd
youknowone Oct 1, 2026
0507916
Use libzstd-rs-sys for _zstd
youknowone Oct 1, 2026
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
commit message
{"subject": "Mark zstd load_dict as unsafe and document invariant", "body": "- Add # Safety docs requiring PyRef<ZstdDict> to outlive the context\n- Wrap calls in load_compressor_dict and load_decompressor_dict with SAFETY comments"}
  • Loading branch information
JamesClarke7283 authored and youknowone committed Oct 1, 2026
commit 72b718c734ba598afa9b783a99e8462a10d670ec
16 changes: 13 additions & 3 deletions crates/stdlib/src/zstd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -828,7 +828,13 @@ mod _zstd {
/// Common path for attaching a dictionary to either context type. Returns
/// the digested `CDict`/`DDict` (if the caller used digested mode) plus
/// the `PyRef<ZstdDict>` we hold to keep the bytes alive for `ref_prefix`.
fn load_dict<L: DictLoader<'static>>(
/// # Safety
///
/// The caller must ensure that the returned `PyRef<ZstdDict>` (if any)
/// outlives the context `ctx`. In `ref_prefix` mode, libzstd stores a
/// raw pointer into the dictionary bytes; the `PyRef` keeps those bytes
/// alive for the required lifetime.
unsafe fn load_dict<L: DictLoader<'static>>(
ctx: &mut L,
dict_obj: Option<PyObjectRef>,
vm: &VirtualMachine,
Expand Down Expand Up @@ -883,15 +889,19 @@ mod _zstd {
dict_obj: Option<PyObjectRef>,
vm: &VirtualMachine,
) -> DictLoadResult<zstd_safe::CDict<'static>> {
load_dict::<CCtx<'static>>(cctx, dict_obj, vm)
// SAFETY: The returned `PyRef<ZstdDict>` is stored alongside the
// `CCtx` in `CompressorState`, so it outlives the context.
unsafe { load_dict::<CCtx<'static>>(cctx, dict_obj, vm) }
}

fn load_decompressor_dict(
dctx: &mut DCtx<'static>,
dict_obj: Option<PyObjectRef>,
vm: &VirtualMachine,
) -> DictLoadResult<zstd_safe::DDict<'static>> {
load_dict::<DCtx<'static>>(dctx, dict_obj, vm)
// SAFETY: The returned `PyRef<ZstdDict>` is stored alongside the
// `DCtx` in `DecompressorState`, so it outlives the context.
unsafe { load_dict::<DCtx<'static>>(dctx, dict_obj, vm) }
}

/// Drive `compress_stream2` until the input is fully consumed and, for
Expand Down