Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 4468dcb

Browse filesBrowse files
committed
Switch to libz-rs-sys for zlib implementation
1 parent 235adaf commit 4468dcb
Copy full SHA for 4468dcb

File tree

7 files changed

+29
-68
lines changed
Filter options

7 files changed

+29
-68
lines changed

‎.github/workflows/ci.yaml

Copy file name to clipboardExpand all lines: .github/workflows/ci.yaml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ concurrency:
1515
cancel-in-progress: true
1616

1717
env:
18-
CARGO_ARGS: --no-default-features --features stdlib,zlib,importlib,encodings,sqlite,ssl
18+
CARGO_ARGS: --no-default-features --features stdlib,importlib,encodings,sqlite,ssl
1919
# Skip additional tests on Windows. They are checked on Linux and MacOS.
2020
# test_glob: many failing tests
2121
# test_io: many failing tests

‎.github/workflows/cron-ci.yaml

Copy file name to clipboardExpand all lines: .github/workflows/cron-ci.yaml
+2-2Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ on:
66
name: Periodic checks/tasks
77

88
env:
9-
CARGO_ARGS: --no-default-features --features stdlib,zlib,importlib,encodings,ssl,jit
9+
CARGO_ARGS: --no-default-features --features stdlib,importlib,encodings,ssl,jit
1010
PYTHON_VERSION: "3.13.1"
1111

1212
jobs:
@@ -24,7 +24,7 @@ jobs:
2424
python-version: ${{ env.PYTHON_VERSION }}
2525
- run: sudo apt-get update && sudo apt-get -y install lcov
2626
- name: Run cargo-llvm-cov with Rust tests.
27-
run: cargo llvm-cov --no-report --workspace --exclude rustpython_wasm --verbose --no-default-features --features stdlib,zlib,importlib,encodings,ssl,jit
27+
run: cargo llvm-cov --no-report --workspace --exclude rustpython_wasm --verbose --no-default-features --features stdlib,importlib,encodings,ssl,jit
2828
- name: Run cargo-llvm-cov with Python snippets.
2929
run: python scripts/cargo-llvm-cov.py
3030
continue-on-error: true

‎.github/workflows/release.yml

Copy file name to clipboardExpand all lines: .github/workflows/release.yml
+1-1Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ permissions:
1616
contents: write
1717

1818
env:
19-
CARGO_ARGS: --no-default-features --features stdlib,zlib,importlib,encodings,sqlite,ssl
19+
CARGO_ARGS: --no-default-features --features stdlib,importlib,encodings,sqlite,ssl
2020

2121
jobs:
2222
build:

‎Cargo.lock

Copy file name to clipboardExpand all lines: Cargo.lock
+14-10Lines changed: 14 additions & 10 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

‎Cargo.toml

Copy file name to clipboardExpand all lines: Cargo.toml
+1-2Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,14 @@ repository.workspace = true
1010
license.workspace = true
1111

1212
[features]
13-
default = ["threading", "stdlib", "zlib", "importlib"]
13+
default = ["threading", "stdlib", "importlib"]
1414
importlib = ["rustpython-vm/importlib"]
1515
encodings = ["rustpython-vm/encodings"]
1616
stdlib = ["rustpython-stdlib", "rustpython-pylib", "encodings"]
1717
flame-it = ["rustpython-vm/flame-it", "flame", "flamescope"]
1818
freeze-stdlib = ["stdlib", "rustpython-vm/freeze-stdlib", "rustpython-pylib?/freeze-stdlib"]
1919
jit = ["rustpython-vm/jit"]
2020
threading = ["rustpython-vm/threading", "rustpython-stdlib/threading"]
21-
zlib = ["stdlib", "rustpython-stdlib/zlib"]
2221
bz2 = ["stdlib", "rustpython-stdlib/bz2"]
2322
sqlite = ["rustpython-stdlib/sqlite"]
2423
ssl = ["rustpython-stdlib/ssl"]

‎stdlib/Cargo.toml

