If we add a terminating NUL to the name in the `weak!` macro, then
`fetch()` can use `CStr::from_bytes_with_nul()` instead of `CString`.
use libc;
-use ffi::CString;
+use ffi::CStr;
use marker;
use mem;
use sync::atomic::{AtomicUsize, Ordering};
macro_rules! weak {
(fn $name:ident($($t:ty),*) -> $ret:ty) => (
static $name: ::sys::weak::Weak<unsafe extern fn($($t),*) -> $ret> =
- ::sys::weak::Weak::new(stringify!($name));
+ ::sys::weak::Weak::new(concat!(stringify!($name), '\0'));
)
}
}
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,
};