Skip to content

Commit

Permalink
Merge remote-tracking branch 'remotes/origin/master' into remove-str-…
Browse files Browse the repository at this point in the history
…trailing-nulls
  • Loading branch information
erickt committed Aug 9, 2013
2 parents 03cc757 + 936f70b commit 56730c0
Show file tree
Hide file tree
Showing 159 changed files with 3,789 additions and 896 deletions.
42 changes: 42 additions & 0 deletions doc/tutorial-ffi.md
Original file line number Diff line number Diff line change
Expand Up @@ -228,6 +228,48 @@ unsafe fn kaboom(ptr: *int) -> int { *ptr }

This function can only be called from an `unsafe` block or another `unsafe` function.

# Accessing foreign globals

Foreign APIs often export a global variable which could do something like track
global state. In order to access these variables, you declare them in `extern`
blocks with the `static` keyword:

~~~{.xfail-test}
use std::libc;
#[link_args = "-lreadline"]
extern {
static rl_readline_version: libc::c_int;
}
fn main() {
println(fmt!("You have readline version %d installed.",
rl_readline_version as int));
}
~~~

Alternatively, you may need to alter global state provided by a foreign
interface. To do this, statics can be declared with `mut` so rust can mutate
them.

~~~{.xfail-test}
use std::libc;
use std::ptr;
#[link_args = "-lreadline"]
extern {
static mut rl_prompt: *libc::c_char;
}
fn main() {
do "[my-awesome-shell] $".as_c_str |buf| {
unsafe { rl_prompt = buf; }
// get a line, process it
unsafe { rl_prompt = ptr::null(); }
}
}
~~~

# Foreign calling conventions

Most foreign code exposes a C ABI, and Rust uses the platform's C calling convention by default when
Expand Down
25 changes: 14 additions & 11 deletions doc/tutorial-tasks.md
Original file line number Diff line number Diff line change
Expand Up @@ -424,7 +424,7 @@ there is no way to "catch" the exception.
All tasks are, by default, _linked_ to each other. That means that the fates
of all tasks are intertwined: if one fails, so do all the others.

~~~
~~~{.xfail-test .linked-failure}
# use std::task::spawn;
# use std::task;
# fn do_some_work() { loop { task::yield() } }
Expand All @@ -447,7 +447,7 @@ pattern-match on a result to check whether it's an `Ok` result with an `int`
field (representing a successful result) or an `Err` result (representing
termination with an error).

~~~
~~~{.xfail-test .linked-failure}
# use std::task;
# fn some_condition() -> bool { false }
# fn calculate_result() -> int { 0 }
Expand Down Expand Up @@ -490,9 +490,10 @@ proceed). Hence, you will need different _linked failure modes_.
By default, task failure is _bidirectionally linked_, which means that if
either task fails, it kills the other one.

