Repository: PistonDevelopers/glfw-rs (language: rust)

Issue:
`local_data_key!` not defined during build
When building, the following error comes up:

```
/home/james/.cargo/git/checkouts/glfw-rs-66a8b4b1793a8461/master/src/callbacks.rs:30:9: 
30:23 error: macro undefined: 'local_data_key!'
/home/james/.cargo/git/checkouts/glfw-rs-66a8b4b1793a8461/master/src/callbacks.rs:30
    local_data_key!(CALLBACK_KEY: Box<Object<Args> + 'static>)
```

Output from `rustc --version`:

```
rustc 0.13.0-nightly (eedfc0779 2014-11-25 22:36:59 +0000)
```



Discussion / hints:
Fixing now.

cc. @Ms2ger 

It's been renamed to `thread_local!` right?


Fix patch:
diff --git a/src/callbacks.rs b/src/callbacks.rs
index 9a4c41d5..f7cf3d0c 100644
--- a/src/callbacks.rs
+++ b/src/callbacks.rs
@@ -27,7 +27,7 @@ macro_rules! callback(
         let ext_set = $ext_set:expr;
         fn callback($($ext_arg:ident: $ext_arg_ty:ty),*) $call:expr
     ) => (
-        local_data_key!(CALLBACK_KEY: Box<Object<Args> + 'static>)
+        thread_local!(static CALLBACK_KEY: RefCell<Option<Box<Object<Args> + 'static>>> = RefCell::new(None))
 
         type Args = ($($arg_ty),*,);
 
@@ -42,26 +42,34 @@ macro_rules! callback(
         }
 
         pub fn set<UserData: 'static>(f: ::$Callback<UserData>) {
-            CALLBACK_KEY.replace(Some(box f as Box<Object<Args> + 'static>));
+            let mut boxed_cb = Some(box f as Box<Object<Args> + 'static>);
+            CALLBACK_KEY.with(|cb| {
+                *cb.borrow_mut() = boxed_cb.take();
+            });
             ($ext_set)(Some(callback));
         }
 
         pub fn unset() {
-            CALLBACK_KEY.replace(None);
+            CALLBACK_KEY.with(|cb| {
+                *cb.borrow_mut() = None;
+            });
             ($ext_set)(None);
         }
 
         extern "C" fn callback($($ext_arg: $ext_arg_ty),*) {
-            match CALLBACK_KEY.get() {
-                Some(cb) => unsafe { cb.call($call) },
-                _ => {}
-            }
+            CALLBACK_KEY.with(|cb| {
+                match *cb.borrow() {
+                    Some(ref cb) => unsafe { cb.call($call) },
+                    _ => {}
+                }
+            })
         }
     )
 )
 
 pub mod error {
     use libc::{c_int, c_char};
+    use std::cell::RefCell;
     use std::mem;
     use std::string;
 
@@ -78,6 +86,7 @@ pub mod error {
 
 pub mod monitor {
     use libc::{c_int};
+    use std::cell::RefCell;
     use std::mem;
     use std::kinds::marker;
 
diff --git a/src/lib.rs b/src/lib.rs
index 0f1f7ded..dbaeafde 100644
--- a/src/lib.rs
+++ b/src/lib.rs
@@ -68,7 +68,6 @@
 // TODO: Document differences between GLFW and glfw-rs
 
 extern crate semver;
-extern crate sync;
 extern crate libc;
 #[phase(plugin, link)]
 extern crate log;
@@ -392,7 +391,7 @@ pub enum InitError {
 /// - If an initialization error occured within the GLFW library
 ///   `Err(InternalInitError)` will be returned.
 pub fn init<UserData: 'static>(mut callback: Option<ErrorCallback<UserData>>) -> Result<Glfw, InitError> {
-    use sync::one::{Once, ONCE_INIT};
+    use std::sync::{Once, ONCE_INIT};
     static mut INIT: Once = ONCE_INIT;
     let mut result = Err(InitError::AlreadyInitialized);
     unsafe {


Test patch: