about summary refs log tree commit diff
path: root/src/libstd
diff options
context:
space:
mode:
authorAlex Crichton <alex@alexcrichton.com>2013-07-11 00:35:43 -0700
committerAlex Crichton <alex@alexcrichton.com>2013-07-11 00:37:13 -0700
commitf9bf69d253e43f9caf279953876d44f6219e71de (patch)
tree77f741ef9093b6f6b4e865cb277dffaa51fdda7c /src/libstd
parent11c63eaad2311bbeea67ec9a9300686dbe400e23 (diff)
downloadrust-f9bf69d253e43f9caf279953876d44f6219e71de.tar.gz
rust-f9bf69d253e43f9caf279953876d44f6219e71de.zip
Remove all external requirements of `@` from TLS
Closes #6004
Diffstat (limited to 'src/libstd')
-rw-r--r--src/libstd/condition.rs2
-rw-r--r--src/libstd/local_data.rs22
-rw-r--r--src/libstd/os.rs2
-rw-r--r--src/libstd/rand.rs2
-rw-r--r--src/libstd/rt/task.rs4
5 files changed, 16 insertions, 16 deletions
diff --git a/src/libstd/condition.rs b/src/libstd/condition.rs
index 10900b7172a..d6d09527f83 100644
--- a/src/libstd/condition.rs
+++ b/src/libstd/condition.rs
@@ -32,7 +32,7 @@ impl<'self, T, U> Condition<'self, T, U> {
     pub fn trap(&'self self, h: &'self fn(T) -> U) -> Trap<'self, T, U> {
         unsafe {
             let p : *RustClosure = ::cast::transmute(&h);
-            let prev = local_data::get(self.key);
+            let prev = local_data::get(self.key, |k| k.map(|&x| *x));
             let h = @Handler { handle: *p, prev: prev };
             Trap { cond: self, handler: h }
         }
diff --git a/src/libstd/local_data.rs b/src/libstd/local_data.rs
index 711ed15fa9d..fa981d273e2 100644
--- a/src/libstd/local_data.rs
+++ b/src/libstd/local_data.rs
@@ -83,16 +83,16 @@ pub unsafe fn pop<T: 'static>(key: Key<T>) -> Option<T> {
  * table until explicitly removed.
  */
 #[cfg(stage0)]
-pub unsafe fn get<T: 'static>(key: Key<@T>) -> Option<@T> {
-    local_get(Handle::new(), key, |loc| loc.map(|&x| *x))
+pub unsafe fn get<T: 'static, U>(key: Key<@T>, f: &fn(Option<&@T>) -> U) -> U {
+    local_get(Handle::new(), key, f)
 }
 /**
  * Retrieve a task-local data value. It will also be kept alive in the
  * table until explicitly removed.
  */
 #[cfg(not(stage0))]
-pub unsafe fn get<T: 'static>(key: Key<@T>) -> Option<@T> {
-    local_get(Handle::new(), key, |loc| loc.map(|&x| *x))
+pub unsafe fn get<T: 'static, U>(key: Key<T>, f: &fn(Option<&T>) -> U) -> U {
+    local_get(Handle::new(), key, f)
 }
 /**
  * Store a value in task-local data. If this key already has a value,
@@ -142,16 +142,16 @@ fn test_tls_multitask() {
         set(my_key, @~"parent data");
         do task::spawn {
             // TLS shouldn't carry over.
-            assert!(get(my_key).is_none());
+            assert!(get(my_key, |k| k.map(|&k| *k)).is_none());
             set(my_key, @~"child data");
-            assert!(*(get(my_key).get()) ==
+            assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) ==
                     ~"child data");
             // should be cleaned up for us
         }
         // Must work multiple times
-        assert!(*(get(my_key).get()) == ~"parent data");
-        assert!(*(get(my_key).get()) == ~"parent data");
-        assert!(*(get(my_key).get()) == ~"parent data");
+        assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) == ~"parent data");
+        assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) == ~"parent data");
+        assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) == ~"parent data");
     }
 }
 
@@ -161,7 +161,7 @@ fn test_tls_overwrite() {
         fn my_key(_x: @~str) { }
         set(my_key, @~"first data");
         set(my_key, @~"next data"); // Shouldn't leak.
-        assert!(*(get(my_key).get()) == ~"next data");
+        assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) == ~"next data");
     }
 }
 
@@ -170,7 +170,7 @@ fn test_tls_pop() {
     unsafe {
         fn my_key(_x: @~str) { }
         set(my_key, @~"weasel");
-        assert!(*(pop(my_key).get()) == ~"weasel");
+        assert!(*(pop(my_key, |k| k.map(|&k| *k)).get()) == ~"weasel");
         // Pop must remove the data from the map.
         assert!(pop(my_key).is_none());
     }
diff --git a/src/libstd/os.rs b/src/libstd/os.rs
index 3c8294bdfd1..2e511f91b5a 100644
--- a/src/libstd/os.rs
+++ b/src/libstd/os.rs
@@ -1230,7 +1230,7 @@ fn overridden_arg_key(_v: @OverriddenArgs) {}
 /// `os::set_args` function.
 pub fn args() -> ~[~str] {
     unsafe {
-        match local_data::get(overridden_arg_key) {
+        match local_data::get(overridden_arg_key, |k| k.map(|&k| *k)) {
             None => real_args(),
             Some(args) => copy args.val
         }
diff --git a/src/libstd/rand.rs b/src/libstd/rand.rs
index 860a69bd1e0..bc80bd9dc6a 100644
--- a/src/libstd/rand.rs
+++ b/src/libstd/rand.rs
@@ -850,7 +850,7 @@ fn tls_rng_state(_v: @@mut IsaacRng) {}
 pub fn task_rng() -> @mut IsaacRng {
     let r : Option<@@mut IsaacRng>;
     unsafe {
-        r = local_data::get(tls_rng_state);
+        r = local_data::get(tls_rng_state, |k| k.map(|&k| *k));
     }
     match r {
         None => {
diff --git a/src/libstd/rt/task.rs b/src/libstd/rt/task.rs
index 55e633e8496..2100e71e9fd 100644
--- a/src/libstd/rt/task.rs
+++ b/src/libstd/rt/task.rs
@@ -172,10 +172,10 @@ mod test {
             unsafe {
                 fn key(_x: @~str) { }
                 local_data::set(key, @~"data");
-                assert!(*local_data::get(key).get() == ~"data");
+                assert!(*local_data::get(key, |k| k.map(|&k| *k)).get() == ~"data");
                 fn key2(_x: @~str) { }
                 local_data::set(key2, @~"data");
-                assert!(*local_data::get(key2).get() == ~"data");
+                assert!(*local_data::get(key2, |k| k.map(|&k| *k)).get() == ~"data");
             }
         }
     }