Visitar URL original
Add `_zstd` stdlib module backing `compression.zstd` by JamesClarke7283 · Pull Request #7962 · RustPython/RustPython · GitHub
Skip to content
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
20 commits
Select commit Hold shift + click to select a range
9e5c27f
Add _zstd stdlib module backing compression.zstd
JamesClarke7283 May 23, 2026
1def1b4
Fix iOS build by removing static PyMutex<PyTypeRef>
JamesClarke7283 May 23, 2026
ee26123
Fix clippy errors in zstd module
JamesClarke7283 May 23, 2026
fbce9c9
Retrigger CI
JamesClarke7283 May 23, 2026
63103b6
chore: format zstd module
JamesClarke7283 May 23, 2026
77370cb
Update crates/stdlib/src/zstd.rs
JamesClarke7283 May 24, 2026
ace862f
chore: remove rustdoc comments from zstd module
JamesClarke7283 May 24, 2026
07aa356
commit message
JamesClarke7283 May 25, 2026
f7598d6
commit message
JamesClarke7283 May 25, 2026
9b1e29e
Identify zstd parameter enums by type identity, not name
JamesClarke7283 Jun 3, 2026
e6c5b19
Match CPython error behavior in _zstd ZstdCompressor
JamesClarke7283 Jun 3, 2026
dbe4626
Address review: drop decorative separators and unused zstd crate
JamesClarke7283 Aug 9, 2026
9d497f4
Switch _zstd backend from zstd-safe to pure-Rust libzstd-rs-sys
JamesClarke7283 Aug 9, 2026
8fe59b8
Fix data loss in ZstdDecompressor.decompress(max_length=0)
JamesClarke7283 Aug 9, 2026
3d4825e
Drop duplicate spell-checker line in zstd.rs
JamesClarke7283 Aug 9, 2026
52bea59
Address review on _zstd constants, version attrs and dict markers
JamesClarke7283 Aug 19, 2026
1335148
Replace the _zstd flush-mode constants with a CompressMode enum
JamesClarke7283 Aug 19, 2026
68bed04
Correct the _zstd explanatory comments and raise MemoryError on OOM
JamesClarke7283 Aug 19, 2026
e163561
Fix CPython divergences and a crash in the _zstd module
JamesClarke7283 Aug 19, 2026
041f631
Restore Lib/test/test_zstd.py to its vendored CPython state
JamesClarke7283 Aug 19, 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
Address review: drop decorative separators and unused zstd crate
Remove the remaining `// ===...` section separators from zstd.rs per
the project comment guidelines, drop the unused `zstd` crate
dependency (only zstd-safe/zstd-sys are used) and declare zstd-safe's
std feature explicitly instead of relying on the zstd crate's feature
unification, and convert a doc comment on #[extend_class] to a regular
comment.
  • Loading branch information
JamesClarke7283 committed Aug 19, 2026
commit dbe4626d0bebd7af878e1815ae32ed4d8680b5cb
3 changes: 1 addition & 2 deletions Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -323,8 +323,7 @@ x509-cert = "0.3.0"
x509-parser = "0.18"
xml = "1.3"
writeable = "0.6"
zstd = { version = "0.13", default-features = false, features = ["zdict_builder"] }
zstd-safe = { version = "7", default-features = false, features = ["zdict_builder"] }
zstd-safe = { version = "7", default-features = false, features = ["std", "zdict_builder"] }
Comment thread
coderabbitai[bot] marked this conversation as resolved.
Outdated

# Lints

Expand Down
1 change: 0 additions & 1 deletion crates/stdlib/Cargo.toml
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,6 @@ pkcs8 = { workspace = true, features = ["encryption", "pkcs5", "pem"], optional
libsqlite3-sys = { workspace = true, features = ["bundled"], optional = true }
xz = { workspace = true }
xz-sys = { workspace = true }
zstd = { workspace = true }
zstd-safe = { workspace = true }

[target.'cfg(windows)'.dependencies]
Expand Down
36 changes: 4 additions & 32 deletions crates/stdlib/src/zstd.rs
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ mod _zstd {
use zstd_safe::zstd_sys;
use zstd_safe::{CCtx, CParameter, DCtx, DParameter, InBuffer, OutBuffer};

// =========================================================================
// Module-level constants
// =========================================================================

#[pyattr]
const ZSTD_CLEVEL_DEFAULT: i32 = zstd_sys::ZSTD_CLEVEL_DEFAULT as i32;

Expand Down Expand Up @@ -138,10 +134,6 @@ mod _zstd {
const DICT_TYPE_UNDIGESTED: i32 = 1;
const DICT_TYPE_PREFIX: i32 = 2;

// =========================================================================
// ZstdError exception
// =========================================================================

#[pyattr(once, name = "ZstdError")]
fn zstd_error(vm: &VirtualMachine) -> PyTypeRef {
vm.ctx.new_exception_type(
Expand All @@ -163,10 +155,6 @@ mod _zstd {
new_zstd_error(zstd_safe::get_error_name(code).to_string(), vm)
}

// =========================================================================
// Parameter helpers
// =========================================================================

/// Reject an options-dict `key` whose class is the parameter enum that is
/// invalid for the caller's context (a `CompressionParameter` passed to a
/// decompressor, or vice versa) with a `TypeError` naming the type.
Expand Down Expand Up @@ -442,10 +430,6 @@ mod _zstd {
Err(vm.new_type_error("zstd_dict argument should be a ZstdDict object"))
}

// =========================================================================
// ZstdDict
// =========================================================================

#[derive(FromArgs)]
pub(super) struct ZstdDictArgs {
#[pyarg(positional)]
Expand Down Expand Up @@ -558,10 +542,6 @@ mod _zstd {
}
}

// =========================================================================
// ZstdCompressor
// =========================================================================

// The three flush modes for `ZstdCompressor.compress()`, mirrored as
// class attributes via `extend_class` below. Values are positional and
// chosen to match what CPython exposes.
Expand Down Expand Up @@ -1050,10 +1030,10 @@ mod _zstd {
self.state.lock().last_mode
}

/// Install class-level constants `CONTINUE`, `FLUSH_BLOCK`, and
/// `FLUSH_FRAME` so callers can reference them as
/// `ZstdCompressor.FLUSH_FRAME` (as the Python `ZstdFile` wrapper
/// does).
// Install class-level constants `CONTINUE`, `FLUSH_BLOCK`, and
// `FLUSH_FRAME` so callers can reference them as
// `ZstdCompressor.FLUSH_FRAME` (as the Python `ZstdFile` wrapper
// does).
#[extend_class]
fn extend_class(ctx: &Context, class: &'static Py<PyType>) {
class.set_attr(
Expand Down Expand Up @@ -1085,10 +1065,6 @@ mod _zstd {
mode: Option<i32>,
}

// =========================================================================
// ZstdDecompressor
// =========================================================================

/// Internal state of a `ZstdDecompressor`. The CPython decompressor is
/// single-frame: once we hit end-of-frame, additional bytes go into
/// `unused_data` and further `decompress` calls raise `EOFError`. Field
Expand Down Expand Up @@ -1339,10 +1315,6 @@ mod _zstd {
}
}

// =========================================================================
// Module-level functions
// =========================================================================

#[pyfunction]
fn get_frame_size(frame_buffer: ArgBytesLike, vm: &VirtualMachine) -> PyResult<usize> {
let buf = frame_buffer.with_ref(|b| b.to_vec());
Expand Down