Copy file name to clipboardExpand all lines: stdlib/Cargo.toml
+2-3Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,6 @@ license.workspace = true
1414
default = ["compiler"]
1515
compiler = ["rustpython-vm/compiler"]
1616
threading = ["rustpython-common/threading", "rustpython-vm/threading"]
17-
zlib = ["libz-sys", "flate2/zlib"]
1817
bz2 = ["bzip2"]
1918
sqlite = ["dep:libsqlite3-sys"]
2019
ssl = ["openssl", "openssl-sys", "foreign-types-shared", "openssl-probe"]
@@ -48,7 +47,6 @@ memchr = { workspace = true }
4847
base64 = "0.13.0"
4948
csv-core = "0.1.11"
5049
dyn-clone = "1.0.10"
51-
libz-sys = { version = "1.1", default-features = false, optional = true }
5250
puruspe = "0.4.0"
5351
xml-rs = "0.8.14"
5452

@@ -81,7 +79,8 @@ ucd = "0.1.1"
8179
# compression
8280
adler32 = "1.2.0"
8381
crc32fast = "1.3.2"
84-
flate2 = "1.0.28"
82+
flate2 = { version = "1.1", default-features = false, features = ["zlib-rs"] }
83+
libz-sys = { package = "libz-rs-sys", version = "0.4" }
8584
bzip2 = { version = "0.4", optional = true }
8685

8786
# uuid

‎stdlib/src/zlib.rs

Copy file name to clipboardExpand all lines: stdlib/src/zlib.rs
+8-49Lines changed: 8 additions & 49 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@ mod zlib {
99
common::lock::PyMutex,
1010
convert::TryFromBorrowedObject,
1111
function::{ArgBytesLike, ArgPrimitiveIndex, ArgSize, OptionalArg},
12+
types::Constructor,
1213
PyObject, PyPayload, PyResult, VirtualMachine,
1314
};
1415
use adler32::RollingAdler32 as Adler32;
@@ -19,35 +20,12 @@ mod zlib {
1920
};
2021
use std::io::Write;
2122

22-
#[cfg(not(feature = "zlib"))]
23-
mod constants {
24-
pub const Z_NO_COMPRESSION: i32 = 0;
25-
pub const Z_BEST_COMPRESSION: i32 = 9;
26-
pub const Z_BEST_SPEED: i32 = 1;
27-
pub const Z_DEFAULT_COMPRESSION: i32 = -1;
28-
pub const Z_NO_FLUSH: i32 = 0;
29-
pub const Z_PARTIAL_FLUSH: i32 = 1;
30-
pub const Z_SYNC_FLUSH: i32 = 2;
31-
pub const Z_FULL_FLUSH: i32 = 3;
32-
// not sure what the value here means, but it's the only compression method zlibmodule
33-
// supports, so it doesn't really matter
34-
pub const Z_DEFLATED: i32 = 8;
35-
}
36-
#[cfg(feature = "zlib")]
37-
use libz_sys as constants;
38-
39-
#[pyattr]
40-
use constants::{
41-
Z_BEST_COMPRESSION, Z_BEST_SPEED, Z_DEFAULT_COMPRESSION, Z_DEFLATED as DEFLATED,
42-
Z_FULL_FLUSH, Z_NO_COMPRESSION, Z_NO_FLUSH, Z_PARTIAL_FLUSH, Z_SYNC_FLUSH,
43-
};
44-
45-
#[cfg(feature = "zlib")]
4623
#[pyattr]
4724
use libz_sys::{
48-
Z_BLOCK, Z_DEFAULT_STRATEGY, Z_FILTERED, Z_FINISH, Z_FIXED, Z_HUFFMAN_ONLY, Z_RLE, Z_TREES,
25+
Z_BEST_COMPRESSION, Z_BEST_SPEED, Z_BLOCK, Z_DEFAULT_COMPRESSION, Z_DEFAULT_STRATEGY,
26+
Z_DEFLATED as DEFLATED, Z_FILTERED, Z_FINISH, Z_FIXED, Z_FULL_FLUSH, Z_HUFFMAN_ONLY,
27+
Z_NO_COMPRESSION, Z_NO_FLUSH, Z_PARTIAL_FLUSH, Z_RLE, Z_SYNC_FLUSH, Z_TREES,
4928
};
50-
use rustpython_vm::types::Constructor;
5129

