From c0cee3ebe47d4fca73cdab23889322c5e47f12e5 Mon Sep 17 00:00:00 2001 From: Tycho Sci Date: Thu, 18 Oct 2012 22:11:03 +0900 Subject: [PATCH 1/2] libcore: Make run::program_output UTF-8 safe --- src/libcore/run.rs | 28 ++++++++++++++++------------ 1 file changed, 16 insertions(+), 12 deletions(-) diff --git a/src/libcore/run.rs b/src/libcore/run.rs index 06b869306305..cb6a7f737f98 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -248,12 +248,14 @@ pub fn start_program(prog: &str, args: &[~str]) -> Program { } fn read_all(rd: io::Reader) -> ~str { - let mut buf = ~""; - while !rd.eof() { - let bytes = rd.read_bytes(4096u); - buf += str::from_bytes(bytes); - } - move buf + let buf = io::with_bytes_writer(|wr| { + let mut bytes = [mut 0, ..4096]; + while !rd.eof() { + let nread = rd.read(bytes, bytes.len()); + wr.write(bytes.view(0, nread)); + } + }); + str::from_bytes(buf) } /** @@ -341,13 +343,15 @@ fn writeclose(fd: c_int, s: ~str) { fn readclose(fd: c_int) -> ~str { let file = os::fdopen(fd); let reader = io::FILE_reader(file, false); - let mut buf = ~""; - while !reader.eof() { - let bytes = reader.read_bytes(4096u); - buf += str::from_bytes(bytes); - } + let buf = io::with_bytes_writer(|writer| { + let mut bytes = [mut 0, ..4096]; + while !reader.eof() { + let nread = reader.read(bytes, bytes.len()); + writer.write(bytes.view(0, nread)); + } + }); os::fclose(file); - move buf + str::from_bytes(buf) } /// Waits for a process to exit and returns the exit code From 6ce4cf769f671c53f05e97357110d4c0ba322eae Mon Sep 17 00:00:00 2001 From: Tycho Sci Date: Thu, 18 Oct 2012 22:13:01 +0900 Subject: [PATCH 2/2] rustdoc: Make markdown_writer::pandoc_writer UTF-8 safe --- src/rustdoc/markdown_writer.rs | 14 ++++++++------ 1 file changed, 8 insertions(+), 6 deletions(-) diff --git a/src/rustdoc/markdown_writer.rs b/src/rustdoc/markdown_writer.rs index ea559ae2ee6b..1ed007def633 100644 --- a/src/rustdoc/markdown_writer.rs +++ b/src/rustdoc/markdown_writer.rs @@ -136,13 +136,15 @@ fn readclose(fd: libc::c_int) -> ~str { // Copied from run::program_output let file = os::fdopen(fd); let reader = io::FILE_reader(file, false); - let mut buf = ~""; - while !reader.eof() { - let bytes = reader.read_bytes(4096u); - buf += str::from_bytes(bytes); - } + let buf = io::with_bytes_writer(|writer| { + let mut bytes = [mut 0, ..4096]; + while !reader.eof() { + let nread = reader.read(bytes, bytes.len()); + writer.write(bytes.view(0, nread)); + } + }); os::fclose(file); - return buf; + str::from_bytes(buf) } fn generic_writer(+process: fn~(markdown: ~str)) -> Writer {