Skip to content

Commit fd7a513

Browse files
committed
libstd: Remove Cell from the library.
1 parent 6113508 commit fd7a513

File tree

10 files changed

+37
-91
lines changed

10 files changed

+37
-91
lines changed

src/librustuv/async.rs

+1
Original file line numberDiff line numberDiff line change
@@ -152,6 +152,7 @@ mod test_remote {
152152
let watcher = AsyncWatcher::new(local_loop(), cb as ~Callback);
153153

154154
let thread = do Thread::start {
155+
let mut watcher = watcher;
155156
watcher.fire();
156157
};
157158

src/librustuv/lib.rs

+3-7
Original file line numberDiff line numberDiff line change
@@ -395,13 +395,9 @@ fn local_loop() -> &'static mut Loop {
395395
unsafe {
396396
cast::transmute({
397397
let mut sched = Local::borrow(None::<Scheduler>);
398-
let mut io = None;
399-
sched.get().event_loop.io(|i| {
400-
let (_vtable, uvio): (uint, &'static mut uvio::UvIoFactory) =
401-
cast::transmute(i);
402-
io = Some(uvio);
403-
});
404-
io.unwrap()
398+
let (_vtable, uvio): (uint, &'static mut uvio::UvIoFactory) =
399+
cast::transmute(sched.get().event_loop.io().unwrap());
400+
uvio
405401
}.uv_loop())
406402
}
407403
}

src/librustuv/net.rs

+7-2
Original file line numberDiff line numberDiff line change
@@ -1073,15 +1073,16 @@ mod test {
10731073
let tasksFriendHandle = sched2.make_handle();
10741074
10751075
let on_exit: proc(UnwindResult) = proc(exit_status) {
1076+
let mut handle1 = handle1;
1077+
let mut handle2 = handle2;
10761078
handle1.send(Shutdown);
10771079
handle2.send(Shutdown);
10781080
assert!(exit_status.is_success());
10791081
};
10801082
10811083
unsafe fn local_io() -> &'static mut IoFactory {
10821084
let mut sched = Local::borrow(None::<Scheduler>);
1083-
let mut io = None;
1084-
sched.get().event_loop.io(|i| io = Some(i));
1085+
let io = sched.get().event_loop.io();
10851086
cast::transmute(io.unwrap())
10861087
}
10871088
@@ -1121,9 +1122,13 @@ mod test {
11211122
// nothing
11221123
};
11231124
1125+
let main_task = main_task;
1126+
let sched1 = sched1;
11241127
let thread1 = do Thread::start {
11251128
sched1.bootstrap(main_task);
11261129
};
1130+
1131+
let sched2 = sched2;
11271132
let thread2 = do Thread::start {
11281133
sched2.bootstrap(null_task);
11291134
};

src/librustuv/uvio.rs

+3-6
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
// except according to those terms.
1010

1111
use std::c_str::CString;
12-
use std::cast;
1312
use std::comm::SharedChan;
1413
use std::libc::c_int;
1514
use std::libc;
@@ -162,11 +161,9 @@ impl EventLoop for UvEventLoop {
162161
~AsyncWatcher::new(self.uvio.uv_loop(), f) as ~RemoteCallback
163162
}
164163

165-
fn io(&mut self) -> &'static mut IoFactory:'static {
166-
unsafe {
167-
let factory = &mut self.uvio as &mut IoFactory;
168-
cast::transmute(factory)
169-
}
164+
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory> {
165+
let factory = &mut self.uvio as &mut IoFactory;
166+
Some(factory)
170167
}
171168
}
172169

src/libstd/cell.rs

-60
Original file line numberDiff line numberDiff line change
@@ -14,66 +14,6 @@ use prelude::*;
1414
use cast;
1515
use util::NonCopyable;
1616

17-
18-
/*
19-
A dynamic, mutable location.
20-
21-
Similar to a mutable option type, but friendlier.
22-
*/
23-
24-
#[no_freeze]
25-
#[deriving(Clone, DeepClone, Eq)]
26-
#[allow(missing_doc)]
27-
pub struct Cell<T> {
28-
priv value: Option<T>
29-
}
30-
31-
impl<T> Cell<T> {
32-
/// Creates a new full cell with the given value.
33-
pub fn new(value: T) -> Cell<T> {
34-
Cell { value: Some(value) }
35-
}
36-
37-
/// Yields the value, failing if the cell is empty.
38-
pub fn take(&self) -> T {
39-
let this = unsafe { cast::transmute_mut(self) };
40-
if this.is_empty() {
41-
fail!("attempt to take an empty cell");
42-
}
43-
44-
this.value.take_unwrap()
45-
}
46-
47-
/// Yields the value if the cell is full, or `None` if it is empty.
48-
pub fn take_opt(&self) -> Option<T> {
49-
let this = unsafe { cast::transmute_mut(self) };
50-
this.value.take()
51-
}
52-
53-
/// Returns true if the cell is empty and false if the cell is full.
54-
pub fn is_empty(&self) -> bool {
55-
self.value.is_none()
56-
}
57-
}
58-
59-
#[test]
60-
fn test_basic() {
61-
let value_cell = Cell::new(~10);
62-
assert!(!value_cell.is_empty());
63-
let value = value_cell.take();
64-
assert!(value == ~10);
65-
assert!(value_cell.is_empty());
66-
}
67-
68-
#[test]
69-
#[should_fail]
70-
fn test_take_empty() {
71-
let value_cell: Cell<~int> = Cell::new(~0);
72-
value_cell.take();
73-
value_cell.take();
74-
}
75-
76-
7717
/// A mutable memory location with dynamically checked borrow rules
7818
#[no_freeze]
7919
pub struct RefCell<T> {

src/libstd/io/stdio.rs

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ use libc;
3131
use option::{Option, Some, None};
3232
use result::{Ok, Err};
3333
use io::buffered::LineBufferedWriter;
34-
use rt::rtio::{IoFactory, RtioTTY, RtioFileStream, DontClose};
34+
use rt::rtio::{DontClose, IoFactory, LocalIo, RtioFileStream, RtioTTY};
3535
use super::{Reader, Writer, io_error, IoError, OtherIoError,
3636
standard_error, EndOfFile};
3737

src/libstd/rt/basic.rs

+3-5
Original file line numberDiff line numberDiff line change
@@ -159,11 +159,9 @@ impl EventLoop for BasicLoop {
159159
~BasicRemote::new(self.messages.clone(), id) as ~RemoteCallback
160160
}
161161

162-
fn io(&mut self) -> &'static mut IoFactory:'static {
163-
unsafe {
164-
let factory: &mut IoFactory = self.io;
165-
cast::transmute(factory)
166-
}
162+
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory> {
163+
let factory: &mut IoFactory = self.io;
164+
Some(factory)
167165
}
168166
}
169167

src/libstd/rt/rtio.rs

+15-8
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ pub trait EventLoop {
3939
fn remote_callback(&mut self, ~Callback) -> ~RemoteCallback;
4040

4141
/// The asynchronous I/O services. Not all event loops may provide one.
42-
fn io(&mut self) -> &'static mut IoFactory:'static;
42+
fn io<'a>(&'a mut self) -> Option<&'a mut IoFactory>;
4343
}
4444

4545
pub trait RemoteCallback {
@@ -78,19 +78,19 @@ pub enum CloseBehavior {
7878
CloseAsynchronously,
7979
}
8080

81-
pub struct LocalIo {
82-
factory: &'static mut IoFactory:'static,
81+
pub struct LocalIo<'a> {
82+
priv factory: &'a mut IoFactory,
8383
}
8484

8585
#[unsafe_destructor]
86-
impl Drop for LocalIo {
86+
impl<'a> Drop for LocalIo<'a> {
8787
fn drop(&mut self) {
8888
// XXX(pcwalton): Do nothing here for now, but eventually we may want
8989
// something. For now this serves to make `LocalIo` noncopyable.
9090
}
9191
}
9292

93-
impl LocalIo {
93+
impl<'a> LocalIo<'a> {
9494
/// Returns the local I/O: either the local scheduler's I/O services or
9595
/// the native I/O services.
9696
pub fn borrow() -> LocalIo {
@@ -102,8 +102,13 @@ impl LocalIo {
102102
let sched: Option<*mut Scheduler> = Local::try_unsafe_borrow();
103103
match sched {
104104
Some(sched) => {
105-
return LocalIo {
106-
factory: (*sched).event_loop.io(),
105+
match (*sched).event_loop.io() {
106+
Some(factory) => {
107+
return LocalIo {
108+
factory: factory,
109+
}
110+
}
111+
None => {}
107112
}
108113
}
109114
None => {}
@@ -120,7 +125,9 @@ impl LocalIo {
120125

121126
/// Returns the underlying I/O factory as a trait reference.
122127
#[inline]
123-
pub fn get(&mut self) -> &'static mut IoFactory {
128+
pub fn get<'a>(&'a mut self) -> &'a mut IoFactory {
129+
// XXX(pcwalton): I think this is actually sound? Could borrow check
130+
// allow this safely?
124131
unsafe {
125132
cast::transmute_copy(&self.factory)
126133
}

src/test/bench/msgsend-ring-mutex-arcs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,9 @@ fn main() {
9090
for i in range(1u, num_tasks) {
9191
//error!("spawning %?", i);
9292
let (new_chan, num_port) = init();
93+
let num_chan_2 = num_chan.clone();
9394
let new_future = do Future::spawn() {
94-
thread_ring(i, msg_per_task, num_chan, num_port)
95+
thread_ring(i, msg_per_task, num_chan_2, num_port)
9596
};
9697
futures.push(new_future);
9798
num_chan = new_chan;

src/test/bench/msgsend-ring-rw-arcs.rs

+2-1
Original file line numberDiff line numberDiff line change
@@ -86,8 +86,9 @@ fn main() {
8686
for i in range(1u, num_tasks) {
8787
//error!("spawning %?", i);
8888
let (new_chan, num_port) = init();
89+
let num_chan_2 = num_chan.clone();
8990
let new_future = do Future::spawn {
90-
thread_ring(i, msg_per_task, num_chan, num_port)
91+
thread_ring(i, msg_per_task, num_chan_2, num_port)
9192
};
9293
futures.push(new_future);
9394
num_chan = new_chan;

0 commit comments

Comments
 (0)