@@ -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