@@ -9,6 +9,7 @@ mod zlib {
9
9
common:: lock:: PyMutex ,
10
10
convert:: TryFromBorrowedObject ,
11
11
function:: { ArgBytesLike , ArgPrimitiveIndex , ArgSize , OptionalArg } ,
12
+ types:: Constructor ,
12
13
PyObject , PyPayload , PyResult , VirtualMachine ,
13
14
} ;
14
15
use adler32:: RollingAdler32 as Adler32 ;
@@ -19,35 +20,12 @@ mod zlib {
19
20
} ;
20
21
use std:: io:: Write ;
21
22
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" ) ]
46
23
#[ pyattr]
47
24
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 ,
49
28
} ;
50
- use rustpython_vm:: types:: Constructor ;
51
29
52
30
// copied from zlibmodule.c (commit 530f506ac91338)
53
31
#[ pyattr]
@@ -119,48 +97,35 @@ mod zlib {
119
97
header : bool ,
120
98
// [De]Compress::new_with_window_bits is only enabled for zlib; miniz_oxide doesn't
121
99
// support wbits (yet?)
122
- #[ cfg( feature = "zlib" ) ]
123
100
wbits : u8 ,
124
101
} ,
125
- #[ cfg( feature = "zlib" ) ]
126
- Gzip { wbits : u8 } ,
102
+ Gzip {
103
+ wbits : u8 ,
104
+ } ,
127
105
}
128
106
129
107
impl InitOptions {
130
108
fn new ( wbits : i8 , vm : & VirtualMachine ) -> PyResult < InitOptions > {
131
109
let header = wbits > 0 ;
132
110
let wbits = wbits. unsigned_abs ( ) ;
133
111
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 } ) ,
140
113
25 ..=31 => Ok ( InitOptions :: Gzip { wbits : wbits - 16 } ) ,
141
114
_ => Err ( vm. new_value_error ( "Invalid initialization option" . to_owned ( ) ) ) ,
142
115
}
143
116
}
144
117
145
118
fn decompress ( self ) -> Decompress {
146
119
match self {
147
- #[ cfg( not( feature = "zlib" ) ) ]
148
- Self :: Standard { header } => Decompress :: new ( header) ,
149
- #[ cfg( feature = "zlib" ) ]
150
120
Self :: Standard { header, wbits } => Decompress :: new_with_window_bits ( header, wbits) ,
151
- #[ cfg( feature = "zlib" ) ]
152
121
Self :: Gzip { wbits } => Decompress :: new_gzip ( wbits) ,
153
122
}
154
123
}
155
124
fn compress ( self , level : Compression ) -> Compress {
156
125
match self {
157
- #[ cfg( not( feature = "zlib" ) ) ]
158
- Self :: Standard { header } => Compress :: new ( level, header) ,
159
- #[ cfg( feature = "zlib" ) ]
160
126
Self :: Standard { header, wbits } => {
161
127
Compress :: new_with_window_bits ( level, header, wbits)
162
128
}
163
- #[ cfg( feature = "zlib" ) ]
164
129
Self :: Gzip { wbits } => Compress :: new_gzip ( level, wbits) ,
165
130
}
166
131
}
@@ -264,7 +229,6 @@ mod zlib {
264
229
struct DecompressobjArgs {
265
230
#[ pyarg( any, default = "ArgPrimitiveIndex { value: MAX_WBITS }" ) ]
266
231
wbits : ArgPrimitiveIndex < i8 > ,
267
- #[ cfg( feature = "zlib" ) ]
268
232
#[ pyarg( any, optional) ]
269
233
_zdict : OptionalArg < ArgBytesLike > ,
270
234
}
@@ -273,7 +237,6 @@ mod zlib {
273
237
fn decompressobj ( args : DecompressobjArgs , vm : & VirtualMachine ) -> PyResult < PyDecompress > {
274
238
#[ allow( unused_mut) ]
275
239
let mut decompress = InitOptions :: new ( args. wbits . value , vm) ?. decompress ( ) ;
276
- #[ cfg( feature = "zlib" ) ]
277
240
if let OptionalArg :: Present ( _dict) = args. _zdict {
278
241
// FIXME: always fails
279
242
// dict.with_ref(|d| decompress.set_dictionary(d));
@@ -426,10 +389,8 @@ mod zlib {
426
389
wbits : ArgPrimitiveIndex < i8 > ,
427
390
#[ pyarg( any, name = "_memLevel" , default = "DEF_MEM_LEVEL" ) ]
428
391
_mem_level : u8 ,
429
- #[ cfg( feature = "zlib" ) ]
430
392
#[ pyarg( any, default = "Z_DEFAULT_STRATEGY" ) ]
431
393
_strategy : i32 ,
432
- #[ cfg( feature = "zlib" ) ]
433
394
#[ pyarg( any, optional) ]
434
395
zdict : Option < ArgBytesLike > ,
435
396
}
@@ -439,15 +400,13 @@ mod zlib {
439
400
let CompressobjArgs {
440
401
level,
441
402
wbits,
442
- #[ cfg( feature = "zlib" ) ]
443
403
zdict,
444
404
..
445
405
} = args;
446
406
let level =
447
407
level. ok_or_else ( || vm. new_value_error ( "invalid initialization option" . to_owned ( ) ) ) ?;
448
408
#[ allow( unused_mut) ]
449
409
let mut compress = InitOptions :: new ( wbits. value , vm) ?. compress ( level) ;
450
- #[ cfg( feature = "zlib" ) ]
451
410
if let Some ( zdict) = zdict {
452
411
zdict. with_ref ( |zdict| compress. set_dictionary ( zdict) . unwrap ( ) ) ;
453
412
}
0 commit comments