Skip to content

Commit ef00c6a

Browse files
committed
extra: Remove io_error usage
1 parent ece8a8f commit ef00c6a

File tree

12 files changed

+324
-242
lines changed

12 files changed

+324
-242
lines changed

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)