Remove all external requirements of @ from TLS

Closes #6004
This commit is contained in:
Alex Crichton 2013-07-11 00:35:43 -07:00
parent 11c63eaad2
commit f9bf69d253
12 changed files with 23 additions and 23 deletions

View file

@ -76,7 +76,7 @@ pub unsafe fn complete(cb: CompletionCb) {
extern fn callback(line: *c_char, completions: *()) { extern fn callback(line: *c_char, completions: *()) {
unsafe { unsafe {
let cb = *local_data::get(complete_key) let cb = *local_data::get(complete_key, |k| k.map(|&k| *k))
.get(); .get();
do cb(str::raw::from_c_str(line)) |suggestion| { do cb(str::raw::from_c_str(line)) |suggestion| {

View file

@ -1204,7 +1204,7 @@ mod big_tests {
#[unsafe_destructor] #[unsafe_destructor]
impl<'self> Drop for LVal<'self> { impl<'self> Drop for LVal<'self> {
fn drop(&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 { match x {
Some(@y) => { Some(@y) => {
unsafe { unsafe {

View file

@ -92,7 +92,7 @@ fn task_local_insn_key(_v: @~[&'static str]) {}
pub fn with_insn_ctxt(blk: &fn(&[&'static str])) { pub fn with_insn_ctxt(blk: &fn(&[&'static str])) {
unsafe { 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() { if opt.is_some() {
blk(*opt.unwrap()); blk(*opt.unwrap());
} }

View file

@ -241,7 +241,7 @@ impl Drop for CrateContext {
fn task_local_llcx_key(_v: @ContextRef) {} fn task_local_llcx_key(_v: @ContextRef) {}
pub fn task_llcx() -> 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!") *opt.expect("task-local LLVMContextRef wasn't ever set!")
} }

View file

@ -144,7 +144,7 @@ impl Program {
let key = ::std::sys::Closure{ code: %? as *(), let key = ::std::sys::Closure{ code: %? as *(),
env: ::std::ptr::null() }; env: ::std::ptr::null() };
let key = ::std::cast::transmute(key); 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)); };\n", key.code as uint));
// Using this __tls_map handle, deserialize each variable binding that // Using this __tls_map handle, deserialize each variable binding that

View file

@ -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> { pub fn trap(&'self self, h: &'self fn(T) -> U) -> Trap<'self, T, U> {
unsafe { unsafe {
let p : *RustClosure = ::cast::transmute(&h); 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 }; let h = @Handler { handle: *p, prev: prev };
Trap { cond: self, handler: h } Trap { cond: self, handler: h }
} }

View file

@ -83,16 +83,16 @@ pub unsafe fn pop<T: 'static>(key: Key<T>) -> Option<T> {
* table until explicitly removed. * table until explicitly removed.
*/ */
#[cfg(stage0)] #[cfg(stage0)]
pub unsafe fn get<T: 'static>(key: Key<@T>) -> Option<@T> { pub unsafe fn get<T: 'static, U>(key: Key<@T>, f: &fn(Option<&@T>) -> U) -> U {
local_get(Handle::new(), key, |loc| loc.map(|&x| *x)) local_get(Handle::new(), key, f)
} }
/** /**
* Retrieve a task-local data value. It will also be kept alive in the * Retrieve a task-local data value. It will also be kept alive in the
* table until explicitly removed. * table until explicitly removed.
*/ */
#[cfg(not(stage0))] #[cfg(not(stage0))]
pub unsafe fn get<T: 'static>(key: Key<@T>) -> Option<@T> { pub unsafe fn get<T: 'static, U>(key: Key<T>, f: &fn(Option<&T>) -> U) -> U {
local_get(Handle::new(), key, |loc| loc.map(|&x| *x)) local_get(Handle::new(), key, f)
} }
/** /**
* Store a value in task-local data. If this key already has a value, * 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"); set(my_key, @~"parent data");
do task::spawn { do task::spawn {
// TLS shouldn't carry over. // 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"); set(my_key, @~"child data");
assert!(*(get(my_key).get()) == assert!(*(get(my_key, |k| k.map(|&k| *k)).get()) ==
~"child data"); ~"child data");
// should be cleaned up for us // should be cleaned up for us
} }
// Must work multiple times // Must work multiple times
assert!(*(get(my_key).get()) == ~"parent data"); assert!(*(get(my_key, |k| k.map(|&k| *k)).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).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) { } fn my_key(_x: @~str) { }
set(my_key, @~"first data"); set(my_key, @~"first data");
set(my_key, @~"next data"); // Shouldn't leak. 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 { unsafe {
fn my_key(_x: @~str) { } fn my_key(_x: @~str) { }
set(my_key, @~"weasel"); 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. // Pop must remove the data from the map.
assert!(pop(my_key).is_none()); assert!(pop(my_key).is_none());
} }

View file

@ -1230,7 +1230,7 @@ fn overridden_arg_key(_v: @OverriddenArgs) {}
/// `os::set_args` function. /// `os::set_args` function.
pub fn args() -> ~[~str] { pub fn args() -> ~[~str] {
unsafe { unsafe {
match local_data::get(overridden_arg_key) { match local_data::get(overridden_arg_key, |k| k.map(|&k| *k)) {
None => real_args(), None => real_args(),
Some(args) => copy args.val Some(args) => copy args.val
} }

View file

@ -850,7 +850,7 @@ fn tls_rng_state(_v: @@mut IsaacRng) {}
pub fn task_rng() -> @mut IsaacRng { pub fn task_rng() -> @mut IsaacRng {
let r : Option<@@mut IsaacRng>; let r : Option<@@mut IsaacRng>;
unsafe { unsafe {
r = local_data::get(tls_rng_state); r = local_data::get(tls_rng_state, |k| k.map(|&k| *k));
} }
match r { match r {
None => { None => {

View file

@ -172,10 +172,10 @@ mod test {
unsafe { unsafe {
fn key(_x: @~str) { } fn key(_x: @~str) { }
local_data::set(key, @~"data"); 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) { } fn key2(_x: @~str) { }
local_data::set(key2, @~"data"); local_data::set(key2, @~"data");
assert!(*local_data::get(key2).get() == ~"data"); assert!(*local_data::get(key2, |k| k.map(|&k| *k)).get() == ~"data");
} }
} }
} }

View file

@ -698,7 +698,7 @@ pub fn get_sctable() -> @mut SCTable {
let sctable_key = (cast::transmute::<(uint, uint), let sctable_key = (cast::transmute::<(uint, uint),
&fn:Copy(v: @@mut SCTable)>( &fn:Copy(v: @@mut SCTable)>(
(-4 as uint, 0u))); (-4 as uint, 0u)));
match local_data::get(sctable_key) { match local_data::get(sctable_key, |k| k.map(|&k| *k)) {
None => { None => {
let new_table = @@mut new_sctable_internal(); let new_table = @@mut new_sctable_internal();
local_data::set(sctable_key,new_table); local_data::set(sctable_key,new_table);

View file

@ -490,7 +490,7 @@ pub fn get_ident_interner() -> @ident_interner {
(cast::transmute::<(uint, uint), (cast::transmute::<(uint, uint),
&fn:Copy(v: @@::parse::token::ident_interner)>( &fn:Copy(v: @@::parse::token::ident_interner)>(
(-3 as uint, 0u))); (-3 as uint, 0u)));
match local_data::get(key) { match local_data::get(key, |k| k.map(|&k| *k)) {
Some(interner) => *interner, Some(interner) => *interner,
None => { None => {
let interner = mk_fresh_ident_interner(); let interner = mk_fresh_ident_interner();