Skip to content

Commit 0b1d46e

Browse files
authored
Merge pull request #133 from JakubOnderka/update-zlib-ng
Update zlib-ng to 2.1.3
2 parents 8adc826 + 5f2cf8d commit 0b1d46e

File tree

4 files changed

+156
-40
lines changed

4 files changed

+156
-40
lines changed

ci/test.bash

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,3 +39,32 @@ mv Cargo-zng.toml Cargo.toml
3939
mv systest/Cargo-zng.toml systest/Cargo.toml
4040
$CROSS test --target $TARGET_TRIPLE
4141
$CROSS run --target $TARGET_TRIPLE --manifest-path systest/Cargo.toml
42+
43+
echo === flate2 validation ===
44+
git clone https://github.com/rust-lang/flate2-rs flate2
45+
git worktree add flate2/libz-sys
46+
git worktree add flate2/libz-ng-sys
47+
48+
cd flate2
49+
(cd libz-sys
50+
git submodule update --init
51+
)
52+
(cd libz-ng-sys
53+
git submodule update --init
54+
mv systest/Cargo-zng.toml systest/Cargo.toml
55+
mv Cargo-zng.toml Cargo.toml
56+
)
57+
58+
echo "[workspace]" >> Cargo.toml
59+
mkdir .cargo
60+
cat <<EOF >.cargo/config.toml
61+
[patch."crates-io"]
62+
libz-sys = { path = "./libz-sys" }
63+
libz-ng-sys = { path = "./libz-ng-sys" }
64+
EOF
65+
66+
set -x
67+
$CROSS test --features zlib --target $TARGET_TRIPLE
68+
$CROSS test --features zlib-default --no-default-features --target $TARGET_TRIPLE
69+
$CROSS test --features zlib-ng --no-default-features --target $TARGET_TRIPLE
70+
$CROSS test --features zlib-ng-compat --no-default-features --target $TARGET_TRIPLE

src/lib.rs

Lines changed: 117 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#![allow(non_camel_case_types)]
2+
#![allow(non_snake_case)]
23

34
use std::os::raw::{c_char, c_int, c_long, c_uchar, c_uint, c_ulong, c_void};
45

@@ -56,9 +57,12 @@ pub type z_off_t = libc::off_t;
5657
))]
5758
pub type z_off_t = c_long;
5859

59-
#[cfg(zng)]
60+
#[cfg(all(zng, windows, not(target_env = "gnu")))]
6061
pub type z_off_t = i64;
6162

