about summary refs log tree commit diff
path: root/src/libextra
diff options
context:
space:
mode:
authorbors <bors@rust-lang.org>2013-07-14 10:19:21 -0700
committerbors <bors@rust-lang.org>2013-07-14 10:19:21 -0700
commit1c35ab322ff2f26962a3550fffc2fa4154224b64 (patch)
treed95eb9acc27f980f2365330b3aa9566e8eec2010 /src/libextra
parent66e2857253ff9bc8ce299398ad5bb346d64e3fc3 (diff)
parent9fd2ac7428afa4f414f32b8b4876ca817ee85f16 (diff)
downloadrust-1c35ab322ff2f26962a3550fffc2fa4154224b64.tar.gz
rust-1c35ab322ff2f26962a3550fffc2fa4154224b64.zip
auto merge of #7751 : alexcrichton/rust/finish-tls, r=pcwalton
This changes the interface to `get`, and it also changes the keys to be static slices instead of static functions.

This allows the removal of the `unsafe` interface because while functions can monomorphize from different types to the same actual function, static slices cannot do this.

From at least what I can tell, we don't need to worry about LLVM coalescing these addresses. If we ever use the `unnamed_addr` it looks like there's cause for worry, but there doesn't appear to be any coalescing atm.
Diffstat (limited to 'src/libextra')
-rw-r--r--src/libextra/rl.rs26
-rw-r--r--src/libextra/sort.rs35
2 files changed, 15 insertions, 46 deletions
diff --git a/src/libextra/rl.rs b/src/libextra/rl.rs
index c1eeb5005b2..59801c945b6 100644
--- a/src/libextra/rl.rs
+++ b/src/libextra/rl.rs
@@ -66,24 +66,28 @@ pub unsafe fn read(prompt: &str) -> Option<~str> {
     }
 }
 
-pub type CompletionCb<'self> = @fn(~str, &'self fn(~str));
+pub type CompletionCb = @fn(~str, @fn(~str));
 
-fn complete_key(_v: @CompletionCb) {}
+#[cfg(not(stage0))]
+static complete_key: local_data::Key<@CompletionCb> = &local_data::Key;
+#[cfg(stage0)]
+fn complete_key(_: @CompletionCb) {}
 
 /// Bind to the main completion callback
 pub unsafe fn complete(cb: CompletionCb) {
-    local_data::set(complete_key, @(cb));
+    local_data::set(complete_key, @cb);
 
     extern fn callback(line: *c_char, completions: *()) {
-        unsafe {
-            let cb = *local_data::get(complete_key, |k| k.map(|&k| *k))
-                .get();
-
-            do cb(str::raw::from_c_str(line)) |suggestion| {
-                do str::as_c_str(suggestion) |buf| {
-                    rustrt::linenoiseAddCompletion(completions, buf);
+        do local_data::get(complete_key) |cb| {
+            let cb = **cb.unwrap();
+
+            unsafe {
+                do cb(str::raw::from_c_str(line)) |suggestion| {
+                    do str::as_c_str(suggestion) |buf| {
+                        rustrt::linenoiseAddCompletion(completions, buf);
+                    }
                 }
-            }
+}
         }
     }
 
diff --git a/src/libextra/sort.rs b/src/libextra/sort.rs
index d4d6162a919..db4ad43e41d 100644
--- a/src/libextra/sort.rs
+++ b/src/libextra/sort.rs
@@ -1195,39 +1195,4 @@ mod big_tests {
             isSorted(arr);
         }
     }
-
-    struct LVal<'self> {
-        val: uint,
-        key: &'self fn:Copy(@uint),
-    }
-
-    #[unsafe_destructor]
-    impl<'self> Drop for LVal<'self> {
-        fn drop(&self) {
-            let x = unsafe { local_data::get(self.key, |k| k.map(|&k| *k)) };
-            match x {
-                Some(@y) => {
-                    unsafe {
-                        local_data::set(self.key, @(y+1));
-                    }
-                }
-                _ => fail!("Expected key to work"),
-            }
-        }
-    }
-
-    impl<'self> Ord for LVal<'self> {
-        fn lt<'a>(&self, other: &'a LVal<'self>) -> bool {
-            (*self).val < other.val
-        }
-        fn le<'a>(&self, other: &'a LVal<'self>) -> bool {
-            (*self).val <= other.val
-        }
-        fn gt<'a>(&self, other: &'a LVal<'self>) -> bool {
-            (*self).val > other.val
-        }
-        fn ge<'a>(&self, other: &'a LVal<'self>) -> bool {
-            (*self).val >= other.val
-        }
-    }
 }