Skip to content

Commit f43ae46

Browse files
authored
xz (#7756)
1 parent 57d1695 commit f43ae46

4 files changed

Lines changed: 62 additions & 54 deletions

File tree

Cargo.lock

Lines changed: 32 additions & 22 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -244,8 +244,8 @@ lexical-parse-float = "1.0.6"
244244
libc = "0.2.186"
245245
libffi = "5"
246246
libloading = "0.9"
247-
liblzma = "0.4"
248-
liblzma-sys = "0.4"
247+
xz = "0.4.6-rc.0"
248+
xz-sys = "0.4.6-rc.0"
249249
libsqlite3-sys = "0.37"
250250
libz-rs-sys = "0.6"
251251
lock_api = "0.4"

crates/stdlib/Cargo.toml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -129,8 +129,8 @@ pkcs8 = { workspace = true, features = ["encryption", "pkcs5", "pem"], optional
129129

130130
[target.'cfg(not(any(target_os = "android", target_arch = "wasm32")))'.dependencies]
131131
libsqlite3-sys = { workspace = true, features = ["bundled"], optional = true }
132-
liblzma = { workspace = true }
133-
liblzma-sys = { workspace = true }
132+
xz = { workspace = true }
133+
xz-sys = { workspace = true }
134134

135135
[target.'cfg(windows)'.dependencies]
136136
paste = { workspace = true }

crates/stdlib/src/lzma.rs

Lines changed: 26 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -9,62 +9,60 @@ mod _lzma {
99
DecompressError, DecompressState, DecompressStatus, Decompressor,
1010
};
1111
use alloc::fmt;
12-
use liblzma::stream::{
12+
use xz::stream::{
1313
Action, Check, Error, Filters, LzmaOptions, MatchFinder, Mode, Status, Stream,
1414
TELL_ANY_CHECK, TELL_NO_CHECK,
1515
};
1616
// lzma_check, lzma_mode, lzma_match_finder have platform-dependent signedness
1717
// (i32 on Windows, u32 elsewhere). Define as fixed-type const to avoid mismatch.
18+
use rustpython_common::lock::PyMutex;
19+
use rustpython_vm::builtins::{PyBaseExceptionRef, PyBytesRef, PyDict, PyType, PyTypeRef};
20+
use rustpython_vm::convert::ToPyException;
21+
use rustpython_vm::function::ArgBytesLike;
22+
use rustpython_vm::types::Constructor;
23+
use rustpython_vm::{Py, PyObjectRef, PyPayload, PyResult, VirtualMachine};
1824
#[pyattr]
19-
use liblzma_sys::{
25+
use xz_sys::{
2026
LZMA_FILTER_ARM as FILTER_ARM, LZMA_FILTER_ARMTHUMB as FILTER_ARMTHUMB,
2127
LZMA_FILTER_DELTA as FILTER_DELTA, LZMA_FILTER_IA64 as FILTER_IA64,
2228
LZMA_FILTER_LZMA1 as FILTER_LZMA1, LZMA_FILTER_LZMA2 as FILTER_LZMA2,
2329
LZMA_FILTER_POWERPC as FILTER_POWERPC, LZMA_FILTER_SPARC as FILTER_SPARC,
2430
LZMA_FILTER_X86 as FILTER_X86,
2531
};
2632
#[pyattr]
27-
use liblzma_sys::{
28-
LZMA_PRESET_DEFAULT as PRESET_DEFAULT, LZMA_PRESET_EXTREME as PRESET_EXTREME,
29-
};
30-
use rustpython_common::lock::PyMutex;
31-
use rustpython_vm::builtins::{PyBaseExceptionRef, PyBytesRef, PyDict, PyType, PyTypeRef};
32-
use rustpython_vm::convert::ToPyException;
33-
use rustpython_vm::function::ArgBytesLike;
34-
use rustpython_vm::types::Constructor;
35-
use rustpython_vm::{Py, PyObjectRef, PyPayload, PyResult, VirtualMachine};
33+
use xz_sys::{LZMA_PRESET_DEFAULT as PRESET_DEFAULT, LZMA_PRESET_EXTREME as PRESET_EXTREME};
3634

3735
const BUFSIZ: usize = 8192;
3836

39-
// liblzma_sys enum types have platform-dependent signedness; `as _` normalizes to i32
37+
// xz_sys enum types have platform-dependent signedness; `as _` normalizes to i32
4038
#[pyattr]
41-
const CHECK_NONE: i32 = liblzma_sys::LZMA_CHECK_NONE as _;
39+
const CHECK_NONE: i32 = xz_sys::LZMA_CHECK_NONE as _;
4240
#[pyattr]
43-
const CHECK_CRC32: i32 = liblzma_sys::LZMA_CHECK_CRC32 as _;
41+
const CHECK_CRC32: i32 = xz_sys::LZMA_CHECK_CRC32 as _;
4442
#[pyattr]
45-
const CHECK_CRC64: i32 = liblzma_sys::LZMA_CHECK_CRC64 as _;
43+
const CHECK_CRC64: i32 = xz_sys::LZMA_CHECK_CRC64 as _;
4644
#[pyattr]
47-
const CHECK_SHA256: i32 = liblzma_sys::LZMA_CHECK_SHA256 as _;
45+
const CHECK_SHA256: i32 = xz_sys::LZMA_CHECK_SHA256 as _;
4846
#[pyattr]
4947
const CHECK_ID_MAX: i32 = 15;
5048
#[pyattr]
5149
const CHECK_UNKNOWN: i32 = CHECK_ID_MAX + 1;
5250

5351
#[pyattr]
54-
const MF_HC3: i32 = liblzma_sys::LZMA_MF_HC3 as _;
52+
const MF_HC3: i32 = xz_sys::LZMA_MF_HC3 as _;
5553
#[pyattr]
56-
const MF_HC4: i32 = liblzma_sys::LZMA_MF_HC4 as _;
54+
const MF_HC4: i32 = xz_sys::LZMA_MF_HC4 as _;
5755
#[pyattr]
58-
const MF_BT2: i32 = liblzma_sys::LZMA_MF_BT2 as _;
56+
const MF_BT2: i32 = xz_sys::LZMA_MF_BT2 as _;
5957
#[pyattr]
60-
const MF_BT3: i32 = liblzma_sys::LZMA_MF_BT3 as _;
58+
const MF_BT3: i32 = xz_sys::LZMA_MF_BT3 as _;
6159
#[pyattr]
62-
const MF_BT4: i32 = liblzma_sys::LZMA_MF_BT4 as _;
60+
const MF_BT4: i32 = xz_sys::LZMA_MF_BT4 as _;
6361

6462
#[pyattr]
65-
const MODE_FAST: i32 = liblzma_sys::LZMA_MODE_FAST as _;
63+
const MODE_FAST: i32 = xz_sys::LZMA_MODE_FAST as _;
6664
#[pyattr]
67-
const MODE_NORMAL: i32 = liblzma_sys::LZMA_MODE_NORMAL as _;
65+
const MODE_NORMAL: i32 = xz_sys::LZMA_MODE_NORMAL as _;
6866

6967
enum Format {
7068
Auto = 0,
@@ -385,13 +383,13 @@ mod _lzma {
385383
Ok(filters)
386384
}
387385

388-
const DEFAULT_LC: u32 = liblzma_sys::LZMA_LC_DEFAULT;
389-
const DEFAULT_LP: u32 = liblzma_sys::LZMA_LP_DEFAULT;
390-
const DEFAULT_PB: u32 = liblzma_sys::LZMA_PB_DEFAULT;
386+
const DEFAULT_LC: u32 = xz_sys::LZMA_LC_DEFAULT;
387+
const DEFAULT_LP: u32 = xz_sys::LZMA_LP_DEFAULT;
388+
const DEFAULT_PB: u32 = xz_sys::LZMA_PB_DEFAULT;
391389
const DICT_POW2: [u8; 10] = [18, 20, 21, 22, 22, 23, 23, 24, 25, 26];
392390

393391
fn preset_dict_size(preset: u32) -> u32 {
394-
let level = (preset & liblzma_sys::LZMA_PRESET_LEVEL_MASK) as usize;
392+
let level = (preset & xz_sys::LZMA_PRESET_LEVEL_MASK) as usize;
395393
if level > 9 {
396394
return 0;
397395
}
@@ -493,7 +491,7 @@ mod _lzma {
493491

494492
#[pyfunction]
495493
fn is_check_supported(check_id: i32) -> bool {
496-
unsafe { liblzma_sys::lzma_check_is_supported(check_id as _) != 0 }
494+
unsafe { xz_sys::lzma_check_is_supported(check_id as _) != 0 }
497495
}
498496

499497
#[pyfunction]

0 commit comments

Comments
 (0)