Skip to content

Commit d91437b

Browse files
committed
---
yaml --- r: 142606 b: refs/heads/try2 c: d64d26c h: refs/heads/master v: v3
1 parent 55cfb3c commit d91437b

File tree

14 files changed

+966
-25
lines changed

14 files changed

+966
-25
lines changed

[refs]

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ refs/heads/snap-stage3: 78a7676898d9f80ab540c6df5d4c9ce35bb50463
55
refs/heads/try: 519addf6277dbafccbb4159db4b710c37eaa2ec5
66
refs/tags/release-0.1: 1f5c5126e96c79d22cb7862f75304136e204f105
77
refs/heads/ndm: f3868061cd7988080c30d6d5bf352a5a5fe2460b
8-
refs/heads/try2: e7213aa21e9a79db01d2e9d1b76761a420e4c967
8+
refs/heads/try2: d64d26cd39a86a40feb0db7a9147cc2ae5e82994
99
refs/heads/dist-snap: ba4081a5a8573875fed17545846f6f6902c8ba8d
1010
refs/tags/release-0.2: c870d2dffb391e14efb05aa27898f1f6333a9596
1111
refs/tags/release-0.3: b5f0d0f648d9a6153664837026ba1be43d3e2503

branches/try2/src/libstd/macros.rs

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -38,16 +38,29 @@ 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),+);
4452

45-
do_abort();
53+
// do_abort();
54+
55+
// NB: This is in a fn to avoid putting the `unsafe` block in
56+
// a macro, which causes spurious 'unnecessary unsafe block'
57+
// warnings.
58+
// fn do_abort() -> ! {
59+
// unsafe { ::libc::abort(); }
60+
// }
61+
62+
::macros::do_abort();
4663

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-
}
5264
} )
5365
)
66+

branches/try2/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/try2/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/try2/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/try2/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 {

branches/try2/src/libstd/rt/sched.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -683,7 +683,7 @@ mod test {
683683
assert_eq!(count, MAX);
684684

685685
fn run_task(count_ptr: *mut int) {
686-
do Local::borrow::<Scheduler> |sched| {
686+
do Local::borrow::<Scheduler, ()> |sched| {
687687
let task = ~do Coroutine::new(&mut sched.stack_pool) {
688688
unsafe {
689689
*count_ptr = *count_ptr + 1;

branches/try2/src/libstd/rt/task.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ impl Task {
6262
pub fn run(&mut self, f: &fn()) {
6363
// This is just an assertion that `run` was called unsafely
6464
// and this instance of Task is still accessible.
65-
do Local::borrow::<Task> |task| {
65+
do Local::borrow::<Task, ()> |task| {
6666
assert!(ptr::ref_eq(task, self));
6767
}
6868

@@ -87,7 +87,7 @@ impl Task {
8787
fn destroy(&mut self) {
8888
// This is just an assertion that `destroy` was called unsafely
8989
// and this instance of Task is still accessible.
90-
do Local::borrow::<Task> |task| {
90+
do Local::borrow::<Task, ()> |task| {
9191
assert!(ptr::ref_eq(task, self));
9292
}
9393
match self.storage {

branches/try2/src/libstd/rt/tube.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -155,7 +155,7 @@ mod test {
155155
if i == 100 { return; }
156156

157157
let tube = Cell(Cell(tube));
158-
do Local::borrow::<Scheduler> |sched| {
158+
do Local::borrow::<Scheduler, ()> |sched| {
159159
let tube = tube.take();
160160
do sched.event_loop.callback {
161161
let mut tube = tube.take();

branches/try2/src/libstd/rt/uv/uvio.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ mod test_remote {
167167
let mut tube = Tube::new();
168168
let tube_clone = tube.clone();
169169
let remote_cell = cell::empty_cell();
170-
do Local::borrow::<Scheduler>() |sched| {
170+
do Local::borrow::<Scheduler, ()>() |sched| {
171171
let tube_clone = tube_clone.clone();
172172
let tube_clone_cell = Cell(tube_clone);
173173
let remote = do sched.event_loop.remote_callback {

0 commit comments

Comments
 (0)