Skip to content

Commit 7547aab

Browse files
committed
---
yaml --- r: 30158 b: refs/heads/incoming c: b769e29 h: refs/heads/master v: v3
1 parent 8e6d70c commit 7547aab

File tree

10 files changed

+1979
-3
lines changed

10 files changed

+1979
-3
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ refs/heads/try: d324a424d8f84b1eb049b12cf34182bda91b0024
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
88
refs/heads/try2: d0c6ce338884ee21843f4b40bf6bf18d222ce5df
9-
refs/heads/incoming: 31bbcf026727cf69e2c4b756a6d2ddc584274056
9+
refs/heads/incoming: b769e296803f578d99654e9fc271c4109e50ab75
1010
refs/heads/dist-snap: 2f32a1581f522e524009138b33b1c7049ced668d
1111
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1212
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/incoming/LICENSE.txt

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,11 @@ included:
235235
BSD-compatible licenses. See src/libuv/LICENSE for
236236
details.
237237

238+
* The src/rt/miniz.c file, carrying an implementation of
239+
RFC1950/RFC1951 DEFLATE, by Rich Geldreich
240+
<[email protected]>. All uses of this file are
241+
permitted by the embedded "unlicense" notice
242+
(effectively: public domain with warranty disclaimer).
238243

239244
* LLVM and Clang. Code for this package is found in
240245
src/llvm.

branches/incoming/mk/rt.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,7 @@ RUNTIME_CS_$(1) := \
6565
rt/rust_util.cpp \
6666
rt/circular_buffer.cpp \
6767
rt/isaac/randport.cpp \
68+
rt/miniz.cpp \
6869
rt/rust_kernel.cpp \
6970
rt/rust_shape.cpp \
7071
rt/rust_abi.cpp \

branches/incoming/mk/tests.mk

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -121,6 +121,7 @@ ALL_CS := $(wildcard $(S)src/rt/*.cpp \
121121
$(S)srcrustllvm/*.cpp)
122122
ALL_CS := $(filter-out $(S)src/rt/bigint/bigint_ext.cpp \
123123
$(S)src/rt/bigint/bigint_int.cpp \
124+
$(S)src/rt/miniz.cpp \
124125
,$(ALL_CS))
125126
ALL_HS := $(wildcard $(S)src/rt/*.h \
126127
$(S)src/rt/*/*.h \

branches/incoming/src/libcore/core.rc

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,7 @@ export cmp;
5656
export num;
5757
export path, path2;
5858
export managed;
59+
export flate;
5960

6061
// NDM seems to be necessary for resolve to work
6162
export option_iter;
@@ -265,6 +266,8 @@ mod unsafe;
265266

266267
mod managed;
267268

269+
mod flate;
270+
268271
// Modules supporting compiler-generated code
269272
// Exported but not part of the public interface
270273

Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
import libc::{c_void, size_t, c_int};
2+
3+
extern mod rustrt {
4+
5+
fn tdefl_compress_mem_to_heap(psrc_buf: *const c_void,
6+
src_buf_len: size_t,
7+
pout_len: *size_t,
8+
flags: c_int) -> *c_void;
9+
10+
fn tinfl_decompress_mem_to_heap(psrc_buf: *const c_void,
11+
src_buf_len: size_t,
12+
pout_len: *size_t,
13+
flags: c_int) -> *c_void;
14+
}
15+
16+
const lz_none : c_int = 0x0; // Huffman-coding only.
17+
const lz_fast : c_int = 0x1; // LZ with only one probe
18+
const lz_norm : c_int = 0x80; // LZ with 128 probes, "normal"
19+
const lz_best : c_int = 0xfff; // LZ with 4095 probes, "best"
20+
21+
fn deflate_buf(buf: &[const u8]) -> ~[u8] {
22+
do vec::as_const_buf(buf) |b, len| {
23+
unsafe {
24+
let mut outsz : size_t = 0;
25+
let res =
26+
rustrt::tdefl_compress_mem_to_heap(b as *c_void,
27+
len as size_t,
28+
ptr::addr_of(outsz),
29+
lz_norm);
30+
assert res as int != 0;
31+
let out = vec::unsafe::from_buf(res as *u8,
32+
outsz as uint);
33+
libc::free(res);
34+
out
35+
}
36+
}
37+
}
38+
39+
fn inflate_buf(buf: &[const u8]) -> ~[u8] {
40+
do vec::as_const_buf(buf) |b, len| {
41+
unsafe {
42+
let mut outsz : size_t = 0;
43+
let res =
44+
rustrt::tinfl_decompress_mem_to_heap(b as *c_void,
45+
len as size_t,
46+
ptr::addr_of(outsz),
47+
0);
48+
assert res as int != 0;
49+
let out = vec::unsafe::from_buf(res as *u8,
50+
outsz as uint);
51+
libc::free(res);
52+
out
53+
}
54+
}
55+
}
56+
57+
#[test]
58+
fn test_flate_round_trip() {
59+
let r = rand::Rng();
60+
let mut words = ~[];
61+
for 20.times {
62+
vec::push(words, r.gen_bytes(r.gen_uint_range(1, 10)));
63+
}
64+
for 20.times {
65+
let mut in = ~[];
66+
for 2000.times {
67+
vec::push_all(in, r.choose(words));
68+
}
69+
debug!("de/inflate of %u bytes of random word-sequences",
70+
in.len());
71+
let cmp = flate::deflate_buf(in);
72+
let out = flate::inflate_buf(cmp);
73+
debug!("%u bytes deflated to %u (%.1f%% size)",
74+
in.len(), cmp.len(),
75+
100.0 * ((cmp.len() as float) / (in.len() as float)));
76+
assert(in == out);
77+
}
78+
}

0 commit comments

Comments
 (0)