about summary refs log tree commit diff
path: root/src/libstd/sys_common
diff options
context:
space:
mode:
authorMark Rousskov <mark.simulacrum@gmail.com>2019-12-22 17:42:04 -0500
committerMark Rousskov <mark.simulacrum@gmail.com>2019-12-22 17:42:47 -0500
commita06baa56b95674fc626b3c3fd680d6a65357fe60 (patch)
treecd9d867c2ca3cff5c1d6b3bd73377c44649fb075 /src/libstd/sys_common
parent8eb7c58dbb7b32701af113bc58722d0d1fefb1eb (diff)
downloadrust-a06baa56b95674fc626b3c3fd680d6a65357fe60.tar.gz
rust-a06baa56b95674fc626b3c3fd680d6a65357fe60.zip
Format the world
Diffstat (limited to 'src/libstd/sys_common')
-rw-r--r--src/libstd/sys_common/at_exit_imp.rs4
-rw-r--r--src/libstd/sys_common/backtrace.rs17
-rw-r--r--src/libstd/sys_common/condvar.rs28
-rw-r--r--src/libstd/sys_common/mod.rs35
-rw-r--r--src/libstd/sys_common/mutex.rs32
-rw-r--r--src/libstd/sys_common/remutex.rs31
-rw-r--r--src/libstd/sys_common/rwlock.rs32
-rw-r--r--src/libstd/sys_common/thread_local.rs35
8 files changed, 126 insertions, 88 deletions
diff --git a/src/libstd/sys_common/at_exit_imp.rs b/src/libstd/sys_common/at_exit_imp.rs
index cdb72ee872e..6b799db856e 100644
--- a/src/libstd/sys_common/at_exit_imp.rs
+++ b/src/libstd/sys_common/at_exit_imp.rs
@@ -2,8 +2,8 @@
 //!
 //! Documentation can be found on the `rt::at_exit` function.
 
-use crate::ptr;
 use crate::mem;
+use crate::ptr;
 use crate::sys_common::mutex::Mutex;
 
 type Queue = Vec<Box<dyn FnOnce()>>;
@@ -31,7 +31,7 @@ unsafe fn init() -> bool {
         QUEUE = Box::into_raw(state);
     } else if QUEUE == DONE {
         // can't re-init after a cleanup
-        return false
+        return false;
     }
 
     true
diff --git a/src/libstd/sys_common/backtrace.rs b/src/libstd/sys_common/backtrace.rs
index d7296b43fbe..191add2c31b 100644
--- a/src/libstd/sys_common/backtrace.rs
+++ b/src/libstd/sys_common/backtrace.rs
@@ -1,10 +1,9 @@
+use crate::borrow::Cow;
 /// Common code for printing the backtrace in the same way across the different
 /// supported platforms.
-
 use crate::env;
 use crate::fmt;
 use crate::io;
-use crate::borrow::Cow;
 use crate::io::prelude::*;
 use crate::path::{self, Path, PathBuf};
 use crate::sync::atomic::{self, Ordering};
@@ -57,9 +56,7 @@ unsafe fn _print(w: &mut dyn Write, format: PrintFmt) -> io::Result<()> {
     }
     impl fmt::Display for DisplayBacktrace {
         fn fmt(&self, fmt: &mut fmt::Formatter<'_>) -> fmt::Result {
-            unsafe {
-                _print_fmt(fmt, self.format)
-            }
+            unsafe { _print_fmt(fmt, self.format) }
         }
     }
     write!(w, "{}", DisplayBacktrace { format })
