about summary refs log tree commit diff
path: root/src/libstd/rt
diff options
context:
space:
mode:
authorFlorian Hahn <flo@fhahn.com>2013-12-12 22:27:26 +0100
committerFlorian Hahn <flo@fhahn.com>2014-01-22 19:20:47 +0100
commit2eb4f05850e25863f05a56b60931e9eb03944b56 (patch)
treedbbb1b2aeb64ff54abf331d7be7bb9ce6615c9e0 /src/libstd/rt
parent750d48b0ad1854b389ce1c209484f9146dc7aba0 (diff)
downloadrust-2eb4f05850e25863f05a56b60931e9eb03944b56.tar.gz
rust-2eb4f05850e25863f05a56b60931e9eb03944b56.zip
Replace C types with Rust types in libstd, closes #7313
Diffstat (limited to 'src/libstd/rt')
-rw-r--r--src/libstd/rt/global_heap.rs28
-rw-r--r--src/libstd/rt/local_heap.rs12
-rw-r--r--src/libstd/rt/local_ptr.rs12
-rw-r--r--src/libstd/rt/thread.rs2
-rw-r--r--src/libstd/rt/thread_local_storage.rs17
-rw-r--r--src/libstd/rt/unwind.rs13
-rw-r--r--src/libstd/rt/util.rs1
7 files changed, 40 insertions, 45 deletions
diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs
index 00195f726cb..54442cedb68 100644
--- a/src/libstd/rt/global_heap.rs
+++ b/src/libstd/rt/global_heap.rs
@@ -8,7 +8,7 @@
 // option. This file may not be copied, modified, or distributed
 // except according to those terms.
 
-use libc::{c_void, c_char, size_t, uintptr_t, free, malloc, realloc};
+use libc::{c_void, size_t, free, malloc, realloc};
 use ptr::{RawPtr, mut_null};
 use unstable::intrinsics::{TyDesc, abort};
 use unstable::raw;
