diff --git a/src/libstd/sys/unix/weak.rs b/src/libstd/sys/unix/weak.rs index d0242ca7422..b60e241f10c 100644 --- a/src/libstd/sys/unix/weak.rs +++ b/src/libstd/sys/unix/weak.rs @@ -18,7 +18,7 @@ use libc; -use ffi::CString; +use ffi::CStr; use marker; use mem; use sync::atomic::{AtomicUsize, Ordering}; @@ -26,7 +26,7 @@ macro_rules! weak { (fn $name:ident($($t:ty),*) -> $ret:ty) => ( static $name: ::sys::weak::Weak $ret> = - ::sys::weak::Weak::new(stringify!($name)); + ::sys::weak::Weak::new(concat!(stringify!($name), '\0')); ) } @@ -45,23 +45,22 @@ pub const fn new(name: &'static str) -> Weak { } } - pub fn get(&self) -> Option<&F> { + pub fn get(&self) -> Option { assert_eq!(mem::size_of::(), mem::size_of::()); unsafe { if self.addr.load(Ordering::SeqCst) == 1 { self.addr.store(fetch(self.name), Ordering::SeqCst); } - if self.addr.load(Ordering::SeqCst) == 0 { - None - } else { - mem::transmute::<&AtomicUsize, Option<&F>>(&self.addr) + match self.addr.load(Ordering::SeqCst) { + 0 => None, + addr => Some(mem::transmute_copy::(&addr)), } } } } unsafe fn fetch(name: &str) -> usize { - let name = match CString::new(name) { + let name = match CStr::from_bytes_with_nul(name.as_bytes()) { Ok(cstr) => cstr, Err(..) => return 0, };