Skip to content

Commit 9941993

Browse files
committed
---
yaml --- r: 148847 b: refs/heads/try2 c: ef00c6a h: refs/heads/master i: 148845: 837563e 148843: b59781a 148839: 05a390f 148831: cad0acb v: v3
1 parent f9f92ba commit 9941993

File tree

13 files changed

+325
-243
lines changed

13 files changed

+325
-243
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: ece8a8f520697be50cbe543bebe065c5198dae4d
8+
refs/heads/try2: ef00c6a278cdd3bd00f44133573e1f5e2e951520
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libextra/ebml.rs

Lines changed: 23 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,10 @@
1212

1313
use std::str;
1414

15+
macro_rules! if_ok( ($e:expr) => (
16+
match $e { Ok(e) => e, Err(e) => { self.last_error = Err(e); return } }
17+
) )
18+
1519
// Simple Extensible Binary Markup Language (ebml) reader and writer on a
1620
// cursor model. See the specification here:
1721
// http://www.matroska.org/technical/specs/rfc/index.html
@@ -595,9 +599,15 @@ pub mod writer {
595599

596600
// ebml writing
597601
pub struct Encoder<'a> {
598-
// FIXME(#5665): this should take a trait object
602+
// FIXME(#5665): this should take a trait object. Note that if you
603+
// delete this comment you should consider removing the
604+
// unwrap()'s below of the results of the calls to
605+
// write(). We're guaranteed that writing into a MemWriter
606+
// won't fail, but this is not true for all I/O streams in
607+
// general.
599608
writer: &'a mut MemWriter,
600609
priv size_positions: ~[uint],
610+
last_error: io::IoResult<()>,
601611
}
602612

603613
fn write_sized_vuint(w: &mut MemWriter, n: uint, size: uint) {
@@ -609,7 +619,7 @@ pub mod writer {
609619
4u => w.write(&[0x10u8 | ((n >> 24_u) as u8), (n >> 16_u) as u8,
610620
(n >> 8_u) as u8, n as u8]),
611621
_ => fail!("vint to write too big: {}", n)
612-
};
622+
}.unwrap()
613623
}
614624

615625
fn write_vuint(w: &mut MemWriter, n: uint) {
@@ -624,7 +634,8 @@ pub mod writer {
624634
let size_positions: ~[uint] = ~[];
625635
Encoder {
626636
writer: w,
627-
size_positions: size_positions
637+
size_positions: size_positions,
638+
last_error: Ok(()),
628639
}
629640
}
630641

@@ -635,6 +646,7 @@ pub mod writer {
635646
Encoder {
636647
writer: cast::transmute_copy(&self.writer),
637648
size_positions: self.size_positions.clone(),
649+
last_error: Ok(()),
638650
}
639651
}
640652

@@ -645,18 +657,18 @@ pub mod writer {
645657
write_vuint(self.writer, tag_id);
646658

647659
// Write a placeholder four-byte size.
648-
self.size_positions.push(self.writer.tell() as uint);
660+
self.size_positions.push(if_ok!(self.writer.tell()) as uint);
649661
let zeroes: &[u8] = &[0u8, 0u8, 0u8, 0u8];
650-
self.writer.write(zeroes);
662+
if_ok!(self.writer.write(zeroes));
651663
}
652664

653665
pub fn end_tag(&mut self) {
654666
let last_size_pos = self.size_positions.pop().unwrap();
655-
let cur_pos = self.writer.tell();
656-
self.writer.seek(last_size_pos as i64, io::SeekSet);
667+
let cur_pos = if_ok!(self.writer.tell());
668+
if_ok!(self.writer.seek(last_size_pos as i64, io::SeekSet));
657669
let size = (cur_pos as uint - last_size_pos - 4);
658670
write_sized_vuint(self.writer, size, 4u);
659-
self.writer.seek(cur_pos as i64, io::SeekSet);
671+
if_ok!(self.writer.seek(cur_pos as i64, io::SeekSet));
660672

661673
debug!("End tag (size = {})", size);
662674
}
@@ -670,7 +682,7 @@ pub mod writer {
670682
pub fn wr_tagged_bytes(&mut self, tag_id: uint, b: &[u8]) {
671683
write_vuint(self.writer, tag_id);
672684
write_vuint(self.writer, b.len());
673-
self.writer.write(b);
685+
self.writer.write(b).unwrap();
674686
}
675687

676688
pub fn wr_tagged_u64(&mut self, tag_id: uint, v: u64) {
@@ -723,12 +735,12 @@ pub mod writer {
723735

724736
pub fn wr_bytes(&mut self, b: &[u8]) {
725737
debug!("Write {} bytes", b.len());
726-
self.writer.write(b);
738+
self.writer.write(b).unwrap();
727739
}
728740

729741
pub fn wr_str(&mut self, s: &str) {
730742
debug!("Write str: {}", s);
731-
self.writer.write(s.as_bytes());
743+
self.writer.write(s.as_bytes()).unwrap();
732744
}
733745
}
734746

0 commit comments

Comments
 (0)