@@ -68,11 +65,7 @@ unsafe fn _print(w: &mut dyn Write, format: PrintFmt) -> io::Result<()> {
 unsafe fn _print_fmt(fmt: &mut fmt::Formatter<'_>, print_fmt: PrintFmt) -> fmt::Result {
     // Always 'fail' to get the cwd when running under Miri -
     // this allows Miri to display backtraces in isolation mode
-    let cwd = if !cfg!(miri) {
-        env::current_dir().ok()
-    } else {
-        None
-    };
+    let cwd = if !cfg!(miri) { env::current_dir().ok() } else { None };
 
     let mut print_path = move |fmt: &mut fmt::Formatter<'_>, bows: BytesOrWideString<'_>| {
         output_filename(fmt, bows, print_fmt, cwd.as_ref())
@@ -206,9 +199,7 @@ pub fn output_filename(
             Cow::Owned(crate::ffi::OsString::from_wide(wide).into())
         }
         #[cfg(not(windows))]
-        BytesOrWideString::Wide(_wide) => {
-            Path::new("<unknown>").into()
-        }
+        BytesOrWideString::Wide(_wide) => Path::new("<unknown>").into(),
     };
     if print_fmt == PrintFmt::Short && file.is_absolute() {
         if let Some(cwd) = cwd {
diff --git a/src/libstd/sys_common/condvar.rs b/src/libstd/sys_common/condvar.rs
index fc59c8356f4..f9611bc6f7b 100644
--- a/src/libstd/sys_common/condvar.rs
+++ b/src/libstd/sys_common/condvar.rs
@@ -1,6 +1,6 @@
-use crate::time::Duration;
-use crate::sys_common::mutex::{self, Mutex};
 use crate::sys::condvar as imp;
+use crate::sys_common::mutex::{self, Mutex};
+use crate::time::Duration;
 
 /// An OS-based condition variable.
 ///
@@ -15,22 +15,30 @@ impl Condvar {
     ///
     /// Behavior is undefined if the condition variable is moved after it is
     /// first used with any of the functions below.
-    pub const fn new() -> Condvar { Condvar(imp::Condvar::new()) }
+    pub const fn new() -> Condvar {
+        Condvar(imp::Condvar::new())
+    }
 
     /// Prepares the condition variable for use.
     ///
     /// This should be called once the condition variable is at a stable memory
     /// address.
     #[inline]
-    pub unsafe fn init(&mut self) { self.0.init() }
+    pub unsafe fn init(&mut self) {
+        self.0.init()
+    }
 
     /// Signals one waiter on this condition variable to wake up.
     #[inline]
-    pub unsafe fn notify_one(&self) { self.0.notify_one() }
+    pub unsafe fn notify_one(&self) {
+        self.0.notify_one()
+    }
 
     /// Awakens all current waiters on this condition variable.
     #[inline]
-    pub unsafe fn notify_all(&self) { self.0.notify_all() }
+    pub unsafe fn notify_all(&self) {
+        self.0.notify_all()
+    }
 
     /// Waits for a signal on the specified mutex.
     ///
@@ -38,7 +46,9 @@ impl Condvar {
     /// Behavior is also undefined if more than one mutex is used concurrently
     /// on this condition variable.
     #[inline]
-    pub unsafe fn wait(&self, mutex: &Mutex) { self.0.wait(mutex::raw(mutex)) }
+    pub unsafe fn wait(&self, mutex: &Mutex) {
+        self.0.wait(mutex::raw(mutex))
+    }
 
     /// Waits for a signal on the specified mutex with a timeout duration
     /// specified by `dur` (a relative time into the future).
@@ -56,5 +66,7 @@ impl Condvar {
     /// Behavior is undefined if there are current or will be future users of
     /// this condition variable.
     #[inline]
-    pub unsafe fn destroy(&self) { self.0.destroy() }
+    pub unsafe fn destroy(&self) {
+        self.0.destroy()
+    }
 }
diff --git a/src/libstd/sys_common/mod.rs b/src/libstd/sys_common/mod.rs
index 8912aed9255..ca8c63d62a6 100644
--- a/src/libstd/sys_common/mod.rs
+++ b/src/libstd/sys_common/mod.rs
@@ -23,26 +23,32 @@ macro_rules! rtabort {
 }
 
 macro_rules! rtassert {
-    ($e:expr) => (if !$e {
-        rtabort!(concat!("assertion failed: ", stringify!($e)));
-    })
+    ($e:expr) => {
+        if !$e {
+            rtabort!(concat!("assertion failed: ", stringify!($e)));
+        }
+    };
 }
 
 #[allow(unused_macros)] // not used on all platforms
 macro_rules! rtunwrap {
-    ($ok:ident, $e:expr) => (match $e {
-        $ok(v) => v,
-        ref err => {
-            let err = err.as_ref().map(|_|()); // map Ok/Some which might not be Debug
-            rtabort!(concat!("unwrap failed: ", stringify!($e), " = {:?}"), err)
-        },
-    })
+    ($ok:ident, $e:expr) => {
+        match $e {
+            $ok(v) => v,
+            ref err => {
+                let err = err.as_ref().map(|_| ()); // map Ok/Some which might not be Debug
+                rtabort!(concat!("unwrap failed: ", stringify!($e), " = {:?}"), err)
+            }
+        }
+    };
 }
 
 pub mod alloc;
 pub mod at_exit_imp;
 pub mod backtrace;
+pub mod bytestring;
 pub mod condvar;
+pub mod fs;
 pub mod io;
 pub mod mutex;
 #[cfg(any(doc, // see `mod os`, docs are generated for multiple platforms
@@ -54,6 +60,7 @@ pub mod mutex;
           all(target_vendor = "fortanix", target_env = "sgx")))]
 pub mod os_str_bytes;
 pub mod poison;
+pub mod process;
 pub mod remutex;
 pub mod rwlock;
 pub mod thread;
@@ -61,9 +68,6 @@ pub mod thread_info;
 pub mod thread_local;
 pub mod util;
 pub mod wtf8;
-pub mod bytestring;
-pub mod process;
-pub mod fs;
 
 cfg_if::cfg_if! {
     if #[cfg(any(target_os = "cloudabi",
@@ -114,7 +118,7 @@ pub trait FromInner<Inner> {
 /// that the closure could not be registered, meaning that it is not scheduled
 /// to be run.
 pub fn at_exit<F: FnOnce() + Send + 'static>(f: F) -> Result<(), ()> {
-    if at_exit_imp::push(Box::new(f)) {Ok(())} else {Err(())}
+    if at_exit_imp::push(Box::new(f)) { Ok(()) } else { Err(()) }
 }
 
 /// One-time runtime cleanup.
@@ -142,6 +146,5 @@ pub fn mul_div_u64(value: u64, numer: u64, denom: u64) -> u64 {
 
 #[test]
 fn test_muldiv() {
-    assert_eq!(mul_div_u64( 1_000_000_000_001, 1_000_000_000, 1_000_000),
-               1_000_000_000_001_000);
+    assert_eq!(mul_div_u64(1_000_000_000_001, 1_000_000_000, 1_000_000), 1_000_000_000_001_000);
 }
diff --git a/src/libstd/sys_common/mutex.rs b/src/libstd/sys_common/mutex.rs
index 28d85949ffa..899fc6a7235 100644
--- a/src/libstd/sys_common/mutex.rs
+++ b/src/libstd/sys_common/mutex.rs
@@ -17,7 +17,9 @@ impl Mutex {
     /// Also, until `init` is called, behavior is undefined if this
     /// mutex is ever used reentrantly, i.e., `raw_lock` or `try_lock`
     /// are called by the thread currently holding the lock.
-    pub const fn new() -> Mutex { Mutex(imp::Mutex::new()) }
+    pub const fn new() -> Mutex {
+        Mutex(imp::Mutex::new())
+    }
 
     /// Prepare the mutex for use.
     ///
@@ -26,14 +28,18 @@ impl Mutex {
     /// Calling it in parallel with or after any operation (including another
     /// `init()`) is undefined behavior.
     #[inline]
-    pub unsafe fn init(&mut self) { self.0.init() }
+    pub unsafe fn init(&mut self) {
+        self.0.init()
+    }
 
     /// Locks the mutex blocking the current thread until it is available.
     ///
     /// Behavior is undefined if the mutex has been moved between this and any
     /// previous function call.
     #[inline]
-    pub unsafe fn raw_lock(&self) { self.0.lock() }
+    pub unsafe fn raw_lock(&self) {
+        self.0.lock()
+    }
 
     /// Calls raw_lock() and then returns an RAII guard to guarantee the mutex
     /// will be unlocked.
@@ -49,7 +55,9 @@ impl Mutex {
     /// Behavior is undefined if the mutex has been moved between this and any
     /// previous function call.
     #[inline]
-    pub unsafe fn try_lock(&self) -> bool { self.0.try_lock() }
+    pub unsafe fn try_lock(&self) -> bool {
+        self.0.try_lock()
+    }
 
     /// Unlocks the mutex.
     ///
@@ -59,18 +67,24 @@ impl Mutex {
     /// Consider switching from the pair of raw_lock() and raw_unlock() to
     /// lock() whenever possible.
     #[inline]
-    pub unsafe fn raw_unlock(&self) { self.0.unlock() }
+    pub unsafe fn raw_unlock(&self) {
+        self.0.unlock()
+    }
 
     /// Deallocates all resources associated with this mutex.
     ///
     /// Behavior is undefined if there are current or will be future users of
     /// this mutex.
     #[inline]
-    pub unsafe fn destroy(&self) { self.0.destroy() }
+    pub unsafe fn destroy(&self) {
+        self.0.destroy()
+    }
 }
 
 // not meant to be exported to the outside world, just the containing module
-pub fn raw(mutex: &Mutex) -> &imp::Mutex { &mutex.0 }
+pub fn raw(mutex: &Mutex) -> &imp::Mutex {
+    &mutex.0
+}
 
 #[must_use]
 /// A simple RAII utility for the above Mutex without the poisoning semantics.
@@ -79,6 +93,8 @@ pub struct MutexGuard<'a>(&'a imp::Mutex);
 impl Drop for MutexGuard<'_> {
     #[inline]
     fn drop(&mut self) {
-        unsafe { self.0.unlock(); }
+        unsafe {
+            self.0.unlock();
+        }
     }
 }
diff --git a/src/libstd/sys_common/remutex.rs b/src/libstd/sys_common/remutex.rs
index f08b13c4aa2..a1ad44a3666 100644
--- a/src/libstd/sys_common/remutex.rs
+++ b/src/libstd/sys_common/remutex.rs
@@ -1,9 +1,9 @@
 use crate::fmt;
 use crate::marker;
 use crate::ops::Deref;
-use crate::sys_common::poison::{self, TryLockError, TryLockResult, LockResult};
+use crate::panic::{RefUnwindSafe, UnwindSafe};
 use crate::sys::mutex as sys;
-use crate::panic::{UnwindSafe, RefUnwindSafe};
+use crate::sys_common::poison::{self, LockResult, TryLockError, TryLockResult};
 
 /// A re-entrant mutual exclusion
 ///
@@ -22,7 +22,6 @@ unsafe impl<T: Send> Sync for ReentrantMutex<T> {}
 impl<T> UnwindSafe for ReentrantMutex<T> {}
 impl<T> RefUnwindSafe for ReentrantMutex<T> {}
 
-
 /// An RAII implementation of a "scoped lock" of a mutex. When this structure is
 /// dropped (falls out of scope), the lock will be unlocked.
 ///
@@ -45,7 +44,6 @@ pub struct ReentrantMutexGuard<'a, T: 'a> {
 
 impl<T> !marker::Send for ReentrantMutexGuard<'_, T> {}
 
-
 impl<T> ReentrantMutex<T> {
     /// Creates a new reentrant mutex in an unlocked state.
     pub fn new(t: T) -> ReentrantMutex<T> {
@@ -113,7 +111,7 @@ impl<T: fmt::Debug + 'static> fmt::Debug for ReentrantMutex<T> {
             Ok(guard) => f.debug_struct("ReentrantMutex").field("data", &*guard).finish(),
             Err(TryLockError::Poisoned(err)) => {
                 f.debug_struct("ReentrantMutex").field("data", &**err.get_ref()).finish()
-            },
+            }
             Err(TryLockError::WouldBlock) => {
                 struct LockedPlaceholder;
                 impl fmt::Debug for LockedPlaceholder {
@@ -129,13 +127,10 @@ impl<T: fmt::Debug + 'static> fmt::Debug for ReentrantMutex<T> {
 }
 
 impl<'mutex, T> ReentrantMutexGuard<'mutex, T> {
-    fn new(lock: &'mutex ReentrantMutex<T>)
-            -> LockResult<ReentrantMutexGuard<'mutex, T>> {
-        poison::map_result(lock.poison.borrow(), |guard| {
-            ReentrantMutexGuard {
-                __lock: lock,
-                __poison: guard,
-            }
+    fn new(lock: &'mutex ReentrantMutex<T>) -> LockResult<ReentrantMutexGuard<'mutex, T>> {
+        poison::map_result(lock.poison.borrow(), |guard| ReentrantMutexGuard {
+            __lock: lock,
+            __poison: guard,
         })
     }
 }
@@ -158,12 +153,11 @@ impl<T> Drop for ReentrantMutexGuard<'_, T> {
     }
 }
 
-
 #[cfg(all(test, not(target_os = "emscripten")))]
 mod tests {
-    use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
     use crate::cell::RefCell;
     use crate::sync::Arc;
+    use crate::sys_common::remutex::{ReentrantMutex, ReentrantMutexGuard};
     use crate::thread;
 
     #[test]
@@ -209,7 +203,9 @@ mod tests {
         thread::spawn(move || {
             let lock = m2.try_lock();
             assert!(lock.is_err());
-        }).join().unwrap();
+        })
+        .join()
+        .unwrap();
         let _lock3 = m.try_lock().unwrap();
     }
 
@@ -224,14 +220,15 @@ mod tests {
     fn poison_works() {
         let m = Arc::new(ReentrantMutex::new(RefCell::new(0)));
         let mc = m.clone();
-        let result = thread::spawn(move ||{
+        let result = thread::spawn(move || {
             let lock = mc.lock().unwrap();
             *lock.borrow_mut() = 1;
             let lock2 = mc.lock().unwrap();
             *lock.borrow_mut() = 2;
             let _answer = Answer(lock2);
             panic!("What the answer to my lifetimes dilemma is?");
-        }).join();
+        })
+        .join();
         assert!(result.is_err());
         let r = m.lock().err().unwrap().into_inner();
         assert_eq!(*r.borrow(), 42);
diff --git a/src/libstd/sys_common/rwlock.rs b/src/libstd/sys_common/rwlock.rs
index 0b1a092de54..3705d641a1b 100644
--- a/src/libstd/sys_common/rwlock.rs
+++ b/src/libstd/sys_common/rwlock.rs
@@ -12,7 +12,9 @@ impl RWLock {
     ///
     /// Behavior is undefined if the reader-writer lock is moved after it is
     /// first used with any of the functions below.
-    pub const fn new() -> RWLock { RWLock(imp::RWLock::new()) }
+    pub const fn new() -> RWLock {
+        RWLock(imp::RWLock::new())
+    }
 
     /// Acquires shared access to the underlying lock, blocking the current
     /// thread to do so.
@@ -20,7 +22,9 @@ impl RWLock {
     /// Behavior is undefined if the rwlock has been moved between this and any
     /// previous method call.
     #[inline]
-    pub unsafe fn read(&self) { self.0.read() }
+    pub unsafe fn read(&self) {
+        self.0.read()
+    }
 
     /// Attempts to acquire shared access to this lock, returning whether it
     /// succeeded or not.
@@ -30,7 +34,9 @@ impl RWLock {
     /// Behavior is undefined if the rwlock has been moved between this and any
     /// previous method call.
     #[inline]
-    pub unsafe fn try_read(&self) -> bool { self.0.try_read() }
+    pub unsafe fn try_read(&self) -> bool {
+        self.0.try_read()
+    }
 
     /// Acquires write access to the underlying lock, blocking the current thread
     /// to do so.
@@ -38,7 +44,9 @@ impl RWLock {
     /// Behavior is undefined if the rwlock has been moved between this and any
     /// previous method call.
     #[inline]
-    pub unsafe fn write(&self) { self.0.write() }
+    pub unsafe fn write(&self) {
+        self.0.write()
+    }
 
     /// Attempts to acquire exclusive access to this lock, returning whether it
     /// succeeded or not.
@@ -48,25 +56,33 @@ impl RWLock {
     /// Behavior is undefined if the rwlock has been moved between this and any
     /// previous method call.
     #[inline]
-    pub unsafe fn try_write(&self) -> bool { self.0.try_write() }
+    pub unsafe fn try_write(&self) -> bool {
+        self.0.try_write()
+    }
 
     /// Unlocks previously acquired shared access to this lock.
     ///
     /// Behavior is undefined if the current thread does not have shared access.
     #[inline]
-    pub unsafe fn read_unlock(&self) { self.0.read_unlock() }
+    pub unsafe fn read_unlock(&self) {
+        self.0.read_unlock()
+    }
 
     /// Unlocks previously acquired exclusive access to this lock.
     ///
     /// Behavior is undefined if the current thread does not currently have
     /// exclusive access.
     #[inline]
-    pub unsafe fn write_unlock(&self) { self.0.write_unlock() }
+    pub unsafe fn write_unlock(&self) {
+        self.0.write_unlock()
+    }
 
     /// Destroys OS-related resources with this RWLock.
     ///
     /// Behavior is undefined if there are any currently active users of this
     /// lock.
     #[inline]
-    pub unsafe fn destroy(&self) { self.0.destroy() }
+    pub unsafe fn destroy(&self) {
+        self.0.destroy()
+    }
 }
diff --git a/src/libstd/sys_common/thread_local.rs b/src/libstd/sys_common/thread_local.rs
index 9596911fd48..756b8d044a2 100644
--- a/src/libstd/sys_common/thread_local.rs
+++ b/src/libstd/sys_common/thread_local.rs
@@ -81,7 +81,7 @@ pub struct StaticKey {
     ///
     /// See `Key::new` for information about when the destructor runs and how
     /// it runs.
-    dtor: Option<unsafe extern fn(*mut u8)>,
+    dtor: Option<unsafe extern "C" fn(*mut u8)>,
 }
 
 /// A type for a safely managed OS-based TLS slot.
@@ -115,11 +115,8 @@ pub struct Key {
 pub const INIT: StaticKey = StaticKey::new(None);
 
 impl StaticKey {
-    pub const fn new(dtor: Option<unsafe extern fn(*mut u8)>) -> StaticKey {
-        StaticKey {
-            key: atomic::AtomicUsize::new(0),
-            dtor,
-        }
+    pub const fn new(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> StaticKey {
+        StaticKey { key: atomic::AtomicUsize::new(0), dtor }
     }
 
     /// Gets the value associated with this TLS key
@@ -127,20 +124,24 @@ impl StaticKey {
     /// This will lazily allocate a TLS key from the OS if one has not already
     /// been allocated.
     #[inline]
-    pub unsafe fn get(&self) -> *mut u8 { imp::get(self.key()) }
+    pub unsafe fn get(&self) -> *mut u8 {
+        imp::get(self.key())
+    }
 
     /// Sets this TLS key to a new value.
     ///
     /// This will lazily allocate a TLS key from the OS if one has not already
     /// been allocated.
     #[inline]
-    pub unsafe fn set(&self, val: *mut u8) { imp::set(self.key(), val) }
+    pub unsafe fn set(&self, val: *mut u8) {
+        imp::set(self.key(), val)
+    }
 
     #[inline]
     unsafe fn key(&self) -> imp::Key {
         match self.key.load(Ordering::Relaxed) {
             0 => self.lazy_init() as imp::Key,
-            n => n as imp::Key
+            n => n as imp::Key,
         }
     }
 
@@ -161,7 +162,7 @@ impl StaticKey {
                 self.key.store(key, Ordering::SeqCst);
             }
             rtassert!(key != 0);
-            return key
+            return key;
         }
 
         // POSIX allows the key created here to be 0, but the compare_and_swap
@@ -186,7 +187,10 @@ impl StaticKey {
             // The CAS succeeded, so we've created the actual key
             0 => key as usize,
             // If someone beat us to the punch, use their key instead
-            n => { imp::destroy(key); n }
+            n => {
+                imp::destroy(key);
+                n
+            }
         }
     }
 }
@@ -204,7 +208,7 @@ impl Key {
     /// Note that the destructor will not be run when the `Key` goes out of
     /// scope.
     #[inline]
-    pub fn new(dtor: Option<unsafe extern fn(*mut u8)>) -> Key {
+    pub fn new(dtor: Option<unsafe extern "C" fn(*mut u8)>) -> Key {
         Key { key: unsafe { imp::create(dtor) } }
     }
 
@@ -229,8 +233,7 @@ impl Drop for Key {
     }
 }
 
-pub unsafe fn register_dtor_fallback(t: *mut u8,
-                                     dtor: unsafe extern fn(*mut u8)) {
+pub unsafe fn register_dtor_fallback(t: *mut u8, dtor: unsafe extern "C" fn(*mut u8)) {
     // The fallback implementation uses a vanilla OS-based TLS key to track
     // the list of destructors that need to be run for this thread. The key
     // then has its own destructor which runs all the other destructors.
@@ -242,7 +245,7 @@ pub unsafe fn register_dtor_fallback(t: *mut u8,
     // flagged for destruction.
 
     static DTORS: StaticKey = StaticKey::new(Some(run_dtors));
-    type List = Vec<(*mut u8, unsafe extern fn(*mut u8))>;
+    type List = Vec<(*mut u8, unsafe extern "C" fn(*mut u8))>;
     if DTORS.get().is_null() {
         let v: Box<List> = box Vec::new();
         DTORS.set(Box::into_raw(v) as *mut u8);
@@ -250,7 +253,7 @@ pub unsafe fn register_dtor_fallback(t: *mut u8,
     let list: &mut List = &mut *(DTORS.get() as *mut List);
     list.push((t, dtor));
 
-    unsafe extern fn run_dtors(mut ptr: *mut u8) {
+    unsafe extern "C" fn run_dtors(mut ptr: *mut u8) {
         while !ptr.is_null() {
             let list: Box<List> = Box::from_raw(ptr as *mut List);
             for (ptr, dtor) in list.into_iter() {