63+
#[cfg(all(zng, not(all(windows, not(target_env = "gnu")))))]
64+
pub type z_off_t = libc::off_t;
65+
6266
#[repr(C)]
6367
#[derive(Copy, Clone)]
6468
pub struct gz_header {
@@ -103,12 +107,16 @@ pub type z_streamp = *mut z_stream;
103107
// can't parse that.
104108
#[cfg(not(zng))]
105109
macro_rules! zng_prefix {
106-
($name:expr) => { stringify!($name) }
110+
($name:expr) => {
111+
stringify!($name)
112+
};
107113
}
108114

109115
#[cfg(zng)]
110116
macro_rules! zng_prefix {
111-
($name:expr) => { concat!("zng_", stringify!($name)) }
117+
($name:expr) => {
118+
concat!("zng_", stringify!($name))
119+
};
112120
}
113121

114122
extern "C" {
@@ -124,24 +132,6 @@ extern "C" {
124132
pub fn deflateCopy(dest: z_streamp, source: z_streamp) -> c_int;
125133
#[link_name = zng_prefix!(deflateEnd)]
126134
pub fn deflateEnd(strm: z_streamp) -> c_int;
127-
#[link_name = zng_prefix!(deflateInit_)]
128-
pub fn deflateInit_(
129-
strm: z_streamp,
130-
level: c_int,
131-
version: *const c_char,
132-
stream_size: c_int,
133-
) -> c_int;
134-
#[link_name = zng_prefix!(deflateInit2_)]
135-
pub fn deflateInit2_(
136-
strm: z_streamp,
137-
level: c_int,
138-
method: c_int,
139-
windowBits: c_int,
140-
memLevel: c_int,
141-
strategy: c_int,
142-
version: *const c_char,
143-
stream_size: c_int,
144-
) -> c_int;
145135
#[link_name = zng_prefix!(deflateParams)]
146136
pub fn deflateParams(strm: z_streamp, level: c_int, strategy: c_int) -> c_int;
147137
#[link_name = zng_prefix!(deflatePrime)]
@@ -176,29 +166,12 @@ extern "C" {
176166
) -> c_int;
177167
#[link_name = zng_prefix!(inflateBackEnd)]
178168
pub fn inflateBackEnd(strm: z_streamp) -> c_int;
179-
#[link_name = zng_prefix!(inflateBackInit_)]
180-
pub fn inflateBackInit_(
181-
strm: z_streamp,
182-
windowBits: c_int,
183-
window: *mut c_uchar,
184-
version: *const c_char,
185-
stream_size: c_int,
186-
) -> c_int;
187169
#[link_name = zng_prefix!(inflateCopy)]
188170
pub fn inflateCopy(dest: z_streamp, source: z_streamp) -> c_int;
189171
#[link_name = zng_prefix!(inflateEnd)]
190172
pub fn inflateEnd(strm: z_streamp) -> c_int;
191173
#[link_name = zng_prefix!(inflateGetHeader)]
192174
pub fn inflateGetHeader(strm: z_streamp, head: gz_headerp) -> c_int;
193-
#[link_name = zng_prefix!(inflateInit_)]
194-
pub fn inflateInit_(strm: z_streamp, version: *const c_char, stream_size: c_int) -> c_int;
195-
#[link_name = zng_prefix!(inflateInit2_)]
196-
pub fn inflateInit2_(
197-
strm: z_streamp,
198-
windowBits: c_int,
199-
version: *const c_char,
200-
stream_size: c_int,
201-
) -> c_int;
202175
#[link_name = zng_prefix!(inflateMark)]
203176
pub fn inflateMark(strm: z_streamp) -> c_long;
204177
#[link_name = zng_prefix!(inflatePrime)]
@@ -245,6 +218,112 @@ extern "C" {
245218
pub fn zlibVersion() -> *const c_char;
246219
}
247220

221+
#[cfg(not(zng))]
222+
extern "C" {
223+
pub fn deflateInit_(
224+
strm: z_streamp,
225+
level: c_int,
226+
version: *const c_char,
227+
stream_size: c_int,
228+
) -> c_int;
229+
pub fn deflateInit2_(
230+
strm: z_streamp,
231+
level: c_int,
232+
method: c_int,
233+
windowBits: c_int,
234+
memLevel: c_int,
235+
strategy: c_int,
236+
version: *const c_char,
237+
stream_size: c_int,
238+
) -> c_int;
239+
pub fn inflateBackInit_(
240+
strm: z_streamp,
241+
windowBits: c_int,
242+
window: *mut c_uchar,
243+
version: *const c_char,
244+
stream_size: c_int,
245+
) -> c_int;
246+
pub fn inflateInit_(strm: z_streamp, version: *const c_char, stream_size: c_int) -> c_int;
247+
pub fn inflateInit2_(
248+
strm: z_streamp,
249+
windowBits: c_int,
250+
version: *const c_char,
251+
stream_size: c_int,
252+
) -> c_int;
253+
}
254+
255+
#[cfg(zng)]
256+
extern "C" {
257+
pub fn zng_deflateInit(strm: z_streamp, level: c_int) -> c_int;
258+
pub fn zng_deflateInit2(
259+
strm: z_streamp,
260+
level: c_int,
261+
method: c_int,
262+
windowBits: c_int,
263+
memLevel: c_int,
264+
strategy: c_int,
265+
) -> c_int;
266+
pub fn zng_inflateBackInit(strm: z_streamp, windowBits: c_int, window: *mut c_uchar) -> c_int;
267+
pub fn zng_inflateInit(strm: z_streamp) -> c_int;
268+
pub fn zng_inflateInit2(strm: z_streamp, windowBits: c_int) -> c_int;
269+
}
270+
271+
// These methods are required to keep BC with original zlib API since zlib-ng 2.1 that changed API
272+
#[cfg(zng)]
273+
#[inline(always)]
274+
pub unsafe fn inflateInit2_(
275+
strm: z_streamp,
276+
windowBits: c_int,
277+
_version: *const c_char,
278+
_stream_size: c_int,
279+
) -> c_int {
280+
zng_inflateInit2(strm, windowBits)
281+
}
282+
283+
#[cfg(zng)]
284+
#[inline(always)]
285+
pub unsafe fn inflateInit_(strm: z_streamp, _version: *const c_char, _stream_size: c_int) -> c_int {
286+
zng_inflateInit(strm)
287+
}
288+
289+
#[cfg(zng)]
290+
#[inline(always)]
291+
pub unsafe fn inflateBackInit_(
292+
strm: z_streamp,
293+
windowBits: c_int,
294+
window: *mut c_uchar,
295+
_version: *const c_char,
296+
_stream_size: c_int,
297+
) -> c_int {
298+
zng_inflateBackInit(strm, windowBits, window)
299+
}
300+
301+
#[cfg(zng)]
302+
#[inline(always)]
303+
pub unsafe fn deflateInit2_(
304+
strm: z_streamp,
305+
level: c_int,
306+
method: c_int,
307+
windowBits: c_int,
308+
memLevel: c_int,
309+
strategy: c_int,
310+
_version: *const c_char,
311+
_stream_size: c_int,
312+
) -> c_int {
313+
zng_deflateInit2(strm, level, method, windowBits, memLevel, strategy)
314+
}
315+
316+
#[cfg(zng)]
317+
#[inline]
318+
pub unsafe fn deflateInit_(
319+
strm: z_streamp,
320+
level: c_int,
321+
_version: *const c_char,
322+
_stream_size: c_int,
323+
) -> c_int {
324+
zng_deflateInit(strm, level)
325+
}
326+
248327
#[cfg(any(zng, feature = "libc"))]
249328
extern "C" {
250329
#[link_name = zng_prefix!(adler32_combine)]

src/zlib-ng

Submodule zlib-ng updated 282 files

systest/build.rs

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ use std::env;
33
fn main() {
44
let zng = env::var("CARGO_PKG_NAME").unwrap() == "systest-zng";
55
let mut cfg = ctest2::TestGenerator::new();
6+
cfg.define("WITH_GZFILEOP", Some("ON"));
67
let (header, dep_include) = if zng {
78
("zlib-ng.h", "DEP_Z_NG_INCLUDE")
89
} else {
@@ -20,8 +21,13 @@ fn main() {
2021
if rust == "zlibVersion" {
2122
return "zlibng_version".to_string();
2223
}
23-
format!("zng_{}", rust)
24+
if rust.starts_with("zng_") {
25+
rust.to_string()
26+
} else {
27+
format!("zng_{}", rust)
28+
}
2429
});
30+
cfg.cfg("zng", None);
2531
}
2632
cfg.type_name(move |n, _, _| {
2733
if zng {
@@ -35,6 +41,8 @@ fn main() {
3541
return "size_t".to_string();
3642
} else if n == "z_checksum" {
3743
return "uint32_t".to_string();
44+
} else if n == "z_off_t" {
45+
return "z_off64_t".to_string();
3846
}
3947
} else {
4048
if n == "z_size" {

0 commit comments

Comments
 (0)