Skip to content

Commit 19e2fd7

Browse files
Tobbaalexcrichton
authored andcommitted
---
yaml --- r: 110535 b: refs/heads/master c: bc234ae h: refs/heads/master i: 110533: b1c1fb2 110531: 70956de 110527: 9bfc849 v: v3
1 parent fad8af5 commit 19e2fd7

File tree

6 files changed

+40
-22
lines changed

6 files changed

+40
-22
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
---
2-
refs/heads/master: dc49018679e75e8641c8a8bb295075ec5f247d99
2+
refs/heads/master: bc234ae1307f6c1ff72782a82b8222691bf67525
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
44
refs/heads/snap-stage3: e263ef1df7b892ed29e53313565eb05ab75e52f4
55
refs/heads/try: 597a645456b55e1c886ce15d23a192abdf4d55cf

trunk/src/libflate/lib.rs

Lines changed: 20 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -54,43 +54,49 @@ static LZ_NORM : c_int = 0x80; // LZ with 128 probes, "normal"
5454
static TINFL_FLAG_PARSE_ZLIB_HEADER : c_int = 0x1; // parse zlib header and adler32 checksum
5555
static TDEFL_WRITE_ZLIB_HEADER : c_int = 0x01000; // write zlib header and adler32 checksum
5656

57-
fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> CVec<u8> {
57+
fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<CVec<u8>> {
5858
unsafe {
5959
let mut outsz : size_t = 0;
6060
let res = rustrt::tdefl_compress_mem_to_heap(bytes.as_ptr() as *c_void,
6161
bytes.len() as size_t,
6262
&mut outsz,
6363
flags);
64-
assert!(!res.is_null());
65-
CVec::new_with_dtor(res as *mut u8, outsz as uint, proc() libc::free(res))
64+
if !res.is_null() {
65+
Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, proc() libc::free(res)))
66+
} else {
67+
None
68+
}
6669
}
6770
}
6871