@@ -31,7 +31,7 @@ fn align_to(size: uint, align: uint) -> uint {
 
 /// A wrapper around libc::malloc, aborting on out-of-memory
 #[inline]
-pub unsafe fn malloc_raw(size: uint) -> *mut c_void {
+pub unsafe fn malloc_raw(size: uint) -> *mut u8 {
     // `malloc(0)` may allocate, but it may also return a null pointer
     // http://pubs.opengroup.org/onlinepubs/9699919799/functions/malloc.html
     if size == 0 {
@@ -42,25 +42,25 @@ pub unsafe fn malloc_raw(size: uint) -> *mut c_void {
             // we need a non-allocating way to print an error here
             abort();
         }
-        p
+        p as *mut u8
     }
 }
 
 /// A wrapper around libc::realloc, aborting on out-of-memory
 #[inline]
-pub unsafe fn realloc_raw(ptr: *mut c_void, size: uint) -> *mut c_void {
+pub unsafe fn realloc_raw(ptr: *mut u8, size: uint) -> *mut u8 {
     // `realloc(ptr, 0)` may allocate, but it may also return a null pointer
     // http://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html
     if size == 0 {
         free(ptr as *c_void);
         mut_null()
     } else {
-        let p = realloc(ptr, size as size_t);
+        let p = realloc(ptr as *mut c_void, size as size_t);
         if p.is_null() {
             // we need a non-allocating way to print an error here
             abort();
         }
-        p
+        p as *mut u8
     }
 }
 
@@ -68,22 +68,22 @@ pub unsafe fn realloc_raw(ptr: *mut c_void, size: uint) -> *mut c_void {
 #[cfg(not(test))]
 #[lang="exchange_malloc"]
 #[inline]
-pub unsafe fn exchange_malloc(size: uintptr_t) -> *c_char {
-    malloc_raw(size as uint) as *c_char
+pub unsafe fn exchange_malloc(size: uint) -> *u8 {
+    malloc_raw(size) as *u8
 }
 
 // FIXME: #7496
 #[cfg(not(test))]
 #[lang="closure_exchange_malloc"]
 #[inline]
-pub unsafe fn closure_exchange_malloc_(td: *c_char, size: uintptr_t) -> *c_char {
+pub unsafe fn closure_exchange_malloc_(td: *u8, size: uint) -> *u8 {
     closure_exchange_malloc(td, size)
 }
 
 #[inline]
-pub unsafe fn closure_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
+pub unsafe fn closure_exchange_malloc(td: *u8, size: uint) -> *u8 {
     let td = td as *TyDesc;
-    let size = size as uint;
+    let size = size;
 
     assert!(td.is_not_null());
 
@@ -93,7 +93,7 @@ pub unsafe fn closure_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
     let alloc = p as *mut raw::Box<()>;
     (*alloc).type_desc = td;
 
-    alloc as *c_char
+    alloc as *u8
 }
 
 // NB: Calls to free CANNOT be allowed to fail, as throwing an exception from
@@ -101,12 +101,12 @@ pub unsafe fn closure_exchange_malloc(td: *c_char, size: uintptr_t) -> *c_char {
 #[cfg(not(test))]
 #[lang="exchange_free"]
 #[inline]
-pub unsafe fn exchange_free_(ptr: *c_char) {
+pub unsafe fn exchange_free_(ptr: *u8) {
     exchange_free(ptr)
 }
 
 #[inline]
-pub unsafe fn exchange_free(ptr: *c_char) {
+pub unsafe fn exchange_free(ptr: *u8) {
     free(ptr as *c_void);
 }
 
diff --git a/src/libstd/rt/local_heap.rs b/src/libstd/rt/local_heap.rs
index 90179612272..36e3bf858e3 100644
--- a/src/libstd/rt/local_heap.rs
+++ b/src/libstd/rt/local_heap.rs
@@ -12,8 +12,6 @@
 
 use cast;
 use iter::Iterator;
-use libc::{c_void, uintptr_t};
-use libc;
 use mem;
 use ops::Drop;
 use option::{Option, None, Some};
@@ -223,7 +221,7 @@ impl MemoryRegion {
 
         let total_size = size + AllocHeader::size();
         let alloc: *AllocHeader = unsafe {
-            global_heap::realloc_raw(orig_alloc as *mut libc::c_void,
+            global_heap::realloc_raw(orig_alloc as *mut u8,
                                      total_size) as *AllocHeader
         };
 
@@ -243,7 +241,7 @@ impl MemoryRegion {
             self.release(cast::transmute(alloc));
             rtassert!(self.live_allocations > 0);
             self.live_allocations -= 1;
-            global_heap::exchange_free(alloc as *libc::c_char)
+            global_heap::exchange_free(alloc as *u8)
         }
     }
 
@@ -294,12 +292,12 @@ impl Drop for MemoryRegion {
 }
 
 #[inline]
-pub unsafe fn local_malloc(td: *libc::c_char, size: libc::uintptr_t) -> *libc::c_char {
+pub unsafe fn local_malloc(td: *u8, size: uint) -> *u8 {
     // XXX: Unsafe borrow for speed. Lame.
     let task: Option<*mut Task> = Local::try_unsafe_borrow();
     match task {
         Some(task) => {
-            (*task).heap.alloc(td as *TyDesc, size as uint) as *libc::c_char
+            (*task).heap.alloc(td as *TyDesc, size) as *u8
         }
         None => rtabort!("local malloc outside of task")
     }
@@ -307,7 +305,7 @@ pub unsafe fn local_malloc(td: *libc::c_char, size: libc::uintptr_t) -> *libc::c
 
 // A little compatibility function
 #[inline]
-pub unsafe fn local_free(ptr: *libc::c_char) {
+pub unsafe fn local_free(ptr: *u8) {
     // XXX: Unsafe borrow for speed. Lame.
     let task_ptr: Option<*mut Task> = Local::try_unsafe_borrow();
     match task_ptr {
diff --git a/src/libstd/rt/local_ptr.rs b/src/libstd/rt/local_ptr.rs
index b89c06edda3..d4e57ab19b1 100644
--- a/src/libstd/rt/local_ptr.rs
+++ b/src/libstd/rt/local_ptr.rs
@@ -81,14 +81,13 @@ pub mod compiled {
     use cast;
     use option::{Option, Some, None};
     use ptr::RawPtr;
-    #[cfg(not(test))] use libc::c_void;
 
     #[cfg(test)]
     pub use realstd::rt::shouldnt_be_public::RT_TLS_PTR;
 
     #[cfg(not(test))]
     #[thread_local]
-    pub static mut RT_TLS_PTR: *mut c_void = 0 as *mut c_void;
+    pub static mut RT_TLS_PTR: *mut u8 = 0 as *mut u8;
 
     pub fn init() {}
 
@@ -230,7 +229,6 @@ pub mod compiled {
 /// thread-local value.
 pub mod native {
     use cast;
-    use libc::c_void;
     use option::{Option, Some, None};
     use ptr;
     use ptr::RawPtr;
@@ -259,7 +257,7 @@ pub mod native {
     #[inline]
     pub unsafe fn put<T>(sched: ~T) {
         let key = tls_key();
-        let void_ptr: *mut c_void = cast::transmute(sched);
+        let void_ptr: *mut u8 = cast::transmute(sched);
         tls::set(key, void_ptr);
     }
 
@@ -271,7 +269,7 @@ pub mod native {
     #[inline]
     pub unsafe fn take<T>() -> ~T {
         let key = tls_key();
-        let void_ptr: *mut c_void = tls::get(key);
+        let void_ptr: *mut u8 = tls::get(key);
         if void_ptr.is_null() {
             rtabort!("thread-local pointer is null. bogus!");
         }
@@ -289,7 +287,7 @@ pub mod native {
     pub unsafe fn try_take<T>() -> Option<~T> {
         match maybe_tls_key() {
             Some(key) => {
-                let void_ptr: *mut c_void = tls::get(key);
+                let void_ptr: *mut u8 = tls::get(key);
                 if void_ptr.is_null() {
                     None
                 } else {
@@ -311,7 +309,7 @@ pub mod native {
     #[inline]
     pub unsafe fn unsafe_take<T>() -> ~T {
         let key = tls_key();
-        let void_ptr: *mut c_void = tls::get(key);
+        let void_ptr: *mut u8 = tls::get(key);
         if void_ptr.is_null() {
             rtabort!("thread-local pointer is null. bogus!");
         }
diff --git a/src/libstd/rt/thread.rs b/src/libstd/rt/thread.rs
index f4f4aaa2765..b5262424c06 100644
--- a/src/libstd/rt/thread.rs
+++ b/src/libstd/rt/thread.rs
@@ -196,7 +196,7 @@ mod imp {
     use unstable::intrinsics;
 
     pub type rust_thread = libc::pthread_t;
-    pub type rust_thread_return = *libc::c_void;
+    pub type rust_thread_return = *u8;
 
     pub unsafe fn create(stack: uint, p: ~proc()) -> rust_thread {
         let mut native: libc::pthread_t = intrinsics::uninit();
diff --git a/src/libstd/rt/thread_local_storage.rs b/src/libstd/rt/thread_local_storage.rs
index d5affdd5173..40d9523cf3a 100644
--- a/src/libstd/rt/thread_local_storage.rs
+++ b/src/libstd/rt/thread_local_storage.rs
@@ -10,7 +10,6 @@
 
 #[allow(dead_code)];
 
-use libc::c_void;
 #[cfg(unix)]
 use libc::c_int;
 #[cfg(unix)]
@@ -27,12 +26,12 @@ pub unsafe fn create(key: &mut Key) {
 }
 
 #[cfg(unix)]
-pub unsafe fn set(key: Key, value: *mut c_void) {
+pub unsafe fn set(key: Key, value: *mut u8) {
     assert_eq!(0, pthread_setspecific(key, value));
 }
 
 #[cfg(unix)]
-pub unsafe fn get(key: Key) -> *mut c_void {
+pub unsafe fn get(key: Key) -> *mut u8 {
     pthread_getspecific(key)
 }
 
@@ -55,8 +54,8 @@ type pthread_key_t = ::libc::c_uint;
 extern {
     fn pthread_key_create(key: *mut pthread_key_t, dtor: *u8) -> c_int;
     fn pthread_key_delete(key: pthread_key_t) -> c_int;
-    fn pthread_getspecific(key: pthread_key_t) -> *mut c_void;
-    fn pthread_setspecific(key: pthread_key_t, value: *mut c_void) -> c_int;
+    fn pthread_getspecific(key: pthread_key_t) -> *mut u8;
+    fn pthread_setspecific(key: pthread_key_t, value: *mut u8) -> c_int;
 }
 
 #[cfg(windows)]
@@ -70,13 +69,13 @@ pub unsafe fn create(key: &mut Key) {
 }
 
 #[cfg(windows)]
-pub unsafe fn set(key: Key, value: *mut c_void) {
-    assert!(0 != TlsSetValue(key, value))
+pub unsafe fn set(key: Key, value: *mut u8) {
+    assert!(0 != TlsSetValue(key, value as *mut ::libc::c_void))
 }
 
 #[cfg(windows)]
-pub unsafe fn get(key: Key) -> *mut c_void {
-    TlsGetValue(key)
+pub unsafe fn get(key: Key) -> *mut u8 {
+    TlsGetValue(key) as *mut u8
 }
 
 #[cfg(windows)]
diff --git a/src/libstd/rt/unwind.rs b/src/libstd/rt/unwind.rs
index ffe254574eb..6f3aa4c4fd0 100644
--- a/src/libstd/rt/unwind.rs
+++ b/src/libstd/rt/unwind.rs
@@ -59,7 +59,6 @@ use any::{Any, AnyRefExt};
 use c_str::CString;
 use cast;
 use kinds::Send;
-use libc::{c_void, c_char, size_t};
 use option::{Some, None, Option};
 use prelude::drop;
 use ptr::RawPtr;
@@ -79,7 +78,7 @@ mod libunwind {
     #[allow(non_camel_case_types)];
     #[allow(dead_code)] // these are just bindings
 
-    use libc::{uintptr_t, uint64_t};
+    use libc::{uintptr_t};
 
     #[cfg(not(target_arch = "arm"))]
     #[repr(C)]
@@ -118,7 +117,7 @@ mod libunwind {
         _URC_FAILURE = 9, // used only by ARM EABI
     }
 
-    pub type _Unwind_Exception_Class = uint64_t;
+    pub type _Unwind_Exception_Class = u64;
 
     pub type _Unwind_Word = uintptr_t;
 
@@ -164,6 +163,7 @@ impl Unwinder {
 
     pub fn try(&mut self, f: ||) {
         use unstable::raw::Closure;
+        use libc::{c_void};
 
         unsafe {
             let closure: Closure = cast::transmute(f);
@@ -365,10 +365,11 @@ pub mod eabi {
 /// The arguments are normally generated by the compiler, and need to
 /// have static lifetimes.
 #[inline(never)] #[cold] // this is the slow path, please never inline this
-pub fn begin_unwind_raw(msg: *c_char, file: *c_char, line: size_t) -> ! {
+pub fn begin_unwind_raw(msg: *u8, file: *u8, line: uint) -> ! {
+    use libc::c_char;
     #[inline]
-    fn static_char_ptr(p: *c_char) -> &'static str {
-        let s = unsafe { CString::new(p, false) };
+    fn static_char_ptr(p: *u8) -> &'static str {
+        let s = unsafe { CString::new(p as *c_char, false) };
         match s.as_str() {
             Some(s) => unsafe { cast::transmute::<&str, &'static str>(s) },
             None => rtabort!("message wasn't utf8?")
diff --git a/src/libstd/rt/util.rs b/src/libstd/rt/util.rs
index a5d5a4677f1..b482e2fb67f 100644
--- a/src/libstd/rt/util.rs
+++ b/src/libstd/rt/util.rs
@@ -70,7 +70,6 @@ pub fn default_sched_threads() -> uint {
 
 pub fn dumb_println(args: &fmt::Arguments) {
     use io;
-    use libc;
 
     struct Stderr;
     impl io::Writer for Stderr {