diff options
| author | Patrick Walton <pcwalton@mimiga.net> | 2013-05-23 19:12:16 -0700 |
|---|---|---|
| committer | Patrick Walton <pcwalton@mimiga.net> | 2013-05-29 19:04:50 -0700 |
| commit | aeda178011775f4a8e16446341fe4774e02d8f5f (patch) | |
| tree | 6e96ca95949ebee511eea69ebe1a854cc31dee0a /src/libstd | |
| parent | b5da389d36ec9108f82bb7025eabb7ce4f26b103 (diff) | |
| download | rust-aeda178011775f4a8e16446341fe4774e02d8f5f.tar.gz rust-aeda178011775f4a8e16446341fe4774e02d8f5f.zip | |
librustc: Redo the unsafe checker and make unsafe methods not callable from safe code
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/comm.rs | 20 | ||||
| -rw-r--r-- | src/libstd/os.rs | 24 | ||||
| -rw-r--r-- | src/libstd/rt/message_queue.rs | 18 | ||||
| -rw-r--r-- | src/libstd/rt/work_queue.rs | 34 | ||||
| -rw-r--r-- | src/libstd/task/spawn.rs | 8 |
5 files changed, 61 insertions, 43 deletions
diff --git a/src/libstd/comm.rs b/src/libstd/comm.rs index 59eb915c239..adc2c21580b 100644 --- a/src/libstd/comm.rs +++ b/src/libstd/comm.rs @@ -236,20 +236,24 @@ impl<T: Owned> SharedChan<T> { impl<T: Owned> GenericChan<T> for SharedChan<T> { fn send(&self, x: T) { - let mut xx = Some(x); - do self.ch.with_imm |chan| { - let x = replace(&mut xx, None); - chan.send(x.unwrap()) + unsafe { + let mut xx = Some(x); + do self.ch.with_imm |chan| { + let x = replace(&mut xx, None); + chan.send(x.unwrap()) + } } } } impl<T: Owned> GenericSmartChan<T> for SharedChan<T> { fn try_send(&self, x: T) -> bool { - let mut xx = Some(x); - do self.ch.with_imm |chan| { - let x = replace(&mut xx, None); - chan.try_send(x.unwrap()) + unsafe { + let mut xx = Some(x); + do self.ch.with_imm |chan| { + let x = replace(&mut xx, None); + chan.try_send(x.unwrap()) + } } } } diff --git a/src/libstd/os.rs b/src/libstd/os.rs index 15c68efc7cc..9c8c2dbe4d7 100644 --- a/src/libstd/os.rs +++ b/src/libstd/os.rs @@ -861,20 +861,18 @@ pub fn change_dir_locked(p: &Path, action: &fn()) -> bool { fn key(_: Exclusive<()>) { } - let result = unsafe { - global_data_clone_create(key, || { - ~exclusive(()) - }) - }; + unsafe { + let result = global_data_clone_create(key, || { ~exclusive(()) }); - do result.with_imm() |_| { - let old_dir = os::getcwd(); - if change_dir(p) { - action(); - change_dir(&old_dir) - } - else { - false + do result.with_imm() |_| { + let old_dir = os::getcwd(); + if change_dir(p) { + action(); + change_dir(&old_dir) + } + else { + false + } } } } diff --git a/src/libstd/rt/message_queue.rs b/src/libstd/rt/message_queue.rs index eaab9288ac8..fb1a5334646 100644 --- a/src/libstd/rt/message_queue.rs +++ b/src/libstd/rt/message_queue.rs @@ -29,16 +29,20 @@ impl<T: Owned> MessageQueue<T> { } pub fn push(&mut self, value: T) { - let value = Cell(value); - self.queue.with(|q| q.push(value.take()) ); + unsafe { + let value = Cell(value); + self.queue.with(|q| q.push(value.take()) ); + } } pub fn pop(&mut self) -> Option<T> { - do self.queue.with |q| { - if !q.is_empty() { - Some(q.shift()) - } else { - None + unsafe { + do self.queue.with |q| { + if !q.is_empty() { + Some(q.shift()) + } else { + None + } } } } diff --git a/src/libstd/rt/work_queue.rs b/src/libstd/rt/work_queue.rs index e9eb663392b..4671a45aaea 100644 --- a/src/libstd/rt/work_queue.rs +++ b/src/libstd/rt/work_queue.rs @@ -29,32 +29,40 @@ pub impl<T: Owned> WorkQueue<T> { } fn push(&mut self, value: T) { - let value = Cell(value); - self.queue.with(|q| q.unshift(value.take()) ); + unsafe { + let value = Cell(value); + self.queue.with(|q| q.unshift(value.take()) ); + } } fn pop(&mut self) -> Option<T> { - do self.queue.with |q| { - if !q.is_empty() { - Some(q.shift()) - } else { - None + unsafe { + do self.queue.with |q| { + if !q.is_empty() { + Some(q.shift()) + } else { + None + } } } } fn steal(&mut self) -> Option<T> { - do self.queue.with |q| { - if !q.is_empty() { - Some(q.pop()) - } else { - None + unsafe { + do self.queue.with |q| { + if !q.is_empty() { + Some(q.pop()) + } else { + None + } } } } fn is_empty(&self) -> bool { - self.queue.with_imm(|q| q.is_empty() ) + unsafe { + self.queue.with_imm(|q| q.is_empty() ) + } } } diff --git a/src/libstd/task/spawn.rs b/src/libstd/task/spawn.rs index 5941221821a..56b1fb43ff1 100644 --- a/src/libstd/task/spawn.rs +++ b/src/libstd/task/spawn.rs @@ -159,13 +159,17 @@ struct AncestorList(Option<Exclusive<AncestorNode>>); // Accessors for taskgroup arcs and ancestor arcs that wrap the unsafety. #[inline(always)] fn access_group<U>(x: &TaskGroupArc, blk: &fn(TaskGroupInner) -> U) -> U { - x.with(blk) + unsafe { + x.with(blk) + } } #[inline(always)] fn access_ancestors<U>(x: &Exclusive<AncestorNode>, blk: &fn(x: &mut AncestorNode) -> U) -> U { - x.with(blk) + unsafe { + x.with(blk) + } } // Iterates over an ancestor list. |