5230
// copied from zlibmodule.c (commit 530f506ac91338)
5331
#[pyattr]
@@ -119,48 +97,35 @@ mod zlib {
11997
header: bool,
12098
// [De]Compress::new_with_window_bits is only enabled for zlib; miniz_oxide doesn't
12199
// support wbits (yet?)
122-
#[cfg(feature = "zlib")]
123100
wbits: u8,
124101
},
125-
#[cfg(feature = "zlib")]
126-
Gzip { wbits: u8 },
102+
Gzip {
103+
wbits: u8,
104+
},
127105
}
128106

129107
impl InitOptions {
130108
fn new(wbits: i8, vm: &VirtualMachine) -> PyResult<InitOptions> {
131109
let header = wbits > 0;
132110
let wbits = wbits.unsigned_abs();
133111
match wbits {
134-
9..=15 => Ok(InitOptions::Standard {
135-
header,
136-
#[cfg(feature = "zlib")]
137-
wbits,
138-
}),
139-
#[cfg(feature = "zlib")]
112+
9..=15 => Ok(InitOptions::Standard { header, wbits }),
140113
25..=31 => Ok(InitOptions::Gzip { wbits: wbits - 16 }),
141114
_ => Err(vm.new_value_error("Invalid initialization option".to_owned())),
142115
}
143116
}
144117

145118
fn decompress(self) -> Decompress {
146119
match self {
147-
#[cfg(not(feature = "zlib"))]
148-
Self::Standard { header } => Decompress::new(header),
149-
#[cfg(feature = "zlib")]
150120
Self::Standard { header, wbits } => Decompress::new_with_window_bits(header, wbits),
151-
#[cfg(feature = "zlib")]
152121
Self::Gzip { wbits } => Decompress::new_gzip(wbits),
153122
}
154123
}
155124
fn compress(self, level: Compression) -> Compress {
156125
match self {
157-
#[cfg(not(feature = "zlib"))]
158-
Self::Standard { header } => Compress::new(level, header),
159-
#[cfg(feature = "zlib")]
160126
Self::Standard { header, wbits } => {
161127
Compress::new_with_window_bits(level, header, wbits)
162128
}
163-
#[cfg(feature = "zlib")]
164129
Self::Gzip { wbits } => Compress::new_gzip(level, wbits),
165130
}
166131
}
@@ -264,7 +229,6 @@ mod zlib {
264229
struct DecompressobjArgs {
265230
#[pyarg(any, default = "ArgPrimitiveIndex { value: MAX_WBITS }")]
266231
wbits: ArgPrimitiveIndex<i8>,
267-
#[cfg(feature = "zlib")]
268232
#[pyarg(any, optional)]
269233
_zdict: OptionalArg<ArgBytesLike>,
270234
}
@@ -273,7 +237,6 @@ mod zlib {
273237
fn decompressobj(args: DecompressobjArgs, vm: &VirtualMachine) -> PyResult<PyDecompress> {
274238
#[allow(unused_mut)]
275239
let mut decompress = InitOptions::new(args.wbits.value, vm)?.decompress();
276-
#[cfg(feature = "zlib")]
277240
if let OptionalArg::Present(_dict) = args._zdict {
278241
// FIXME: always fails
279242
// dict.with_ref(|d| decompress.set_dictionary(d));
@@ -426,10 +389,8 @@ mod zlib {
426389
wbits: ArgPrimitiveIndex<i8>,
427390
#[pyarg(any, name = "_memLevel", default = "DEF_MEM_LEVEL")]
428391
_mem_level: u8,
429-
#[cfg(feature = "zlib")]
430392
#[pyarg(any, default = "Z_DEFAULT_STRATEGY")]
431393
_strategy: i32,
432-
#[cfg(feature = "zlib")]
433394
#[pyarg(any, optional)]
434395
zdict: Option<ArgBytesLike>,
435396
}
@@ -439,15 +400,13 @@ mod zlib {
439400
let CompressobjArgs {
440401
level,
441402
wbits,
442-
#[cfg(feature = "zlib")]
443403
zdict,
444404
..
445405
} = args;
446406
let level =
447407
level.ok_or_else(|| vm.new_value_error("invalid initialization option".to_owned()))?;
448408
#[allow(unused_mut)]
449409
let mut compress = InitOptions::new(wbits.value, vm)?.compress(level);
450-
#[cfg(feature = "zlib")]
451410
if let Some(zdict) = zdict {
452411
zdict.with_ref(|zdict| compress.set_dictionary(zdict).unwrap());
453412
}

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.