69-
pub fn deflate_bytes(bytes: &[u8]) -> CVec<u8> {
72+
pub fn deflate_bytes(bytes: &[u8]) -> Option<CVec<u8>> {
7073
deflate_bytes_internal(bytes, LZ_NORM)
7174
}
7275

73-
pub fn deflate_bytes_zlib(bytes: &[u8]) -> CVec<u8> {
76+
pub fn deflate_bytes_zlib(bytes: &[u8]) -> Option<CVec<u8>> {
7477
deflate_bytes_internal(bytes, LZ_NORM | TDEFL_WRITE_ZLIB_HEADER)
7578
}
7679

77-
fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> CVec<u8> {
80+
fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> Option<CVec<u8>> {
7881
unsafe {
7982
let mut outsz : size_t = 0;
8083
let res = rustrt::tinfl_decompress_mem_to_heap(bytes.as_ptr() as *c_void,
8184
bytes.len() as size_t,
8285
&mut outsz,
8386
flags);
84-
assert!(!res.is_null());
85-
CVec::new_with_dtor(res as *mut u8, outsz as uint, proc() libc::free(res))
87+
if !res.is_null() {
88+
Some(CVec::new_with_dtor(res as *mut u8, outsz as uint, proc() libc::free(res)))
89+
} else {
90+
None
91+
}
8692
}
8793
}
8894

89-
pub fn inflate_bytes(bytes: &[u8]) -> CVec<u8> {
95+
pub fn inflate_bytes(bytes: &[u8]) -> Option<CVec<u8>> {
9096
inflate_bytes_internal(bytes, 0)
9197
}
9298

93-
pub fn inflate_bytes_zlib(bytes: &[u8]) -> CVec<u8> {
99+
pub fn inflate_bytes_zlib(bytes: &[u8]) -> Option<CVec<u8>> {
94100
inflate_bytes_internal(bytes, TINFL_FLAG_PARSE_ZLIB_HEADER)
95101
}
96102

@@ -117,8 +123,8 @@ mod tests {
117123
}
118124
debug!("de/inflate of {} bytes of random word-sequences",
119125
input.len());
120-
let cmp = deflate_bytes(input);
121-
let out = inflate_bytes(cmp.as_slice());
126+
let cmp = deflate_bytes(input).expect("deflation failed");
127+
let out = inflate_bytes(cmp.as_slice()).expect("inflation failed");
122128
debug!("{} bytes deflated to {} ({:.1f}% size)",
123129
input.len(), cmp.len(),
124130
100.0 * ((cmp.len() as f64) / (input.len() as f64)));
@@ -129,8 +135,8 @@ mod tests {
129135
#[test]
130136
fn test_zlib_flate() {
131137
let bytes = vec!(1, 2, 3, 4, 5);
132-
let deflated = deflate_bytes(bytes.as_slice());
133-
let inflated = inflate_bytes(deflated.as_slice());
138+
let deflated = deflate_bytes(bytes.as_slice()).expect("deflation failed");
139+
let inflated = inflate_bytes(deflated.as_slice()).expect("inflation failed");
134140
assert_eq!(inflated.as_slice(), bytes.as_slice());
135141
}
136142
}

trunk/src/librustc/back/link.rs

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -945,11 +945,14 @@ fn link_rlib<'a>(sess: &'a Session,
945945
let bc_deflated = obj_filename.with_extension("bc.deflate");
946946
match fs::File::open(&bc).read_to_end().and_then(|data| {
947947
fs::File::create(&bc_deflated)
948-
.write(flate::deflate_bytes(data.as_slice()).as_slice())
948+
.write(match flate::deflate_bytes(data.as_slice()) {
949+
Some(compressed) => compressed,
950+
None => sess.fatal("failed to compress bytecode")
951+
}.as_slice())
949952
}) {
950953
Ok(()) => {}
951954
Err(e) => {
952-
sess.err(format!("failed to compress bytecode: {}", e));
955+
sess.err(format!("failed to write compressed bytecode: {}", e));
953956
sess.abort_if_errors()
954957
}
955958
}

trunk/src/librustc/back/lto.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,10 @@ pub fn run(sess: &session::Session, llmod: ModuleRef,
5656
archive.read(format!("{}.bc.deflate", name)));
5757
let bc = bc.expect("missing compressed bytecode in archive!");
5858
let bc = time(sess.time_passes(), format!("inflate {}.bc", name), (), |_|
59-
flate::inflate_bytes(bc));
59+
match flate::inflate_bytes(bc) {
60+
Some(bc) => bc,
61+
None => sess.fatal(format!("failed to decompress bc of `{}`", name))
62+
});
6063
let ptr = bc.as_slice().as_ptr();
6164
debug!("linking {}", name);
6265
time(sess.time_passes(), format!("ll link {}", name), (), |()| unsafe {

trunk/src/librustc/metadata/loader.rs

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -494,14 +494,17 @@ fn get_metadata_section_imp(os: Os, filename: &Path) -> Result<MetadataBlob, ~st
494494
let version_ok = slice::raw::buf_as_slice(cvbuf, minsz,
495495
|buf0| buf0 == encoder::metadata_encoding_version);
496496
if !version_ok { return Err(format!("incompatible metadata version found: '{}'",
497-
filename.display()));}
497+
filename.display())); }
498498

499499
let cvbuf1 = cvbuf.offset(vlen as int);
500500
debug!("inflating {} bytes of compressed metadata",
501501
csz - vlen);
502502
slice::raw::buf_as_slice(cvbuf1, csz-vlen, |bytes| {
503-
let inflated = flate::inflate_bytes(bytes);
504-
found = Ok(MetadataVec(inflated));
503+
match flate::inflate_bytes(bytes) {
504+
Some(inflated) => found = Ok(MetadataVec(inflated)),
505+
None => found = Err(format!("failed to decompress metadata for: '{}'",
506+
filename.display()))
507+
}
505508
});
506509
if found.is_ok() {
507510
return found;

trunk/src/librustc/middle/trans/base.rs

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2236,7 +2236,10 @@ pub fn write_metadata(cx: &CrateContext, krate: &ast::Crate) -> Vec<u8> {
22362236
let encode_parms = crate_ctxt_to_encode_parms(cx, encode_inlined_item);
22372237
let metadata = encoder::encode_metadata(encode_parms, krate);
22382238
let compressed = encoder::metadata_encoding_version +
2239-
flate::deflate_bytes(metadata.as_slice()).as_slice();
2239+
match flate::deflate_bytes(metadata.as_slice()) {
2240+
Some(compressed) => compressed,
2241+
None => cx.sess().fatal(format!("failed to compress metadata", ))
2242+
}.as_slice();
22402243
let llmeta = C_bytes(cx, compressed);
22412244
let llconst = C_struct(cx, [llmeta], false);
22422245
let name = format!("rust_metadata_{}_{}_{}", cx.link_meta.crateid.name,

0 commit comments

Comments
 (0)