libcore: make a copyless io::BytesWriter
This commit is contained in:
@@ -219,12 +219,8 @@ fn under(n: uint, it: fn(uint)) {
|
|||||||
while i < n { it(i); i += 1u; }
|
while i < n { it(i); i += 1u; }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn devnull() -> io::Writer { io::mem_buffer_writer(io::mem_buffer()) }
|
|
||||||
|
|
||||||
fn as_str(f: fn@(io::Writer)) -> ~str {
|
fn as_str(f: fn@(io::Writer)) -> ~str {
|
||||||
let buf = io::mem_buffer();
|
io::with_str_writer(f)
|
||||||
f(io::mem_buffer_writer(buf));
|
|
||||||
io::mem_buffer_str(buf)
|
|
||||||
}
|
}
|
||||||
|
|
||||||
fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
|
fn check_variants_of_ast(crate: ast::crate, codemap: codemap::codemap,
|
||||||
|
|||||||
@@ -670,9 +670,12 @@ fn stderr() -> Writer { fd_writer(libc::STDERR_FILENO as c_int, false) }
|
|||||||
fn print(s: &str) { stdout().write_str(s); }
|
fn print(s: &str) { stdout().write_str(s); }
|
||||||
fn println(s: &str) { stdout().write_line(s); }
|
fn println(s: &str) { stdout().write_line(s); }
|
||||||
|
|
||||||
type MemBuffer = @{buf: DVec<u8>, mut pos: uint};
|
struct BytesWriter {
|
||||||
|
buf: DVec<u8>,
|
||||||
|
mut pos: uint,
|
||||||
|
}
|
||||||
|
|
||||||
impl MemBuffer: Writer {
|
impl @BytesWriter: Writer {
|
||||||
fn write(v: &[const u8]) {
|
fn write(v: &[const u8]) {
|
||||||
do self.buf.swap |buf| {
|
do self.buf.swap |buf| {
|
||||||
let mut buf <- buf;
|
let mut buf <- buf;
|
||||||
@@ -701,27 +704,24 @@ impl MemBuffer: Writer {
|
|||||||
fn get_type() -> WriterType { File }
|
fn get_type() -> WriterType { File }
|
||||||
}
|
}
|
||||||
|
|
||||||
fn mem_buffer() -> MemBuffer {
|
fn BytesWriter() -> @BytesWriter {
|
||||||
@{buf: DVec(), mut pos: 0u}
|
@BytesWriter { buf: DVec(), mut pos: 0u }
|
||||||
}
|
}
|
||||||
fn mem_buffer_writer(b: MemBuffer) -> Writer { b as Writer }
|
|
||||||
fn mem_buffer_buf(b: MemBuffer) -> ~[u8] { b.buf.get() }
|
fn with_bytes_writer(f: fn(Writer)) -> ~[u8] {
|
||||||
fn mem_buffer_str(b: MemBuffer) -> ~str {
|
let wr = BytesWriter();
|
||||||
str::from_bytes(b.buf.get())
|
f(wr as Writer);
|
||||||
|
wr.buf.check_out(|buf| buf)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn with_str_writer(f: fn(Writer)) -> ~str {
|
fn with_str_writer(f: fn(Writer)) -> ~str {
|
||||||
let buf = mem_buffer();
|
let mut v = with_bytes_writer(f);
|
||||||
let wr = mem_buffer_writer(buf);
|
|
||||||
f(wr);
|
|
||||||
io::mem_buffer_str(buf)
|
|
||||||
}
|
|
||||||
|
|
||||||
fn with_buf_writer(f: fn(Writer)) -> ~[u8] {
|
// Make sure the vector has a trailing null and is proper utf8.
|
||||||
let buf = mem_buffer();
|
vec::push(v, 0);
|
||||||
let wr = mem_buffer_writer(buf);
|
assert str::is_utf8(v);
|
||||||
f(wr);
|
|
||||||
io::mem_buffer_buf(buf)
|
unsafe { move ::unsafe::transmute(v) }
|
||||||
}
|
}
|
||||||
|
|
||||||
// Utility functions
|
// Utility functions
|
||||||
@@ -946,18 +946,18 @@ mod tests {
|
|||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn mem_buffer_overwrite() {
|
fn bytes_buffer_overwrite() {
|
||||||
let mbuf = mem_buffer();
|
let wr = BytesWriter();
|
||||||
mbuf.write(~[0u8, 1u8, 2u8, 3u8]);
|
wr.write(~[0u8, 1u8, 2u8, 3u8]);
|
||||||
assert mem_buffer_buf(mbuf) == ~[0u8, 1u8, 2u8, 3u8];
|
assert wr.buf.borrow(|buf| buf == ~[0u8, 1u8, 2u8, 3u8]);
|
||||||
mbuf.seek(-2, SeekCur);
|
wr.seek(-2, SeekCur);
|
||||||
mbuf.write(~[4u8, 5u8, 6u8, 7u8]);
|
wr.write(~[4u8, 5u8, 6u8, 7u8]);
|
||||||
assert mem_buffer_buf(mbuf) == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8];
|
assert wr.buf.borrow(|buf| buf == ~[0u8, 1u8, 4u8, 5u8, 6u8, 7u8]);
|
||||||
mbuf.seek(-2, SeekEnd);
|
wr.seek(-2, SeekEnd);
|
||||||
mbuf.write(~[8u8]);
|
wr.write(~[8u8]);
|
||||||
mbuf.seek(1, SeekSet);
|
wr.seek(1, SeekSet);
|
||||||
mbuf.write(~[9u8]);
|
wr.write(~[9u8]);
|
||||||
assert mem_buffer_buf(mbuf) == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8];
|
assert wr.buf.borrow(|buf| buf == ~[0u8, 9u8, 4u8, 5u8, 8u8, 7u8]);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -99,10 +99,9 @@ pure fn refcount<T>(+t: @T) -> uint {
|
|||||||
|
|
||||||
pure fn log_str<T>(t: T) -> ~str {
|
pure fn log_str<T>(t: T) -> ~str {
|
||||||
unsafe {
|
unsafe {
|
||||||
let buffer = io::mem_buffer();
|
do io::with_str_writer |wr| {
|
||||||
let writer = io::mem_buffer_writer(buffer);
|
repr::write_repr(wr, &t)
|
||||||
repr::write_repr(writer, &t);
|
}
|
||||||
return io::mem_buffer_str(buffer); // XXX: Extra malloc and copy.
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -373,10 +373,10 @@ trait ToBytes {
|
|||||||
|
|
||||||
impl<A: IterBytes> A: ToBytes {
|
impl<A: IterBytes> A: ToBytes {
|
||||||
fn to_bytes(lsb0: bool) -> ~[u8] {
|
fn to_bytes(lsb0: bool) -> ~[u8] {
|
||||||
let buf = io::mem_buffer();
|
do io::with_bytes_writer |wr| {
|
||||||
for self.iter_bytes(lsb0) |bytes| {
|
for self.iter_bytes(lsb0) |bytes| {
|
||||||
buf.write(bytes)
|
wr.write(bytes)
|
||||||
}
|
}
|
||||||
io::mem_buffer_buf(buf)
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -631,10 +631,11 @@ fn test_option_int() {
|
|||||||
|
|
||||||
fn test_v(v: Option<int>) {
|
fn test_v(v: Option<int>) {
|
||||||
debug!("v == %?", v);
|
debug!("v == %?", v);
|
||||||
let mbuf = io::mem_buffer();
|
let bytes = do io::with_bytes_writer |wr| {
|
||||||
let ebml_w = ebml::Writer(io::mem_buffer_writer(mbuf));
|
let ebml_w = ebml::Writer(wr);
|
||||||
serialize_0(ebml_w, v);
|
serialize_0(ebml_w, v);
|
||||||
let ebml_doc = ebml::Doc(@io::mem_buffer_buf(mbuf));
|
};
|
||||||
|
let ebml_doc = ebml::Doc(@bytes);
|
||||||
let deser = ebml_deserializer(ebml_doc);
|
let deser = ebml_deserializer(ebml_doc);
|
||||||
let v1 = deserialize_0(deser);
|
let v1 = deserialize_0(deser);
|
||||||
debug!("v1 == %?", v1);
|
debug!("v1 == %?", v1);
|
||||||
|
|||||||
@@ -233,9 +233,7 @@ fn print_failures(st: ConsoleTestState) {
|
|||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn should_sort_failures_before_printing_them() {
|
fn should_sort_failures_before_printing_them() {
|
||||||
let buffer = io::mem_buffer();
|
let s = do io::with_str_writer |wr| {
|
||||||
let writer = io::mem_buffer_writer(buffer);
|
|
||||||
|
|
||||||
let test_a = {
|
let test_a = {
|
||||||
name: ~"a",
|
name: ~"a",
|
||||||
testfn: fn~() { },
|
testfn: fn~() { },
|
||||||
@@ -251,7 +249,7 @@ fn should_sort_failures_before_printing_them() {
|
|||||||
};
|
};
|
||||||
|
|
||||||
let st =
|
let st =
|
||||||
@{out: writer,
|
@{out: wr,
|
||||||
log_out: option::None,
|
log_out: option::None,
|
||||||
use_color: false,
|
use_color: false,
|
||||||
mut total: 0u,
|
mut total: 0u,
|
||||||
@@ -261,8 +259,7 @@ fn should_sort_failures_before_printing_them() {
|
|||||||
mut failures: ~[test_b, test_a]};
|
mut failures: ~[test_b, test_a]};
|
||||||
|
|
||||||
print_failures(st);
|
print_failures(st);
|
||||||
|
};
|
||||||
let s = io::mem_buffer_str(buffer);
|
|
||||||
|
|
||||||
let apos = option::get(str::find_str(s, ~"a"));
|
let apos = option::get(str::find_str(s, ~"a"));
|
||||||
let bpos = option::get(str::find_str(s, ~"b"));
|
let bpos = option::get(str::find_str(s, ~"b"));
|
||||||
|
|||||||
@@ -125,13 +125,13 @@ fn path_to_str(&&p: @ast::path, intr: ident_interner) -> ~str {
|
|||||||
|
|
||||||
fn fun_to_str(decl: ast::fn_decl, name: ast::ident,
|
fn fun_to_str(decl: ast::fn_decl, name: ast::ident,
|
||||||
params: ~[ast::ty_param], intr: ident_interner) -> ~str {
|
params: ~[ast::ty_param], intr: ident_interner) -> ~str {
|
||||||
let buffer = io::mem_buffer();
|
do io::with_str_writer |wr| {
|
||||||
let s = rust_printer(io::mem_buffer_writer(buffer), intr);
|
let s = rust_printer(wr, intr);
|
||||||
print_fn(s, decl, None, name, params, None);
|
print_fn(s, decl, None, name, params, None);
|
||||||
end(s); // Close the head box
|
end(s); // Close the head box
|
||||||
end(s); // Close the outer box
|
end(s); // Close the outer box
|
||||||
eof(s.s);
|
eof(s.s);
|
||||||
io::mem_buffer_str(buffer)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
@@ -148,15 +148,15 @@ fn test_fun_to_str() {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn block_to_str(blk: ast::blk, intr: ident_interner) -> ~str {
|
fn block_to_str(blk: ast::blk, intr: ident_interner) -> ~str {
|
||||||
let buffer = io::mem_buffer();
|
do io::with_str_writer |wr| {
|
||||||
let s = rust_printer(io::mem_buffer_writer(buffer), intr);
|
let s = rust_printer(wr, intr);
|
||||||
// containing cbox, will be closed by print-block at }
|
// containing cbox, will be closed by print-block at }
|
||||||
cbox(s, indent_unit);
|
cbox(s, indent_unit);
|
||||||
// head-ibox, will be closed by print-block after {
|
// head-ibox, will be closed by print-block after {
|
||||||
ibox(s, 0u);
|
ibox(s, 0u);
|
||||||
print_block(s, blk);
|
print_block(s, blk);
|
||||||
eof(s.s);
|
eof(s.s);
|
||||||
io::mem_buffer_str(buffer)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn meta_item_to_str(mi: @ast::meta_item, intr: ident_interner) -> ~str {
|
fn meta_item_to_str(mi: @ast::meta_item, intr: ident_interner) -> ~str {
|
||||||
@@ -2026,11 +2026,11 @@ fn print_string(s: ps, st: ~str) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
fn to_str<T>(t: T, f: fn@(ps, T), intr: ident_interner) -> ~str {
|
fn to_str<T>(t: T, f: fn@(ps, T), intr: ident_interner) -> ~str {
|
||||||
let buffer = io::mem_buffer();
|
do io::with_str_writer |wr| {
|
||||||
let s = rust_printer(io::mem_buffer_writer(buffer), intr);
|
let s = rust_printer(wr, intr);
|
||||||
f(s, t);
|
f(s, t);
|
||||||
eof(s.s);
|
eof(s.s);
|
||||||
io::mem_buffer_str(buffer)
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
fn next_comment(s: ps) -> Option<comments::cmnt> {
|
fn next_comment(s: ps) -> Option<comments::cmnt> {
|
||||||
|
|||||||
@@ -68,7 +68,6 @@ type stats = {
|
|||||||
enum encode_ctxt = {
|
enum encode_ctxt = {
|
||||||
diag: span_handler,
|
diag: span_handler,
|
||||||
tcx: ty::ctxt,
|
tcx: ty::ctxt,
|
||||||
buf: io::MemBuffer,
|
|
||||||
stats: stats,
|
stats: stats,
|
||||||
reachable: HashMap<ast::node_id, ()>,
|
reachable: HashMap<ast::node_id, ()>,
|
||||||
reexports: ~[(~str, def_id)],
|
reexports: ~[(~str, def_id)],
|
||||||
@@ -1089,7 +1088,7 @@ const metadata_encoding_version : &[u8] = &[0x72, //'r' as u8,
|
|||||||
0, 0, 0, 1 ];
|
0, 0, 0, 1 ];
|
||||||
|
|
||||||
fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
||||||
let buf = io::mem_buffer();
|
let wr = io::BytesWriter();
|
||||||
let stats =
|
let stats =
|
||||||
{mut inline_bytes: 0,
|
{mut inline_bytes: 0,
|
||||||
mut attr_bytes: 0,
|
mut attr_bytes: 0,
|
||||||
@@ -1102,7 +1101,6 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
|||||||
let ecx: @encode_ctxt = @encode_ctxt({
|
let ecx: @encode_ctxt = @encode_ctxt({
|
||||||
diag: parms.diag,
|
diag: parms.diag,
|
||||||
tcx: parms.tcx,
|
tcx: parms.tcx,
|
||||||
buf: buf,
|
|
||||||
stats: move stats,
|
stats: move stats,
|
||||||
reachable: parms.reachable,
|
reachable: parms.reachable,
|
||||||
reexports: parms.reexports,
|
reexports: parms.reexports,
|
||||||
@@ -1115,37 +1113,36 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
|||||||
type_abbrevs: ty::new_ty_hash()
|
type_abbrevs: ty::new_ty_hash()
|
||||||
});
|
});
|
||||||
|
|
||||||
let buf_w = io::mem_buffer_writer(buf);
|
let ebml_w = ebml::Writer(wr as io::Writer);
|
||||||
let ebml_w = ebml::Writer(buf_w);
|
|
||||||
|
|
||||||
encode_hash(ebml_w, ecx.link_meta.extras_hash);
|
encode_hash(ebml_w, ecx.link_meta.extras_hash);
|
||||||
|
|
||||||
let mut i = buf.pos;
|
let mut i = wr.pos;
|
||||||
let crate_attrs = synthesize_crate_attrs(ecx, crate);
|
let crate_attrs = synthesize_crate_attrs(ecx, crate);
|
||||||
encode_attributes(ebml_w, crate_attrs);
|
encode_attributes(ebml_w, crate_attrs);
|
||||||
ecx.stats.attr_bytes = buf.pos - i;
|
ecx.stats.attr_bytes = wr.pos - i;
|
||||||
|
|
||||||
i = buf.pos;
|
i = wr.pos;
|
||||||
encode_crate_deps(ecx, ebml_w, ecx.cstore);
|
encode_crate_deps(ecx, ebml_w, ecx.cstore);
|
||||||
ecx.stats.dep_bytes = buf.pos - i;
|
ecx.stats.dep_bytes = wr.pos - i;
|
||||||
|
|
||||||
// Encode and index the items.
|
// Encode and index the items.
|
||||||
ebml_w.start_tag(tag_items);
|
ebml_w.start_tag(tag_items);
|
||||||
i = buf.pos;
|
i = wr.pos;
|
||||||
let items_index = encode_info_for_items(ecx, ebml_w, crate);
|
let items_index = encode_info_for_items(ecx, ebml_w, crate);
|
||||||
ecx.stats.item_bytes = buf.pos - i;
|
ecx.stats.item_bytes = wr.pos - i;
|
||||||
|
|
||||||
i = buf.pos;
|
i = wr.pos;
|
||||||
let items_buckets = create_index(items_index, hash_node_id);
|
let items_buckets = create_index(items_index, hash_node_id);
|
||||||
encode_index(ebml_w, items_buckets, write_int);
|
encode_index(ebml_w, items_buckets, write_int);
|
||||||
ecx.stats.index_bytes = buf.pos - i;
|
ecx.stats.index_bytes = wr.pos - i;
|
||||||
ebml_w.end_tag();
|
ebml_w.end_tag();
|
||||||
|
|
||||||
ecx.stats.total_bytes = buf.pos;
|
ecx.stats.total_bytes = wr.pos;
|
||||||
|
|
||||||
if (parms.tcx.sess.meta_stats()) {
|
if (parms.tcx.sess.meta_stats()) {
|
||||||
|
|
||||||
do buf.buf.borrow |v| {
|
do wr.buf.borrow |v| {
|
||||||
do v.each |e| {
|
do v.each |e| {
|
||||||
if e == 0 {
|
if e == 0 {
|
||||||
ecx.stats.zero_bytes += 1;
|
ecx.stats.zero_bytes += 1;
|
||||||
@@ -1166,7 +1163,7 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
|||||||
|
|
||||||
// Pad this, since something (LLVM, presumably) is cutting off the
|
// Pad this, since something (LLVM, presumably) is cutting off the
|
||||||
// remaining % 4 bytes.
|
// remaining % 4 bytes.
|
||||||
buf_w.write(&[0u8, 0u8, 0u8, 0u8]);
|
wr.write(&[0u8, 0u8, 0u8, 0u8]);
|
||||||
|
|
||||||
// FIXME #3396: weird bug here, for reasons unclear this emits random
|
// FIXME #3396: weird bug here, for reasons unclear this emits random
|
||||||
// looking bytes (mostly 0x1) if we use the version byte-array constant
|
// looking bytes (mostly 0x1) if we use the version byte-array constant
|
||||||
@@ -1178,7 +1175,7 @@ fn encode_metadata(parms: encode_parms, crate: @crate) -> ~[u8] {
|
|||||||
|
|
||||||
(do str::as_bytes(~"rust\x00\x00\x00\x01") |bytes| {
|
(do str::as_bytes(~"rust\x00\x00\x00\x01") |bytes| {
|
||||||
vec::slice(bytes, 0, 8)
|
vec::slice(bytes, 0, 8)
|
||||||
}) + flate::deflate_bytes(io::mem_buffer_buf(buf))
|
}) + flate::deflate_bytes(wr.buf.check_out(|buf| buf))
|
||||||
}
|
}
|
||||||
|
|
||||||
// Get the encoded string for a type
|
// Get the encoded string for a type
|
||||||
@@ -1188,9 +1185,9 @@ fn encoded_ty(tcx: ty::ctxt, t: ty::t) -> ~str {
|
|||||||
tcx: tcx,
|
tcx: tcx,
|
||||||
reachable: |_id| false,
|
reachable: |_id| false,
|
||||||
abbrevs: tyencode::ac_no_abbrevs};
|
abbrevs: tyencode::ac_no_abbrevs};
|
||||||
let buf = io::mem_buffer();
|
do io::with_str_writer |wr| {
|
||||||
tyencode::enc_ty(io::mem_buffer_writer(buf), cx, t);
|
tyencode::enc_ty(wr, cx, t);
|
||||||
return io::mem_buffer_str(buf);
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
@@ -47,10 +47,11 @@ fn enc_ty(w: io::Writer, cx: @ctxt, t: ty::t) {
|
|||||||
let result_str = match cx.tcx.short_names_cache.find(t) {
|
let result_str = match cx.tcx.short_names_cache.find(t) {
|
||||||
Some(s) => *s,
|
Some(s) => *s,
|
||||||
None => {
|
None => {
|
||||||
let buf = io::mem_buffer();
|
let s = do io::with_str_writer |wr| {
|
||||||
enc_sty(io::mem_buffer_writer(buf), cx, ty::get(t).sty);
|
enc_sty(wr, cx, ty::get(t).sty);
|
||||||
cx.tcx.short_names_cache.insert(t, @io::mem_buffer_str(buf));
|
};
|
||||||
io::mem_buffer_str(buf)
|
cx.tcx.short_names_cache.insert(t, @s);
|
||||||
|
s
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
w.write_str(result_str);
|
w.write_str(result_str);
|
||||||
|
|||||||
@@ -1012,10 +1012,11 @@ fn mk_ctxt() -> fake_ext_ctxt {
|
|||||||
|
|
||||||
#[cfg(test)]
|
#[cfg(test)]
|
||||||
fn roundtrip(in_item: @ast::item) {
|
fn roundtrip(in_item: @ast::item) {
|
||||||
let mbuf = io::mem_buffer();
|
let bytes = do io::with_bytes_writer |wr| {
|
||||||
let ebml_w = ebml::Writer(io::mem_buffer_writer(mbuf));
|
let ebml_w = ebml::Writer(wr);
|
||||||
encode_item_ast(ebml_w, in_item);
|
encode_item_ast(ebml_w, in_item);
|
||||||
let ebml_doc = ebml::Doc(@io::mem_buffer_buf(mbuf));
|
};
|
||||||
|
let ebml_doc = ebml::Doc(@bytes);
|
||||||
let out_item = decode_item_ast(ebml_doc);
|
let out_item = decode_item_ast(ebml_doc);
|
||||||
|
|
||||||
let exp_str =
|
let exp_str =
|
||||||
|
|||||||
@@ -85,14 +85,14 @@ fn main() {
|
|||||||
|
|
||||||
fn check_pp<T>(cx: fake_ext_ctxt,
|
fn check_pp<T>(cx: fake_ext_ctxt,
|
||||||
expr: T, f: fn(pprust::ps, T), expect: ~str) {
|
expr: T, f: fn(pprust::ps, T), expect: ~str) {
|
||||||
let buf = mem_buffer();
|
let s = do io::with_str_writer |wr| {
|
||||||
let pp = pprust::rust_printer(buf as io::Writer,cx.parse_sess().interner);
|
let pp = pprust::rust_printer(wr, cx.parse_sess().interner);
|
||||||
f(pp, expr);
|
f(pp, expr);
|
||||||
pp::eof(pp.s);
|
pp::eof(pp.s);
|
||||||
let str = mem_buffer_str(buf);
|
};
|
||||||
stdout().write_line(str);
|
stdout().write_line(s);
|
||||||
if expect != ~"" {
|
if expect != ~"" {
|
||||||
error!("expect: '%s', got: '%s'", expect, str);
|
error!("expect: '%s', got: '%s'", expect, s);
|
||||||
assert str == expect;
|
assert str == expect;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,10 +21,11 @@ fn test_ser_and_deser<A:Eq>(a1: A,
|
|||||||
assert s == expected;
|
assert s == expected;
|
||||||
|
|
||||||
// check the EBML serializer:
|
// check the EBML serializer:
|
||||||
let buf = io::mem_buffer();
|
let bytes = do io::with_bytes_writer |wr| {
|
||||||
let w = ebml::Writer(buf as io::Writer);
|
let w = ebml::Writer(wr);
|
||||||
ebml_ser_fn(w, a1);
|
ebml_ser_fn(w, a1);
|
||||||
let d = ebml::Doc(@io::mem_buffer_buf(buf));
|
};
|
||||||
|
let d = ebml::Doc(@bytes);
|
||||||
let a2 = ebml_deser_fn(ebml::ebml_deserializer(d));
|
let a2 = ebml_deser_fn(ebml::ebml_deserializer(d));
|
||||||
io::print(~"\na1 = ");
|
io::print(~"\na1 = ");
|
||||||
io_ser_fn(io::stdout(), a1);
|
io_ser_fn(io::stdout(), a1);
|
||||||
|
|||||||
Reference in New Issue
Block a user