Skip to content

auto: std: Stamp out structural records #4796

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
28 changes: 12 additions & 16 deletions src/libstd/c_vec.rs
Original file line number Diff line number Diff line change
Expand Up @@ -46,11 +46,11 @@ use core::task;
/**
* The type representing a foreign chunk of memory
*
* Wrapped in a enum for opacity; FIXME #818 when it is possible to have
* truly opaque types, this should be revisited.
*/
pub enum CVec<T> {
CVecCtor({ base: *mut T, len: uint, rsrc: @DtorRes})
pub struct CVec<T> {
priv base: *mut T,
priv len: uint,
priv rsrc: @DtorRes
}

struct DtorRes {
Expand Down Expand Up @@ -85,11 +85,11 @@ fn DtorRes(dtor: Option<fn@()>) -> DtorRes {
* * len - The number of elements in the buffer
*/
pub unsafe fn CVec<T>(base: *mut T, len: uint) -> CVec<T> {
return CVecCtor({
return CVec{
base: base,
len: len,
rsrc: @DtorRes(option::None)
});
};
}

/**
Expand All @@ -105,11 +105,11 @@ pub unsafe fn CVec<T>(base: *mut T, len: uint) -> CVec<T> {
*/
pub unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
-> CVec<T> {
return CVecCtor({
return CVec{
base: base,
len: len,
rsrc: @DtorRes(option::Some(dtor))
});
};
}

/*
Expand All @@ -123,7 +123,7 @@ pub unsafe fn c_vec_with_dtor<T>(base: *mut T, len: uint, dtor: fn@())
*/
pub fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
assert ofs < len(t);
return unsafe { *ptr::mut_offset((*t).base, ofs) };
return unsafe { *ptr::mut_offset(t.base, ofs) };
}

/**
Expand All @@ -133,22 +133,18 @@ pub fn get<T: Copy>(t: CVec<T>, ofs: uint) -> T {
*/
pub fn set<T: Copy>(t: CVec<T>, ofs: uint, v: T) {
assert ofs < len(t);
unsafe { *ptr::mut_offset((*t).base, ofs) = v };
unsafe { *ptr::mut_offset(t.base, ofs) = v };
}

/*
Section: Elimination forms
*/

/// Returns the length of the vector
pub pure fn len<T>(t: CVec<T>) -> uint {
return (*t).len;
}
pub pure fn len<T>(t: CVec<T>) -> uint { t.len }

/// Returns a pointer to the first element of the vector
pub unsafe fn ptr<T>(t: CVec<T>) -> *mut T {
return (*t).base;
}
pub unsafe fn ptr<T>(t: CVec<T>) -> *mut T { t.base }

#[cfg(test)]
mod tests {
Expand Down
15 changes: 10 additions & 5 deletions src/libstd/ebml.rs
Original file line number Diff line number Diff line change
Expand Up @@ -84,22 +84,27 @@ pub mod reader {
}
}

fn vuint_at(data: &[u8], start: uint) -> {val: uint, next: uint} {
struct Res {
val: uint,
next: uint
}

fn vuint_at(data: &[u8], start: uint) -> Res {
let a = data[start];
if a & 0x80u8 != 0u8 {
return {val: (a & 0x7fu8) as uint, next: start + 1u};
return Res {val: (a & 0x7fu8) as uint, next: start + 1u};
}
if a & 0x40u8 != 0u8 {
return {val: ((a & 0x3fu8) as uint) << 8u |
return Res {val: ((a & 0x3fu8) as uint) << 8u |
(data[start + 1u] as uint),
next: start + 2u};
} else if a & 0x20u8 != 0u8 {
return {val: ((a & 0x1fu8) as uint) << 16u |
return Res {val: ((a & 0x1fu8) as uint) << 16u |
(data[start + 1u] as uint) << 8u |
(data[start + 2u] as uint),
next: start + 3u};
} else if a & 0x10u8 != 0u8 {
return {val: ((a & 0x0fu8) as uint) << 24u |
return Res {val: ((a & 0x0fu8) as uint) << 24u |
(data[start + 1u] as uint) << 16u |
(data[start + 2u] as uint) << 8u |
(data[start + 3u] as uint),
Expand Down
13 changes: 10 additions & 3 deletions src/libstd/md4.rs
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,14 @@ use core::str;
use core::uint;
use core::vec;

pub pure fn md4(msg: &[u8]) -> {a: u32, b: u32, c: u32, d: u32} {
struct Quad {
a: u32,
b: u32,
c: u32,
d: u32
}

pub pure fn md4(msg: &[u8]) -> Quad {
// subtle: if orig_len is merely uint, then the code below
// which performs shifts by 32 bits or more has undefined
// results.
Expand Down Expand Up @@ -95,11 +102,11 @@ pub pure fn md4(msg: &[u8]) -> {a: u32, b: u32, c: u32, d: u32} {
a += aa; b += bb; c += cc; d += dd;
i += 64u;
}
return {a: a, b: b, c: c, d: d};
return Quad {a: a, b: b, c: c, d: d};
}

pub pure fn md4_str(msg: &[u8]) -> ~str {
let {a, b, c, d} = md4(msg);
let Quad {a, b, c, d} = md4(msg);
pure fn app(a: u32, b: u32, c: u32, d: u32, f: fn(u32)) {
f(a); f(b); f(c); f(d);
}
Expand Down
4 changes: 2 additions & 2 deletions src/libstd/sha1.rs
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ const k3: u32 = 0xCA62C1D6u32;

/// Construct a `sha` object
pub fn sha1() -> Sha1 {
type Sha1State =
struct Sha1State
{h: ~[mut u32],
mut len_low: u32,
mut len_high: u32,
Expand Down Expand Up @@ -258,7 +258,7 @@ pub fn sha1() -> Sha1 {
return s;
}
}
let st = {
let st = Sha1State {
h: vec::cast_to_mut(vec::from_elem(digest_buf_len, 0u32)),
mut len_low: 0u32,
mut len_high: 0u32,
Expand Down
4 changes: 0 additions & 4 deletions src/libstd/std.rc
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,6 @@ not required in or otherwise suitable for the core library.
#[forbid(deprecated_pattern)];
#[allow(deprecated_self)];


// Transitional
#[legacy_records];

#[no_core];

extern mod core(vers = "0.6");
Expand Down
63 changes: 32 additions & 31 deletions src/libstd/test.rs
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
};

let filter =
if vec::len(matches.free) > 0u {
if vec::len(matches.free) > 0 {
option::Some(matches.free[0])
} else { option::None };

Expand All @@ -111,26 +111,27 @@ pub fn parse_opts(args: &[~str]) -> OptRes {
#[deriving_eq]
pub enum TestResult { TrOk, TrFailed, TrIgnored, }

type ConsoleTestState =
@{out: io::Writer,
log_out: Option<io::Writer>,
use_color: bool,
mut total: uint,
mut passed: uint,
mut failed: uint,
mut ignored: uint,
mut failures: ~[TestDesc]};
struct ConsoleTestState {
out: io::Writer,
log_out: Option<io::Writer>,
use_color: bool,
mut total: uint,
mut passed: uint,
mut failed: uint,
mut ignored: uint,
mut failures: ~[TestDesc]
}

// A simple console test runner
pub fn run_tests_console(opts: &TestOpts,
tests: &[TestDesc]) -> bool {

fn callback(event: &TestEvent, st: ConsoleTestState) {
fn callback(event: &TestEvent, st: @ConsoleTestState) {
debug!("callback(event=%?)", event);
match *event {
TeFiltered(ref filtered_tests) => {
st.total = filtered_tests.len();
let noun = if st.total != 1u { ~"tests" } else { ~"test" };
let noun = if st.total != 1 { ~"tests" } else { ~"test" };
st.out.write_line(fmt!("\nrunning %u %s", st.total, noun));
}
TeWait(ref test) => st.out.write_str(
Expand All @@ -142,18 +143,18 @@ pub fn run_tests_console(opts: &TestOpts,
}
match result {
TrOk => {
st.passed += 1u;
st.passed += 1;
write_ok(st.out, st.use_color);
st.out.write_line(~"");
}
TrFailed => {
st.failed += 1u;
st.failed += 1;
write_failed(st.out, st.use_color);
st.out.write_line(~"");
st.failures.push(move test);
}
TrIgnored => {
st.ignored += 1u;
st.ignored += 1;
write_ignored(st.out, st.use_color);
st.out.write_line(~"");
}
Expand All @@ -174,19 +175,19 @@ pub fn run_tests_console(opts: &TestOpts,
};

let st =
@{out: io::stdout(),
@ConsoleTestState{out: io::stdout(),
log_out: log_out,
use_color: use_color(),
mut total: 0u,
mut passed: 0u,
mut failed: 0u,
mut ignored: 0u,
mut total: 0,
mut passed: 0,
mut failed: 0,
mut ignored: 0,
mut failures: ~[]};

run_tests(opts, tests, |x| callback(&x, st));

assert (st.passed + st.failed + st.ignored == st.total);
let success = st.failed == 0u;
let success = st.failed == 0;

if !success {
print_failures(st);
Expand Down Expand Up @@ -234,7 +235,7 @@ pub fn run_tests_console(opts: &TestOpts,
}
}

fn print_failures(st: ConsoleTestState) {
fn print_failures(st: @ConsoleTestState) {
st.out.write_line(~"\nfailures:");
let failures = copy st.failures;
let failures = vec::map(failures, |test| test.name);
Expand Down Expand Up @@ -262,13 +263,13 @@ fn should_sort_failures_before_printing_them() {
};

let st =
@{out: wr,
@ConsoleTestState{out: wr,
log_out: option::None,
use_color: false,
mut total: 0u,
mut passed: 0u,
mut failed: 0u,
mut ignored: 0u,
mut total: 0,
mut passed: 0,
mut failed: 0,
mut ignored: 0,
mut failures: ~[move test_b, move test_a]};

print_failures(st);
Expand All @@ -279,7 +280,7 @@ fn should_sort_failures_before_printing_them() {
assert apos < bpos;
}

fn use_color() -> bool { return get_concurrency() == 1u; }
fn use_color() -> bool { return get_concurrency() == 1; }

enum TestEvent {
TeFiltered(~[TestDesc]),
Expand Down Expand Up @@ -334,15 +335,15 @@ fn run_tests(opts: &TestOpts,

// Windows tends to dislike being overloaded with threads.
#[cfg(windows)]
const sched_overcommit : uint = 1u;
const sched_overcommit : uint = 1;

#[cfg(unix)]
const sched_overcommit : uint = 4u;

fn get_concurrency() -> uint {
unsafe {
let threads = rustrt::rust_sched_threads() as uint;
if threads == 1u { 1u }
if threads == 1 { 1 }
else { threads * sched_overcommit }
}
}
Expand Down Expand Up @@ -556,7 +557,7 @@ mod tests {
];
let filtered = filter_tests(&opts, tests);

assert (vec::len(filtered) == 1u);
assert (vec::len(filtered) == 1);
assert (filtered[0].name == ~"1");
assert (filtered[0].ignore == false);
}
Expand Down
16 changes: 7 additions & 9 deletions src/libstd/uv_iotask.rs
Original file line number Diff line number Diff line change
Expand Up @@ -27,19 +27,17 @@ use core::task::TaskBuilder;
use core::task;

/// Used to abstract-away direct interaction with a libuv loop.
pub enum IoTask {
IoTask_({
async_handle: *ll::uv_async_t,
op_chan: SharedChan<IoTaskMsg>
})
pub struct IoTask {
async_handle: *ll::uv_async_t,
op_chan: SharedChan<IoTaskMsg>
}

impl IoTask: Clone {
fn clone(&self) -> IoTask {
IoTask_({
IoTask{
async_handle: self.async_handle,
op_chan: self.op_chan.clone()
})
}
}
}

Expand Down Expand Up @@ -131,10 +129,10 @@ fn run_loop(iotask_ch: &Chan<IoTask>) {

// Send out a handle through which folks can talk to us
// while we dwell in the I/O loop
let iotask = IoTask_({
let iotask = IoTask{
async_handle: async_handle,
op_chan: SharedChan(msg_ch)
});
};
iotask_ch.send(iotask);

log(debug, ~"about to run uv loop");
Expand Down
2 changes: 1 addition & 1 deletion src/libstd/uv_ll.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1543,7 +1543,7 @@ pub mod test {
let continue_async_handle_ptr =
ptr::addr_of(&continue_async_handle);
let async_data =
{ continue_chan: continue_chan };
async_handle_data { continue_chan: continue_chan };
let async_data_ptr = ptr::addr_of(&async_data);

let server_data = tcp_server_data {
Expand Down