提交 f9bf69d2 编写于 作者: A Alex Crichton

Remove all external requirements of `@` from TLS

Closes #6004
上级 11c63eaa
......@@ -76,7 +76,7 @@ pub unsafe fn complete(cb: CompletionCb) {
extern fn callback(line: *c_char, completions: *()) {
unsafe {
let cb = *local_data::get(complete_key)
let cb = *local_data::get(complete_key, |k| k.map(|&k| *k))
.get();
do cb(str::raw::from_c_str(line)) |suggestion| {
......
......@@ -1204,7 +1204,7 @@ struct LVal<'self> {
#[unsafe_destructor]
impl<'self> Drop for LVal<'self> {
fn drop(&self) {
let x = unsafe { local_data::get(self.key) };
let x = unsafe { local_data::get(self.key, |k| k.map(|&k| *k)) };
match x {
Some(@y) => {
unsafe {
......
......@@ -92,7 +92,7 @@ fn task_local_insn_key(_v: @~[&'static str]) {}
pub fn with_insn_ctxt(blk: &fn(&[&'static str])) {
unsafe {
let opt = local_data::get(task_local_insn_key);
let opt = local_data::get(task_local_insn_key, |k| k.map(|&k| *k));
if opt.is_some() {
blk(*opt.unwrap());
}
......
......@@ -241,7 +241,7 @@ fn drop(&self) {
fn task_local_llcx_key(_v: @ContextRef) {}
pub fn task_llcx() -> ContextRef {
let opt = unsafe { local_data::get(task_local_llcx_key) };
let opt = unsafe { local_data::get(task_local_llcx_key, |k| k.map(|&k| *k)) };
*opt.expect("task-local LLVMContextRef wasn't ever set!")
}
......
......@@ -144,7 +144,7 @@ fn main() {
let key = ::std::sys::Closure{ code: %? as *(),
env: ::std::ptr::null() };
let key = ::std::cast::transmute(key);
*::std::local_data::get(key).unwrap()
*::std::local_data::get(key, |k| k.map(|&x| *x)).unwrap()
};\n", key.code as uint));
// Using this __tls_map handle, deserialize each variable binding that
......
......@@ -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 }
}
......
......@@ -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 my_key(_x: @~str) { }
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());
}
......
......@@ -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
}
......
......@@ -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 => {
......
......@@ -172,10 +172,10 @@ fn tls() {
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");
}
}
}
......
......@@ -698,7 +698,7 @@ pub fn get_sctable() -> @mut SCTable {
let sctable_key = (cast::transmute::<(uint, uint),
&fn:Copy(v: @@mut SCTable)>(
(-4 as uint, 0u)));
match local_data::get(sctable_key) {
match local_data::get(sctable_key, |k| k.map(|&k| *k)) {
None => {
let new_table = @@mut new_sctable_internal();
local_data::set(sctable_key,new_table);
......
......@@ -490,7 +490,7 @@ pub fn get_ident_interner() -> @ident_interner {
(cast::transmute::<(uint, uint),
&fn:Copy(v: @@::parse::token::ident_interner)>(
(-3 as uint, 0u)));
match local_data::get(key) {
match local_data::get(key, |k| k.map(|&k| *k)) {
Some(interner) => *interner,
None => {
let interner = mk_fresh_ident_interner();
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册