~~~
~~~{.xfail-test .linked-failure}
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# use std::comm::oneshot;
# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
# do task::try {
do spawn {
do spawn {
Expand All @@ -511,11 +512,12 @@ function `task::try`, which we saw previously, uses `spawn_supervised`
internally, with additional logic to wait for the child task to finish
before returning. Hence:

~~~
~~~{.xfail-test .linked-failure}
# use std::comm::{stream, Chan, Port};
# use std::comm::oneshot;
# use std::task::{spawn, try};
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
# do task::try {
let (receiver, sender): (Port<int>, Chan<int>) = stream();
do spawn { // Bidirectionally linked
Expand All @@ -541,9 +543,10 @@ also fail.
Supervised task failure propagates across multiple generations even if
an intermediate generation has already exited:

~~~
~~~{.xfail-test .linked-failure}
# use std::task;
# fn sleep_forever() { loop { task::yield() } }
# use std::comm::oneshot;
# fn sleep_forever() { loop { let (p, c) = oneshot::<()>(); p.recv(); } }
# fn wait_for_a_while() { for _ in range(0, 1000u) { task::yield() } }
# do task::try::<int> {
do task::spawn_supervised {
Expand All @@ -560,7 +563,7 @@ fail!(); // Will kill grandchild even if child has already exited
Finally, tasks can be configured to not propagate failure to each
other at all, using `task::spawn_unlinked` for _isolated failure_.

~~~
~~~{.xfail-test .linked-failure}
# use std::task;
# fn random() -> uint { 100 }
# fn sleep_for(i: uint) { for _ in range(0, i) { task::yield() } }
Expand Down Expand Up @@ -588,7 +591,7 @@ that repeatedly receives a `uint` message, converts it to a string, and sends
the string in response. The child terminates when it receives `0`.
Here is the function that implements the child task:

~~~~
~~~{.xfail-test .linked-failure}
# use extra::comm::DuplexStream;
# use std::uint;
fn stringifier(channel: &DuplexStream<~str, uint>) {
Expand All @@ -611,7 +614,7 @@ response itself is simply the stringified version of the received value,
Here is the code for the parent task:
~~~~
~~~{.xfail-test .linked-failure}
# use std::task::spawn;
# use std::uint;
# use extra::comm::DuplexStream;
Expand Down
4 changes: 2 additions & 2 deletions doc/tutorial.md
Original file line number Diff line number Diff line change
Expand Up @@ -2288,8 +2288,8 @@ pub mod farm {
}
impl Farm {
priv fn feed_chickens(&self) { ... }
priv fn feed_cows(&self) { ... }
fn feed_chickens(&self) { ... }
fn feed_cows(&self) { ... }
pub fn add_chicken(&self, c: Chicken) { ... }
}
Expand Down
14 changes: 7 additions & 7 deletions src/compiletest/compiletest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -109,8 +109,8 @@ pub fn parse_config(args: ~[~str]) -> config {
compile_lib_path: getopts::opt_str(matches, "compile-lib-path"),
run_lib_path: getopts::opt_str(matches, "run-lib-path"),
rustc_path: opt_path(matches, "rustc-path"),
clang_path: getopts::opt_maybe_str(matches, "clang-path").map(|s| Path(*s)),
llvm_bin_path: getopts::opt_maybe_str(matches, "llvm-bin-path").map(|s| Path(*s)),
clang_path: getopts::opt_maybe_str(matches, "clang-path").map_move(|s| Path(s)),
llvm_bin_path: getopts::opt_maybe_str(matches, "llvm-bin-path").map_move(|s| Path(s)),
src_base: opt_path(matches, "src-base"),
build_base: opt_path(matches, "build-base"),
aux_base: opt_path(matches, "aux-base"),
Expand All @@ -123,14 +123,14 @@ pub fn parse_config(args: ~[~str]) -> config {
} else {
None
},
logfile: getopts::opt_maybe_str(matches, "logfile").map(|s| Path(*s)),
save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map(|s| Path(*s)),
logfile: getopts::opt_maybe_str(matches, "logfile").map_move(|s| Path(s)),
save_metrics: getopts::opt_maybe_str(matches, "save-metrics").map_move(|s| Path(s)),
ratchet_metrics:
getopts::opt_maybe_str(matches, "ratchet-metrics").map(|s| Path(*s)),
getopts::opt_maybe_str(matches, "ratchet-metrics").map_move(|s| Path(s)),
ratchet_noise_percent:
getopts::opt_maybe_str(matches,
"ratchet-noise-percent").map(|s|
f64::from_str(*s).unwrap()),
"ratchet-noise-percent").map_move(|s|
f64::from_str(s).unwrap()),
runtool: getopts::opt_maybe_str(matches, "runtool"),
rustcflags: getopts::opt_maybe_str(matches, "rustcflags"),
jit: getopts::opt_present(matches, "jit"),
Expand Down
9 changes: 4 additions & 5 deletions src/compiletest/runtest.rs
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,8 @@ fn run_pretty_test(config: &config, props: &TestProps, testfile: &Path) {
round += 1;
}

let mut expected =
match props.pp_exact {
Some(ref file) => {
let mut expected = match props.pp_exact {
Some(ref file) => {
let filepath = testfile.dir_path().push_rel(file);
io::read_whole_file_str(&filepath).unwrap()
}
Expand Down Expand Up @@ -413,8 +412,8 @@ fn check_expected_errors(expected_errors: ~[errors::ExpectedError],
}
}

for i in range(0u, found_flags.len()) {
if !found_flags[i] {
for (i, &flag) in found_flags.iter().enumerate() {
if !flag {
let ee = &expected_errors[i];
fatal_ProcRes(fmt!("expected %s on line %u not found: %s",
ee.kind, ee.line, ee.msg), ProcRes);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@
<keyword>for</keyword>
<keyword>if</keyword>
<keyword>impl</keyword>
<keyword>in</keyword>
<keyword>let</keyword>
<keyword>log</keyword>
<keyword>loop</keyword>
Expand Down
15 changes: 5 additions & 10 deletions src/libextra/arc.rs
Original file line number Diff line number Diff line change
Expand Up @@ -611,6 +611,7 @@ mod tests {
}
}
}
#[test] #[should_fail] #[ignore(cfg(windows))]
fn test_arc_condvar_poison() {
unsafe {
Expand Down Expand Up @@ -846,22 +847,16 @@ mod tests {
}
assert_eq!(*state, 42);
*state = 31337;
// FIXME: #7372: hits type inference bug with iterators
// send to other readers
for i in range(0u, reader_convos.len()) {
match reader_convos[i] {
(ref rc, _) => rc.send(()),
}
for &(ref rc, _) in reader_convos.iter() {
rc.send(())
}
}
let read_mode = arc.downgrade(write_mode);
do (&read_mode).read |state| {
// FIXME: #7372: hits type inference bug with iterators
// complete handshake with other readers
for i in range(0u, reader_convos.len()) {
match reader_convos[i] {
(_, ref rp) => rp.recv(),
}
for &(_, ref rp) in reader_convos.iter() {
rp.recv()
}
wc1.send(()); // tell writer to try again
assert_eq!(*state, 31337);
Expand Down
17 changes: 9 additions & 8 deletions src/libextra/bitv.rs
Original file line number Diff line number Diff line change
Expand Up @@ -145,22 +145,24 @@ impl BigBitv {
let len = b.storage.len();
assert_eq!(self.storage.len(), len);
let mut changed = false;
for i in range(0, len) {
for (i, (a, b)) in self.storage.mut_iter()
.zip(b.storage.iter())
.enumerate() {
let mask = big_mask(nbits, i);
let w0 = self.storage[i] & mask;
let w1 = b.storage[i] & mask;
let w0 = *a & mask;
let w1 = *b & mask;
let w = op(w0, w1) & mask;
if w0 != w {
changed = true;
self.storage[i] = w;
*a = w;
}
}
changed
}

#[inline]
pub fn each_storage(&mut self, op: &fn(v: &mut uint) -> bool) -> bool {
range(0u, self.storage.len()).advance(|i| op(&mut self.storage[i]))
self.storage.mut_iter().advance(|elt| op(elt))
}

#[inline]
Expand Down Expand Up @@ -205,10 +207,9 @@ impl BigBitv {

#[inline]
pub fn equals(&self, b: &BigBitv, nbits: uint) -> bool {
let len = b.storage.len();
for i in range(0, len) {
for (i, elt) in b.storage.iter().enumerate() {
let mask = big_mask(nbits, i);
if mask & self.storage[i] != mask & b.storage[i] {
if mask & self.storage[i] != mask & *elt {
return false;
}
}
Expand Down
20 changes: 10 additions & 10 deletions src/libextra/dlist.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl<T> DList<T> {
/// Remove the first Node and return it, or None if the list is empty
#[inline]
fn pop_front_node(&mut self) -> Option<~Node<T>> {
do self.list_head.take().map_consume |mut front_node| {
do self.list_head.take().map_move |mut front_node| {
self.length -= 1;
match front_node.next.take() {
Some(node) => self.list_head = link_with_prev(node, Rawlink::none()),
Expand All @@ -190,7 +190,7 @@ impl<T> DList<T> {
/// Remove the last Node and return it, or None if the list is empty
#[inline]
fn pop_back_node(&mut self) -> Option<~Node<T>> {
do self.list_tail.resolve().map_consume_default(None) |tail| {
do self.list_tail.resolve().map_move_default(None) |tail| {
self.length -= 1;
self.list_tail = tail.prev;
match tail.prev.resolve() {
Expand Down Expand Up @@ -237,7 +237,7 @@ impl<T> Deque<T> for DList<T> {
///
/// O(1)
fn pop_front(&mut self) -> Option<T> {
self.pop_front_node().map_consume(|~Node{value, _}| value)
self.pop_front_node().map_move(|~Node{value, _}| value)
}

/// Add an element last in the list
Expand All @@ -251,7 +251,7 @@ impl<T> Deque<T> for DList<T> {
///
/// O(1)
fn pop_back(&mut self) -> Option<T> {
self.pop_back_node().map_consume(|~Node{value, _}| value)
self.pop_back_node().map_move(|~Node{value, _}| value)
}
}

Expand All @@ -267,7 +267,7 @@ impl<T> DList<T> {
/// If the list is empty, do nothing.
#[inline]
pub fn rotate_forward(&mut self) {
do self.pop_back_node().map_consume |tail| {
do self.pop_back_node().map_move |tail| {
self.push_front_node(tail)
};
}
Expand All @@ -277,7 +277,7 @@ impl<T> DList<T> {
/// If the list is empty, do nothing.
#[inline]
pub fn rotate_backward(&mut self) {
do self.pop_front_node().map_consume |head| {
do self.pop_front_node().map_move |head| {
self.push_back_node(head)
};
}
Expand Down Expand Up @@ -463,7 +463,7 @@ impl<'self, A> DoubleEndedIterator<&'self A> for DListIterator<'self, A> {
if self.nelem == 0 {
return None;
}
do self.tail.resolve().map_consume |prev| {
do self.tail.resolve().map_move |prev| {
self.nelem -= 1;
self.tail = prev.prev;
&prev.value
Expand All @@ -477,7 +477,7 @@ impl<'self, A> Iterator<&'self mut A> for MutDListIterator<'self, A> {
if self.nelem == 0 {
return None;
}
do self.head.resolve().map_consume |next| {
do self.head.resolve().map_move |next| {
self.nelem -= 1;
self.head = match next.next {
Some(ref mut node) => Rawlink::some(&mut **node),
Expand All @@ -499,7 +499,7 @@ impl<'self, A> DoubleEndedIterator<&'self mut A> for MutDListIterator<'self, A>
if self.nelem == 0 {
return None;
}
do self.tail.resolve().map_consume |prev| {
do self.tail.resolve().map_move |prev| {
self.nelem -= 1;
self.tail = prev.prev;
&mut prev.value
Expand Down Expand Up @@ -553,7 +553,7 @@ impl<'self, A> ListInsertion<A> for MutDListIterator<'self, A> {
if self.nelem == 0 {
return None
}
self.head.resolve().map_consume(|head| &mut head.value)
self.head.resolve().map_move(|head| &mut head.value)
}
}

Expand Down
Loading

1 comment on commit 56730c0

@brson
Copy link

@brson brson commented on 56730c0 Aug 9, 2013

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

r+ p=1

Please sign in to comment.