From 9123c585268fb7ae844b6cd98559a76ba080448f Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 7 Feb 2013 18:22:58 -0800 Subject: [PATCH 1/2] core: Remove transitional code --- src/libcore/ptr.rs | 11 ----------- 1 file changed, 11 deletions(-) diff --git a/src/libcore/ptr.rs b/src/libcore/ptr.rs index ad0bcb5cff8..4369b29ba52 100644 --- a/src/libcore/ptr.rs +++ b/src/libcore/ptr.rs @@ -187,18 +187,7 @@ pub trait Ptr { pure fn offset(count: uint) -> Self; } -#[cfg(stage0)] -unsafe fn memmove32(dst: *mut u8, src: *const u8, count: u32) { - libc::memmove(dst as *c_void, src as *c_void, count as size_t); -} -#[cfg(stage0)] -unsafe fn memmove64(dst: *mut u8, src: *const u8, count: u64) { - libc::memmove(dst as *c_void, src as *c_void, count as size_t); -} - #[abi="rust-intrinsic"] -#[cfg(stage1)] -#[cfg(stage2)] pub extern { fn memmove32(dst: *mut u8, src: *u8, size: u32); fn memmove64(dst: *mut u8, src: *u8, size: u64); From 3b8f1fa2b6369c40cdd3d3030e37ce3308d63caf Mon Sep 17 00:00:00 2001 From: Tim Chevalier Date: Thu, 7 Feb 2013 18:23:47 -0800 Subject: [PATCH 2/2] core: Remove structural records from the rest of core, except pipes That will, sadly, require one more snapshot. --- src/libcargo/pgp.rs | 2 +- src/libcore/extfmt.rs | 13 +++++-------- src/libcore/gc.rs | 15 +++++++-------- src/libcore/os.rs | 18 ++++++++++-------- src/libcore/pipes.rs | 3 +-- src/libcore/run.rs | 11 ++++++----- src/librustdoc/config.rs | 38 +++++++++++++++----------------------- 7 files changed, 45 insertions(+), 55 deletions(-) diff --git a/src/libcargo/pgp.rs b/src/libcargo/pgp.rs index f6e0ebda925..fe7808bad5d 100644 --- a/src/libcargo/pgp.rs +++ b/src/libcargo/pgp.rs @@ -12,7 +12,7 @@ use core::os; use core::path::Path; use core::run; -pub fn gpgv(args: ~[~str]) -> { status: int, out: ~str, err: ~str } { +pub fn gpgv(args: ~[~str]) -> run::ProgramOutput { return run::program_output(~"gpgv", args); } diff --git a/src/libcore/extfmt.rs b/src/libcore/extfmt.rs index 4d2a1b2afe0..aa4a7546f02 100644 --- a/src/libcore/extfmt.rs +++ b/src/libcore/extfmt.rs @@ -51,9 +51,6 @@ //! * s - str (any flavor) //! * ? - arbitrary type (does not use the to_str trait) -// Transitional -#[allow(structural_records)]; // Macros -- needs a snapshot - /* Syntax Extension: fmt @@ -619,11 +616,11 @@ pub mod rt { let padstr = str::from_chars(vec::from_elem(diff, padchar)); return s + padstr; } - let {might_zero_pad, signed} = match mode { - PadNozero => {might_zero_pad:false, signed:false}, - PadSigned => {might_zero_pad:true, signed:true }, - PadFloat => {might_zero_pad:true, signed:true}, - PadUnsigned => {might_zero_pad:true, signed:false} + let (might_zero_pad, signed) = match mode { + PadNozero => (false, true), + PadSigned => (true, true), + PadFloat => (true, true), + PadUnsigned => (true, false) }; pure fn have_precision(cv: Conv) -> bool { return match cv.precision { CountImplied => false, _ => true }; diff --git a/src/libcore/gc.rs b/src/libcore/gc.rs index d0c40ccf19a..3e3c327af5f 100644 --- a/src/libcore/gc.rs +++ b/src/libcore/gc.rs @@ -35,9 +35,6 @@ with destructors. */ -// Transitional -#[allow(structural_records)]; - use cast; use container::{Container, Mutable, Map, Set}; use io; @@ -172,12 +169,14 @@ unsafe fn is_frame_in_segment(fp: *Word, segment: *StackSegment) -> bool { return begin <= frame && frame <= end; } +struct Segment { segment: *StackSegment, boundary: bool } + // Find and return the segment containing the given frame pointer. At // stack segment boundaries, returns true for boundary, so that the // caller can do any special handling to identify where the correct // return address is in the stack frame. unsafe fn find_segment_for_frame(fp: *Word, segment: *StackSegment) - -> {segment: *StackSegment, boundary: bool} { + -> Segment { // Check if frame is in either current frame or previous frame. let in_segment = is_frame_in_segment(fp, segment); let in_prev_segment = ptr::is_not_null((*segment).prev) && @@ -191,16 +190,16 @@ unsafe fn find_segment_for_frame(fp: *Word, segment: *StackSegment) is_frame_in_segment(fp, (*segment).next) { segment = (*segment).next; } - return {segment: segment, boundary: false}; + return Segment {segment: segment, boundary: false}; } // If frame is in previous frame, then we're at a boundary. if !in_segment && in_prev_segment { - return {segment: (*segment).prev, boundary: true}; + return Segment {segment: (*segment).prev, boundary: true}; } // Otherwise, we're somewhere on the inside of the frame. - return {segment: segment, boundary: false}; + return Segment {segment: segment, boundary: false}; } type Memory = uint; @@ -224,7 +223,7 @@ unsafe fn walk_gc_roots(mem: Memory, sentinel: **Word, visitor: Visitor) { for stackwalk::walk_stack |frame| { unsafe { let pc = last_ret; - let {segment: next_segment, boundary: boundary} = + let Segment {segment: next_segment, boundary: boundary} = find_segment_for_frame(frame.fp, segment); segment = next_segment; // Each stack segment is bounded by a morestack frame. The diff --git a/src/libcore/os.rs b/src/libcore/os.rs index e3fe0a1aae2..38469c35cfa 100644 --- a/src/libcore/os.rs +++ b/src/libcore/os.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[allow(structural_records)]; - /*! * Higher-level interfaces to libc::* functions and operating system services. * @@ -318,33 +316,37 @@ pub fn waitpid(pid: pid_t) -> c_int { } +pub struct Pipe { mut in: c_int, mut out: c_int } + #[cfg(unix)] -pub fn pipe() -> {in: c_int, out: c_int} { +pub fn pipe() -> Pipe { unsafe { - let mut fds = {in: 0 as c_int, out: 0 as c_int}; + let mut fds = Pipe {mut in: 0 as c_int, + mut out: 0 as c_int }; assert (libc::pipe(ptr::mut_addr_of(&(fds.in))) == (0 as c_int)); - return {in: fds.in, out: fds.out}; + return Pipe {in: fds.in, out: fds.out}; } } #[cfg(windows)] -pub fn pipe() -> {in: c_int, out: c_int} { +pub fn pipe() -> Pipe { unsafe { // Windows pipes work subtly differently than unix pipes, and their // inheritance has to be handled in a different way that I do not // fully understand. Here we explicitly make the pipe non-inheritable, // which means to pass it to a subprocess they need to be duplicated // first, as in rust_run_program. - let mut fds = { in: 0 as c_int, out: 0 as c_int }; + let mut fds = Pipe { mut in: 0 as c_int, + mut out: 0 as c_int }; let res = libc::pipe(ptr::mut_addr_of(&(fds.in)), 1024 as c_uint, (libc::O_BINARY | libc::O_NOINHERIT) as c_int); assert (res == 0 as c_int); assert (fds.in != -1 as c_int && fds.in != 0 as c_int); assert (fds.out != -1 as c_int && fds.in != 0 as c_int); - return {in: fds.in, out: fds.out}; + return Pipe {in: fds.in, out: fds.out}; } } diff --git a/src/libcore/pipes.rs b/src/libcore/pipes.rs index 3f0aecb887d..10aa4e41a0d 100644 --- a/src/libcore/pipes.rs +++ b/src/libcore/pipes.rs @@ -82,8 +82,7 @@ bounded and unbounded protocols allows for less code duplication. */ -// Transitional -- needs snapshot -#[allow(structural_records)]; +#[allow(structural_records)]; // Macros -- needs another snapshot use cmp::Eq; use cast::{forget, reinterpret_cast, transmute}; diff --git a/src/libcore/run.rs b/src/libcore/run.rs index c8187fa794d..43ecf350ff3 100644 --- a/src/libcore/run.rs +++ b/src/libcore/run.rs @@ -8,8 +8,6 @@ // option. This file may not be copied, modified, or distributed // except according to those terms. -#[allow(structural_records)]; - //! Process spawning use cast; use io; @@ -301,6 +299,8 @@ fn read_all(rd: io::Reader) -> ~str { str::from_bytes(buf) } +pub struct ProgramOutput {status: int, out: ~str, err: ~str} + /** * Spawns a process, waits for it to exit, and returns the exit code, and * contents of stdout and stderr. @@ -315,8 +315,7 @@ fn read_all(rd: io::Reader) -> ~str { * A record, {status: int, out: str, err: str} containing the exit code, * the contents of stdout and the contents of stderr. */ -pub fn program_output(prog: &str, args: &[~str]) -> - {status: int, out: ~str, err: ~str} { +pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput { unsafe { let pipe_in = os::pipe(); let pipe_out = os::pipe(); @@ -371,7 +370,9 @@ pub fn program_output(prog: &str, args: &[~str]) -> }; count -= 1; }; - return {status: status, out: move outs, err: move errs}; + return ProgramOutput {status: status, + out: move outs, + err: move errs}; } } diff --git a/src/librustdoc/config.rs b/src/librustdoc/config.rs index 9ba23a20b50..90b18599620 100644 --- a/src/librustdoc/config.rs +++ b/src/librustdoc/config.rs @@ -14,6 +14,7 @@ use core::cmp; use core::os; use core::result; use core::run; +use core::run::ProgramOutput; use core::vec; use core::result::Result; use std::getopts; @@ -104,29 +105,18 @@ pub fn default_config(input_crate: &Path) -> Config { } } -struct ProcOut { - status: int, - out: ~str, - err: ~str -} +type Process = fn~((&str), (&[~str])) -> ProgramOutput; -type ProgramOutput = fn~((&str), (&[~str])) -> ProcOut; - -pub fn mock_program_output(_prog: &str, _args: &[~str]) -> ProcOut { - ProcOut { +pub fn mock_program_output(_prog: &str, _args: &[~str]) -> ProgramOutput { + ProgramOutput { status: 0, out: ~"", err: ~"" } } -pub fn program_output(prog: &str, args: &[~str]) -> ProcOut { - let {status, out, err} = run::program_output(prog, args); - ProcOut { - status: status, - out: out, - err: err - } +pub fn program_output(prog: &str, args: &[~str]) -> ProgramOutput { + run::program_output(prog, args) } pub fn parse_config(args: &[~str]) -> Result { @@ -135,7 +125,7 @@ pub fn parse_config(args: &[~str]) -> Result { pub fn parse_config_( args: &[~str], - program_output: ProgramOutput + program_output: Process ) -> Result { let args = args.tail(); let opts = vec::unzip(opts()).first(); @@ -159,7 +149,7 @@ pub fn parse_config_( fn config_from_opts( input_crate: &Path, matches: &getopts::Matches, - program_output: ProgramOutput + program_output: Process ) -> Result { let config = default_config(input_crate); @@ -235,7 +225,7 @@ fn parse_output_style(output_style: &str) -> Result { fn maybe_find_pandoc( config: &Config, maybe_pandoc_cmd: Option<~str>, - program_output: ProgramOutput + program_output: Process ) -> Result, ~str> { if config.output_format != PandocHtml { return result::Ok(maybe_pandoc_cmd); @@ -272,8 +262,9 @@ fn should_find_pandoc() { output_format: PandocHtml, .. default_config(&Path("test")) }; - let mock_program_output = fn~(_prog: &str, _args: &[~str]) -> ProcOut { - ProcOut { + let mock_program_output = fn~(_prog: &str, _args: &[~str]) + -> ProgramOutput { + ProgramOutput { status: 0, out: ~"pandoc 1.8.2.1", err: ~"" } }; @@ -287,8 +278,9 @@ fn should_error_with_no_pandoc() { output_format: PandocHtml, .. default_config(&Path("test")) }; - let mock_program_output = fn~(_prog: &str, _args: &[~str]) -> ProcOut { - ProcOut { + let mock_program_output = fn~(_prog: &str, _args: &[~str]) + -> ProgramOutput { + ProgramOutput { status: 1, out: ~"", err: ~"" } };