From b8fb0cf789289fb7d350cc553d871f880e1b2b02 Mon Sep 17 00:00:00 2001 From: Alex Crichton Date: Mon, 6 Oct 2014 16:35:11 -0700 Subject: [PATCH] rustrt: Convert statics to constants --- src/librustrt/c_str.rs | 2 +- src/librustrt/lib.rs | 2 +- src/librustrt/libunwind.rs | 10 ++++---- src/librustrt/mutex.rs | 48 +++++++++++++++++++------------------- src/librustrt/stack.rs | 2 +- src/librustrt/unwind.rs | 2 +- src/librustrt/util.rs | 6 ++--- 7 files changed, 36 insertions(+), 36 deletions(-) diff --git a/src/librustrt/c_str.rs b/src/librustrt/c_str.rs index 934fb0ddd3c..a5ac70286fe 100644 --- a/src/librustrt/c_str.rs +++ b/src/librustrt/c_str.rs @@ -414,7 +414,7 @@ impl ToCStr for String { } // The length of the stack allocated buffer for `vec.with_c_str()` -static BUF_LEN: uint = 128; +const BUF_LEN: uint = 128; impl<'a> ToCStr for &'a [u8] { fn to_c_str(&self) -> CString { diff --git a/src/librustrt/lib.rs b/src/librustrt/lib.rs index d3ea07291a4..26fc399968c 100644 --- a/src/librustrt/lib.rs +++ b/src/librustrt/lib.rs @@ -100,7 +100,7 @@ pub trait Runtime { /// The default error code of the rust runtime if the main task fails instead /// of exiting cleanly. -pub static DEFAULT_ERROR_CODE: int = 101; +pub const DEFAULT_ERROR_CODE: int = 101; /// One-time runtime initialization. /// diff --git a/src/librustrt/libunwind.rs b/src/librustrt/libunwind.rs index bb7a1227e0e..6867cb2e76b 100644 --- a/src/librustrt/libunwind.rs +++ b/src/librustrt/libunwind.rs @@ -57,19 +57,19 @@ pub type _Unwind_Exception_Class = u64; pub type _Unwind_Word = libc::uintptr_t; #[cfg(target_arch = "x86")] -pub static unwinder_private_data_size: uint = 5; +pub const unwinder_private_data_size: uint = 5; #[cfg(target_arch = "x86_64")] -pub static unwinder_private_data_size: uint = 6; +pub const unwinder_private_data_size: uint = 6; #[cfg(all(target_arch = "arm", not(target_os = "ios")))] -pub static unwinder_private_data_size: uint = 20; +pub const unwinder_private_data_size: uint = 20; #[cfg(all(target_arch = "arm", target_os = "ios"))] -pub static unwinder_private_data_size: uint = 5; +pub const unwinder_private_data_size: uint = 5; #[cfg(any(target_arch = "mips", target_arch = "mipsel"))] -pub static unwinder_private_data_size: uint = 2; +pub const unwinder_private_data_size: uint = 2; #[repr(C)] pub struct _Unwind_Exception { diff --git a/src/librustrt/mutex.rs b/src/librustrt/mutex.rs index 28b0256f2e6..d10ba693866 100644 --- a/src/librustrt/mutex.rs +++ b/src/librustrt/mutex.rs @@ -88,7 +88,7 @@ pub struct LockGuard<'a> { lock: &'a StaticNativeMutex } -pub static NATIVE_MUTEX_INIT: StaticNativeMutex = StaticNativeMutex { +pub const NATIVE_MUTEX_INIT: StaticNativeMutex = StaticNativeMutex { inner: imp::MUTEX_INIT, }; @@ -353,9 +353,9 @@ mod imp { pub type pthread_mutex_t = *mut libc::c_void; pub type pthread_cond_t = *mut libc::c_void; - pub static PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = 0 as pthread_mutex_t; - pub static PTHREAD_COND_INITIALIZER: pthread_cond_t = + pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = 0 as pthread_cond_t; } @@ -390,11 +390,11 @@ mod imp { __opaque: [u8, ..__PTHREAD_COND_SIZE__], } - pub static PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { __sig: _PTHREAD_MUTEX_SIG_INIT, __opaque: [0, ..__PTHREAD_MUTEX_SIZE__], }; - pub static PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { + pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { __sig: _PTHREAD_COND_SIG_INIT, __opaque: [0, ..__PTHREAD_COND_SIZE__], }; @@ -406,25 +406,25 @@ mod imp { // minus 8 because we have an 'align' field #[cfg(target_arch = "x86_64")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 40 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 40 - 8; #[cfg(target_arch = "x86")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; #[cfg(target_arch = "arm")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; #[cfg(target_arch = "mips")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; #[cfg(target_arch = "mipsel")] - static __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; + const __SIZEOF_PTHREAD_MUTEX_T: uint = 24 - 8; #[cfg(target_arch = "x86_64")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[cfg(target_arch = "x86")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[cfg(target_arch = "arm")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[cfg(target_arch = "mips")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[cfg(target_arch = "mipsel")] - static __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; + const __SIZEOF_PTHREAD_COND_T: uint = 48 - 8; #[repr(C)] pub struct pthread_mutex_t { @@ -437,11 +437,11 @@ mod imp { size: [u8, ..__SIZEOF_PTHREAD_COND_T], } - pub static PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { __align: 0, size: [0, ..__SIZEOF_PTHREAD_MUTEX_T], }; - pub static PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { + pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { __align: 0, size: [0, ..__SIZEOF_PTHREAD_COND_T], }; @@ -455,10 +455,10 @@ mod imp { #[repr(C)] pub struct pthread_cond_t { value: libc::c_int } - pub static PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { + pub const PTHREAD_MUTEX_INITIALIZER: pthread_mutex_t = pthread_mutex_t { value: 0, }; - pub static PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { + pub const PTHREAD_COND_INITIALIZER: pthread_cond_t = pthread_cond_t { value: 0, }; } @@ -468,7 +468,7 @@ mod imp { cond: UnsafeCell, } - pub static MUTEX_INIT: Mutex = Mutex { + pub const MUTEX_INIT: Mutex = Mutex { lock: UnsafeCell { value: PTHREAD_MUTEX_INITIALIZER }, cond: UnsafeCell { value: PTHREAD_COND_INITIALIZER }, }; @@ -523,11 +523,11 @@ mod imp { use libc; type LPCRITICAL_SECTION = *mut c_void; - static SPIN_COUNT: DWORD = 4000; + const SPIN_COUNT: DWORD = 4000; #[cfg(target_arch = "x86")] - static CRIT_SECTION_SIZE: uint = 24; + const CRIT_SECTION_SIZE: uint = 24; #[cfg(target_arch = "x86_64")] - static CRIT_SECTION_SIZE: uint = 40; + const CRIT_SECTION_SIZE: uint = 40; pub struct Mutex { // pointers for the lock/cond handles, atomically updated @@ -535,7 +535,7 @@ mod imp { cond: atomic::AtomicUint, } - pub static MUTEX_INIT: Mutex = Mutex { + pub const MUTEX_INIT: Mutex = Mutex { lock: atomic::INIT_ATOMIC_UINT, cond: atomic::INIT_ATOMIC_UINT, }; diff --git a/src/librustrt/stack.rs b/src/librustrt/stack.rs index 5c94ef61bfd..4034000e28f 100644 --- a/src/librustrt/stack.rs +++ b/src/librustrt/stack.rs @@ -46,7 +46,7 @@ // corresponding prolog, decision was taken to disable segmented // stack support on iOS. -pub static RED_ZONE: uint = 20 * 1024; +pub const RED_ZONE: uint = 20 * 1024; /// This function is invoked from rust's current __morestack function. Segmented /// stacks are currently not enabled as segmented stacks, but rather one giant diff --git a/src/librustrt/unwind.rs b/src/librustrt/unwind.rs index f07e8ecc335..2a2fa29eca0 100644 --- a/src/librustrt/unwind.rs +++ b/src/librustrt/unwind.rs @@ -91,7 +91,7 @@ pub type Callback = fn(msg: &Any + Send, file: &'static str, line: uint); // Variables used for invoking callbacks when a task starts to unwind. // // For more information, see below. -static MAX_CALLBACKS: uint = 16; +const MAX_CALLBACKS: uint = 16; static mut CALLBACKS: [atomic::AtomicUint, ..MAX_CALLBACKS] = [atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, atomic::INIT_ATOMIC_UINT, diff --git a/src/librustrt/util.rs b/src/librustrt/util.rs index ab1ef2fc5aa..a94da33e543 100644 --- a/src/librustrt/util.rs +++ b/src/librustrt/util.rs @@ -23,15 +23,15 @@ use libc; // // FIXME: Once the runtime matures remove the `true` below to turn off rtassert, // etc. -pub static ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) || +pub const ENFORCE_SANITY: bool = true || !cfg!(rtopt) || cfg!(rtdebug) || cfg!(rtassert); pub struct Stdio(libc::c_int); #[allow(non_uppercase_statics)] -pub static Stdout: Stdio = Stdio(libc::STDOUT_FILENO); +pub const Stdout: Stdio = Stdio(libc::STDOUT_FILENO); #[allow(non_uppercase_statics)] -pub static Stderr: Stdio = Stdio(libc::STDERR_FILENO); +pub const Stderr: Stdio = Stdio(libc::STDERR_FILENO); impl fmt::FormatWriter for Stdio { fn write(&mut self, data: &[u8]) -> fmt::Result {