Skip to content

Commit a0e82d8

Browse files
committed
---
yaml --- r: 63314 b: refs/heads/snap-stage3 c: d1ec8b5 h: refs/heads/master v: v3
1 parent cc886d4 commit a0e82d8

File tree

21 files changed

+1720
-387
lines changed

21 files changed

+1720
-387
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
---
22
refs/heads/master: 2d28d645422c1617be58c8ca7ad9a457264ca850
33
refs/heads/snap-stage1: e33de59e47c5076a89eadeb38f4934f58a3618a6
4-
refs/heads/snap-stage3: a7f92c92ed07588c3bde3cc38e64b9289ea682f5
4+
refs/heads/snap-stage3: d1ec8b5fb85cb6fd4caed64223c5cb3fd920daab
55
refs/heads/try: 7b78b52e602bb3ea8174f9b2006bff3315f03ef9
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b

branches/snap-stage3/src/libstd/macros.rs

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,18 @@ macro_rules! rtassert (
3838
} )
3939
)
4040

41+
42+
// The do_abort function was originally inside the abort macro, but
43+
// this was ICEing the compiler so it has been moved outside. Now this
44+
// seems to work?
45+
pub fn do_abort() -> ! {
46+
unsafe { ::libc::abort(); }
47+
}
48+
4149
macro_rules! abort(
4250
($( $msg:expr),+) => ( {
4351
rtdebug!($($msg),+);
44-
45-
do_abort();
46-
47-
// NB: This is in a fn to avoid putting the `unsafe` block in a macro,
48-
// which causes spurious 'unnecessary unsafe block' warnings.
49-
fn do_abort() -> ! {
50-
unsafe { ::libc::abort(); }
51-
}
52+
::macros::do_abort();
5253
} )
5354
)
55+

branches/snap-stage3/src/libstd/rt/comm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -120,13 +120,13 @@ impl<T> ChanOne<T> {
120120
match oldstate {
121121
STATE_BOTH => {
122122
// Port is not waiting yet. Nothing to do
123-
do Local::borrow::<Scheduler> |sched| {
123+
do Local::borrow::<Scheduler, ()> |sched| {
124124
rtdebug!("non-rendezvous send");
125125
sched.metrics.non_rendezvous_sends += 1;
126126
}
127127
}
128128
STATE_ONE => {
129-
do Local::borrow::<Scheduler> |sched| {
129+
do Local::borrow::<Scheduler, ()> |sched| {
130130
rtdebug!("rendezvous send");
131131
sched.metrics.rendezvous_sends += 1;
132132
}

branches/snap-stage3/src/libstd/rt/io/extensions.rs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -749,6 +749,8 @@ mod test {
749749
#[should_fail]
750750
#[ignore(cfg(windows))]
751751
fn push_bytes_fail_reset_len() {
752+
use unstable::finally::Finally;
753+
752754
// push_bytes unsafely sets the vector length. This is testing that
753755
// upon failure the length is reset correctly.
754756
let mut reader = MockReader::new();
@@ -770,8 +772,7 @@ mod test {
770772
reader.push_bytes(&mut *buf, 4);
771773
}).finally {
772774
// NB: Using rtassert here to trigger abort on failure since this is a should_fail test
773-
// FIXME: #7049 This fails because buf is still borrowed
774-
//rtassert!(*buf == ~[8, 9, 10]);
775+
rtassert!(*buf == ~[8, 9, 10]);
775776
}
776777
}
777778

branches/snap-stage3/src/libstd/rt/local.rs

Lines changed: 30 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ pub trait Local {
1818
fn put(value: ~Self);
1919
fn take() -> ~Self;
2020
fn exists() -> bool;
21-
fn borrow(f: &fn(&mut Self));
21+
fn borrow<T>(f: &fn(&mut Self) -> T) -> T;
2222
unsafe fn unsafe_borrow() -> *mut Self;
2323
unsafe fn try_unsafe_borrow() -> Option<*mut Self>;
2424
}
@@ -27,7 +27,20 @@ impl Local for Scheduler {
2727
fn put(value: ~Scheduler) { unsafe { local_ptr::put(value) }}
2828
fn take() -> ~Scheduler { unsafe { local_ptr::take() } }
2929
fn exists() -> bool { local_ptr::exists() }
30-
fn borrow(f: &fn(&mut Scheduler)) { unsafe { local_ptr::borrow(f) } }
30+
fn borrow<T>(f: &fn(&mut Scheduler) -> T) -> T {
31+
let mut res: Option<T> = None;
32+
let res_ptr: *mut Option<T> = &mut res;
33+
unsafe {
34+
do local_ptr::borrow |sched| {
35+
let result = f(sched);
36+
*res_ptr = Some(result);
37+
}
38+
}
39+
match res {
40+
Some(r) => { r }
41+
None => abort!("function failed!")
42+
}
43+
}
3144
unsafe fn unsafe_borrow() -> *mut Scheduler { local_ptr::unsafe_borrow() }
3245
unsafe fn try_unsafe_borrow() -> Option<*mut Scheduler> { abort!("unimpl") }
3346
}
@@ -36,8 +49,8 @@ impl Local for Task {
3649
fn put(_value: ~Task) { abort!("unimpl") }
3750
fn take() -> ~Task { abort!("unimpl") }
3851
fn exists() -> bool { abort!("unimpl") }
39-
fn borrow(f: &fn(&mut Task)) {
40-
do Local::borrow::<Scheduler> |sched| {
52+
fn borrow<T>(f: &fn(&mut Task) -> T) -> T {
53+
do Local::borrow::<Scheduler, T> |sched| {
4154
match sched.current_task {
4255
Some(~ref mut task) => {
4356
f(&mut *task.task)
@@ -74,7 +87,7 @@ impl Local for IoFactoryObject {
7487
fn put(_value: ~IoFactoryObject) { abort!("unimpl") }
7588
fn take() -> ~IoFactoryObject { abort!("unimpl") }
7689
fn exists() -> bool { abort!("unimpl") }
77-
fn borrow(_f: &fn(&mut IoFactoryObject)) { abort!("unimpl") }
90+
fn borrow<T>(_f: &fn(&mut IoFactoryObject) -> T) -> T { abort!("unimpl") }
7891
unsafe fn unsafe_borrow() -> *mut IoFactoryObject {
7992
let sched = Local::unsafe_borrow::<Scheduler>();
8093
let io: *mut IoFactoryObject = (*sched).event_loop.io().unwrap();
@@ -115,4 +128,16 @@ mod test {
115128
}
116129
let _scheduler: ~Scheduler = Local::take();
117130
}
131+
132+
#[test]
133+
fn borrow_with_return() {
134+
let scheduler = ~new_test_uv_sched();
135+
Local::put(scheduler);
136+
let res = do Local::borrow::<Scheduler,bool> |_sched| {
137+
true
138+
};
139+
assert!(res)
140+
let _scheduler: ~Scheduler = Local::take();
141+
}
142+
118143
}

branches/snap-stage3/src/libstd/rt/mod.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -208,7 +208,7 @@ pub fn context() -> RuntimeContext {
208208
} else {
209209
if Local::exists::<Scheduler>() {
210210
let context = ::cell::empty_cell();
211-
do Local::borrow::<Scheduler> |sched| {
211+
do Local::borrow::<Scheduler, ()> |sched| {
212212
if sched.in_task_context() {
213213
context.put_back(TaskContext);
214214
} else {

0 commit comments

Comments
 (0)