Skip to content

Commit d60a870

Browse files
committed
---
yaml --- r: 110867 b: refs/heads/auto c: f862e12 h: refs/heads/master i: 110865: 75197bf 110863: fa51ea6 v: v3
1 parent ff3b12c commit d60a870

29 files changed

+286
-256
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ refs/heads/try3: 9387340aab40a73e8424c48fd42f0c521a4875c0
1313
refs/tags/release-0.3.1: 495bae036dfe5ec6ceafd3312b4dca48741e845b
1414
refs/tags/release-0.4: e828ea2080499553b97dfe33b3f4d472b4562ad7
1515
refs/tags/release-0.5: 7e3bcfbf21278251ee936ad53e92e9b719702d73
16-
refs/heads/auto: ab0d8472777d2359492dfdee1d21230fbf144f70
16+
refs/heads/auto: f862e1256d846e235b749358ab6fe3a324c1b25c
1717
refs/heads/servo: af82457af293e2a842ba6b7759b70288da276167
1818
refs/tags/release-0.6: b4ebcfa1812664df5e142f0134a5faea3918544c
1919
refs/tags/0.1: b19db808c2793fe2976759b85a355c3ad8c8b336

branches/auto/src/doc/guide-ffi.md

Lines changed: 58 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -11,14 +11,16 @@ snappy includes a C interface (documented in
1111
The following is a minimal example of calling a foreign function which will
1212
compile if snappy is installed:
1313

14-
~~~~ {.ignore}
14+
~~~~
1515
extern crate libc;
1616
use libc::size_t;
1717
1818
#[link(name = "snappy")]
19+
# #[cfg(ignore_this)]
1920
extern {
2021
fn snappy_max_compressed_length(source_length: size_t) -> size_t;
2122
}
23+
# unsafe fn snappy_max_compressed_length(a: size_t) -> size_t { a }
2224
2325
fn main() {
2426
let x = unsafe { snappy_max_compressed_length(100) };
@@ -78,7 +80,11 @@ vectors as pointers to memory. Rust's vectors are guaranteed to be a contiguous
7880
length is number of elements currently contained, and the capacity is the total size in elements of
7981
the allocated memory. The length is less than or equal to the capacity.
8082

81-
~~~~ {.ignore}
83+
~~~~
84+
# extern crate libc;
85+
# use libc::{c_int, size_t};
86+
# unsafe fn snappy_validate_compressed_buffer(_: *u8, _: size_t) -> c_int { 0 }
87+
# fn main() {}
8288
pub fn validate_compressed_buffer(src: &[u8]) -> bool {
8389
unsafe {
8490
snappy_validate_compressed_buffer(src.as_ptr(), src.len() as size_t) == 0
@@ -98,14 +104,20 @@ required capacity to hold the compressed output. The vector can then be passed t
98104
`snappy_compress` function as an output parameter. An output parameter is also passed to retrieve
99105
the true length after compression for setting the length.
100106

101-
~~~~ {.ignore}
102-
pub fn compress(src: &[u8]) -> ~[u8] {
107+
~~~~
108+
# extern crate libc;
109+
# use libc::{size_t, c_int};
110+
# unsafe fn snappy_compress(a: *u8, b: size_t, c: *mut u8,
111+
# d: *mut size_t) -> c_int { 0 }
112+
# unsafe fn snappy_max_compressed_length(a: size_t) -> size_t { a }
113+
# fn main() {}
114+
pub fn compress(src: &[u8]) -> Vec<u8> {
103115
unsafe {
104116
let srclen = src.len() as size_t;
105117
let psrc = src.as_ptr();
106118
107119
let mut dstlen = snappy_max_compressed_length(srclen);
108-
let mut dst = slice::with_capacity(dstlen as uint);
120+
let mut dst = Vec::with_capacity(dstlen as uint);
109121
let pdst = dst.as_mut_ptr();
110122
111123
snappy_compress(psrc, srclen, pdst, &mut dstlen);
@@ -118,16 +130,26 @@ pub fn compress(src: &[u8]) -> ~[u8] {
118130
Decompression is similar, because snappy stores the uncompressed size as part of the compression
119131
format and `snappy_uncompressed_length` will retrieve the exact buffer size required.
120132

121-
~~~~ {.ignore}
122-
pub fn uncompress(src: &[u8]) -> Option<~[u8]> {
133+
~~~~
134+
# extern crate libc;
135+
# use libc::{size_t, c_int};
136+
# unsafe fn snappy_uncompress(compressed: *u8,
137+
# compressed_length: size_t,
138+
# uncompressed: *mut u8,
139+
# uncompressed_length: *mut size_t) -> c_int { 0 }
140+
# unsafe fn snappy_uncompressed_length(compressed: *u8,
141+
# compressed_length: size_t,
142+
# result: *mut size_t) -> c_int { 0 }
143+
# fn main() {}
144+
pub fn uncompress(src: &[u8]) -> Option<Vec<u8>> {
123145
unsafe {
124146
let srclen = src.len() as size_t;
125147
let psrc = src.as_ptr();
126148
127149
let mut dstlen: size_t = 0;
128150
snappy_uncompressed_length(psrc, srclen, &mut dstlen);
129151
130-
let mut dst = slice::with_capacity(dstlen as uint);
152+
let mut dst = Vec::with_capacity(dstlen as uint);
131153
let pdst = dst.as_mut_ptr();
132154
133155
if snappy_uncompress(psrc, srclen, pdst, &mut dstlen) == 0 {
@@ -187,16 +209,19 @@ A basic example is:
187209

188210
Rust code:
189211

190-
~~~~ {.ignore}
212+
~~~~
191213
extern fn callback(a:i32) {
192214
println!("I'm called from C with value {0}", a);
193215
}
194216
195217
#[link(name = "extlib")]
218+
# #[cfg(ignore)]
196219
extern {
197-
fn register_callback(cb: extern "C" fn(i32)) -> i32;
220+
fn register_callback(cb: extern fn(i32)) -> i32;
198221
fn trigger_callback();
199222
}
223+
# unsafe fn register_callback(cb: extern fn(i32)) -> i32 { 0 }
224+
# unsafe fn trigger_callback() { }
200225
201226
fn main() {
202227
unsafe {
@@ -240,33 +265,39 @@ referenced Rust object.
240265

241266
Rust code:
242267

243-
~~~~ {.ignore}
268+
~~~~
244269
245270
struct RustObject {
246271
a: i32,
247272
// other members
248273
}
249274
250-
extern fn callback(target: *RustObject, a:i32) {
275+
extern fn callback(target: *mut RustObject, a:i32) {
251276
println!("I'm called from C with value {0}", a);
252-
(*target).a = a; // Update the value in RustObject with the value received from the callback
277+
unsafe {
278+
// Update the value in RustObject with the value received from the callback
279+
(*target).a = a;
280+
}
253281
}
254282
255283
#[link(name = "extlib")]
284+
# #[cfg(ignore)]
256285
extern {
257-
fn register_callback(target: *RustObject, cb: extern "C" fn(*RustObject, i32)) -> i32;
286+
fn register_callback(target: *mut RustObject,
287+
cb: extern fn(*mut RustObject, i32)) -> i32;
258288
fn trigger_callback();
259289
}
290+
# unsafe fn register_callback(a: *mut RustObject,
291+
# b: extern fn(*mut RustObject, i32)) -> i32 { 0 }
292+
# unsafe fn trigger_callback() {}
260293
261294
fn main() {
262295
// Create the object that will be referenced in the callback
263-
let rust_object = ~RustObject{a: 5, ...};
296+
let mut rust_object = ~RustObject{ a: 5 };
264297
265298
unsafe {
266-
// Gets a raw pointer to the object
267-
let target_addr:*RustObject = ptr::to_unsafe_ptr(rust_object);
268-
register_callback(target_addr, callback);
269-
trigger_callback(); // Triggers the callback
299+
register_callback(&mut *rust_object, callback);
300+
trigger_callback();
270301
}
271302
}
272303
~~~~
@@ -403,13 +434,15 @@ Foreign APIs often export a global variable which could do something like track
403434
global state. In order to access these variables, you declare them in `extern`
404435
blocks with the `static` keyword:
405436

406-
~~~{.ignore}
437+
~~~
407438
extern crate libc;
408439
409440
#[link(name = "readline")]
441+
# #[cfg(ignore)]
410442
extern {
411443
static rl_readline_version: libc::c_int;
412444
}
445+
# static rl_readline_version: libc::c_int = 0;
413446
414447
fn main() {
415448
println!("You have readline version {} installed.",
@@ -421,21 +454,23 @@ Alternatively, you may need to alter global state provided by a foreign
421454
interface. To do this, statics can be declared with `mut` so rust can mutate
422455
them.
423456

424-
~~~{.ignore}
457+
~~~
425458
extern crate libc;
426459
use std::ptr;
427460
428461
#[link(name = "readline")]
462+
# #[cfg(ignore)]
429463
extern {
430464
static mut rl_prompt: *libc::c_char;
431465
}
466+
# static mut rl_prompt: *libc::c_char = 0 as *libc::c_char;
432467
433468
fn main() {
434-
do "[my-awesome-shell] $".as_c_str |buf| {
469+
"[my-awesome-shell] $".with_c_str(|buf| {
435470
unsafe { rl_prompt = buf; }
436471
// get a line, process it
437472
unsafe { rl_prompt = ptr::null(); }
438-
}
473+
});
439474
}
440475
~~~
441476

branches/auto/src/libgreen/sched.rs

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1011,6 +1011,7 @@ fn new_sched_rng() -> XorShiftRng {
10111011
mod test {
10121012
use rustuv;
10131013

1014+
use std::comm;
10141015
use std::task::TaskOpts;
10151016
use std::rt::task::Task;
10161017
use std::rt::local::Local;
@@ -1427,7 +1428,7 @@ mod test {
14271428
// This task should not be able to starve the sender;
14281429
// The sender should get stolen to another thread.
14291430
spawn(proc() {
1430-
while rx.try_recv().is_err() { }
1431+
while rx.try_recv() != comm::Data(()) { }
14311432
});
14321433

14331434
tx.send(());
@@ -1444,7 +1445,7 @@ mod test {
14441445
// This task should not be able to starve the other task.
14451446
// The sends should eventually yield.
14461447
spawn(proc() {
1447-
while rx1.try_recv().is_err() {
1448+
while rx1.try_recv() != comm::Data(()) {
14481449
tx2.send(());
14491450
}
14501451
});
@@ -1498,7 +1499,7 @@ mod test {
14981499
let mut val = 20;
14991500
while val > 0 {
15001501
val = po.recv();
1501-
let _ = ch.send_opt(val - 1);
1502+
ch.try_send(val - 1);
15021503
}
15031504
}
15041505

branches/auto/src/libgreen/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -515,7 +515,7 @@ mod tests {
515515
let _tx = tx;
516516
fail!()
517517
});
518-
assert_eq!(rx.recv_opt(), Err(()));
518+
assert_eq!(rx.recv_opt(), None);
519519
}
520520

521521
#[test]

branches/auto/src/libnative/io/timer_other.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,7 @@
4646
//!
4747
//! Note that all time units in this file are in *milliseconds*.
4848
49+
use std::comm::Data;
4950
use libc;
5051
use std::mem;
5152
use std::os;
@@ -118,7 +119,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
118119
Some(timer) => timer, None => return
119120
};
120121
let tx = timer.tx.take_unwrap();
121-
if tx.send_opt(()).is_ok() && timer.repeat {
122+
if tx.try_send(()) && timer.repeat {
122123
timer.tx = Some(tx);
123124
timer.target += timer.interval;
124125
insert(timer, active);
@@ -161,14 +162,14 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
161162
1 => {
162163
loop {
163164
match messages.try_recv() {
164-
Ok(Shutdown) => {
165+
Data(Shutdown) => {
165166
assert!(active.len() == 0);
166167
break 'outer;
167168
}
168169

169-
Ok(NewTimer(timer)) => insert(timer, &mut active),
170+
Data(NewTimer(timer)) => insert(timer, &mut active),
170171

171-
Ok(RemoveTimer(id, ack)) => {
172+
Data(RemoveTimer(id, ack)) => {
172173
match dead.iter().position(|&(i, _)| id == i) {
173174
Some(i) => {
174175
let (_, i) = dead.remove(i).unwrap();

branches/auto/src/libnative/io/timer_timerfd.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
//!
2929
//! As with timer_other, all units in this file are in units of millseconds.
3030
31+
use std::comm::Data;
3132
use libc;
3233
use std::ptr;
3334
use std::os;
@@ -106,7 +107,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
106107
match list.as_slice().bsearch(|&(f, _, _)| f.cmp(&fd)) {
107108
Some(i) => {
108109
let (_, ref c, oneshot) = *list.get(i);
109-
(c.send_opt(()).is_err() || oneshot, i)
110+
(!c.try_send(()) || oneshot, i)
110111
}
111112
None => fail!("fd not active: {}", fd),
112113
}
@@ -120,7 +121,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
120121

121122
while incoming {
122123
match messages.try_recv() {
123-
Ok(NewTimer(fd, chan, one, timeval)) => {
124+
Data(NewTimer(fd, chan, one, timeval)) => {
124125
// acknowledge we have the new channel, we will never send
125126
// another message to the old channel
126127
chan.send(());
@@ -148,7 +149,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
148149
assert_eq!(ret, 0);
149150
}
150151

151-
Ok(RemoveTimer(fd, chan)) => {
152+
Data(RemoveTimer(fd, chan)) => {
152153
match list.as_slice().bsearch(|&(f, _, _)| f.cmp(&fd)) {
153154
Some(i) => {
154155
drop(list.remove(i));
@@ -159,7 +160,7 @@ fn helper(input: libc::c_int, messages: Receiver<Req>) {
159160
chan.send(());
160161
}
161162

162-
Ok(Shutdown) => {
163+
Data(Shutdown) => {
163164
assert!(list.len() == 0);
164165
break 'outer;
165166
}

branches/auto/src/libnative/io/timer_win32.rs

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
//! Other than that, the implementation is pretty straightforward in terms of
2121
//! the other two implementations of timers with nothing *that* new showing up.
2222
23+
use std::comm::Data;
2324
use libc;
2425
use std::ptr;
2526
use std::rt::rtio;
@@ -53,11 +54,11 @@ fn helper(input: libc::HANDLE, messages: Receiver<Req>) {
5354
if idx == 0 {
5455
loop {
5556
match messages.try_recv() {
56-
Ok(NewTimer(obj, c, one)) => {
57+
Data(NewTimer(obj, c, one)) => {
5758
objs.push(obj);
5859
chans.push((c, one));
5960
}
60-
Ok(RemoveTimer(obj, c)) => {
61+
Data(RemoveTimer(obj, c)) => {
6162
c.send(());
6263
match objs.iter().position(|&o| o == obj) {
6364
Some(i) => {
@@ -67,7 +68,7 @@ fn helper(input: libc::HANDLE, messages: Receiver<Req>) {
6768
None => {}
6869
}
6970
}
70-
Ok(Shutdown) => {
71+
Data(Shutdown) => {
7172
assert_eq!(objs.len(), 1);
7273
assert_eq!(chans.len(), 0);
7374
break 'outer;
@@ -78,7 +79,7 @@ fn helper(input: libc::HANDLE, messages: Receiver<Req>) {
7879
} else {
7980
let remove = {
8081
match chans.get(idx as uint - 1) {
81-
&(ref c, oneshot) => c.send_opt(()).is_err() || oneshot
82+
&(ref c, oneshot) => !c.try_send(()) || oneshot
8283
}
8384
};
8485
if remove {

branches/auto/src/libnative/task.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -274,7 +274,7 @@ mod tests {
274274
let _tx = tx;
275275
fail!()
276276
});
277-
assert_eq!(rx.recv_opt(), Err(()));
277+
assert_eq!(rx.recv_opt(), None);
278278
}
279279

280280
#[test]

branches/auto/src/librustuv/net.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1065,7 +1065,7 @@ mod test {
10651065
}
10661066
reads += 1;
10671067

1068-
let _ = tx2.send_opt(());
1068+
tx2.try_send(());
10691069
}
10701070

10711071
// Make sure we had multiple reads

branches/auto/src/librustuv/signal.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ impl SignalWatcher {
5151
extern fn signal_cb(handle: *uvll::uv_signal_t, signum: c_int) {
5252
let s: &mut SignalWatcher = unsafe { UvHandle::from_uv_handle(&handle) };
5353
assert_eq!(signum as int, s.signal as int);
54-
let _ = s.channel.send_opt(s.signal);
54+
s.channel.try_send(s.signal);
5555
}
5656

5757
impl HomingIO for SignalWatcher {

0 commit comments

Comments
 (0)