auto merge of #4839 : catamorphism/rust/rm-structural-records, r=catamorphism
This commit is contained in:
commit
e5637226d8
@ -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);
|
||||
}
|
||||
|
||||
|
@ -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 };
|
||||
|
@ -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
|
||||
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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};
|
||||
|
@ -187,18 +187,7 @@ pub trait Ptr<T> {
|
||||
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);
|
||||
|
@ -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};
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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<Config, ~str> {
|
||||
@ -135,7 +125,7 @@ pub fn parse_config(args: &[~str]) -> Result<Config, ~str> {
|
||||
|
||||
pub fn parse_config_(
|
||||
args: &[~str],
|
||||
program_output: ProgramOutput
|
||||
program_output: Process
|
||||
) -> Result<Config, ~str> {
|
||||
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<Config, ~str> {
|
||||
|
||||
let config = default_config(input_crate);
|
||||
@ -235,7 +225,7 @@ fn parse_output_style(output_style: &str) -> Result<OutputStyle, ~str> {
|
||||
fn maybe_find_pandoc(
|
||||
config: &Config,
|
||||
maybe_pandoc_cmd: Option<~str>,
|
||||
program_output: ProgramOutput
|
||||
program_output: Process
|
||||
) -> Result<Option<~str>, ~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: ~""
|
||||
}
|
||||
};
|
||||
|
Loading…
Reference in New Issue
Block a user