diff options
| author | Daniel Micay <danielmicay@gmail.com> | 2014-01-21 09:31:32 -0500 |
|---|---|---|
| committer | Daniel Micay <danielmicay@gmail.com> | 2014-01-22 23:13:53 -0500 |
| commit | 802d41fe235794d84084897ae6187ee5cc27dd95 (patch) | |
| tree | 6cd1eecb0ec529673396040e2c43ad08941732e9 /src/libstd | |
| parent | fce792249e72a181f2ad52413b25b1db643c371f (diff) | |
| download | rust-802d41fe235794d84084897ae6187ee5cc27dd95.tar.gz rust-802d41fe235794d84084897ae6187ee5cc27dd95.zip | |
libc: switch `free` to the proper signature
This does not attempt to fully propagate the mutability everywhere, but gives new code a hint to avoid the same issues.
Diffstat (limited to 'src/libstd')
| -rw-r--r-- | src/libstd/c_str.rs | 4 | ||||
| -rw-r--r-- | src/libstd/libc.rs | 2 | ||||
| -rw-r--r-- | src/libstd/rt/global_heap.rs | 4 | ||||
| -rw-r--r-- | src/libstd/sync/deque.rs | 2 | ||||
| -rw-r--r-- | src/libstd/unstable/mutex.rs | 40 |
5 files changed, 26 insertions, 26 deletions
diff --git a/src/libstd/c_str.rs b/src/libstd/c_str.rs index c735e325068..22e93e58194 100644 --- a/src/libstd/c_str.rs +++ b/src/libstd/c_str.rs @@ -183,7 +183,7 @@ impl Drop for CString { fn drop(&mut self) { if self.owns_buffer_ { unsafe { - libc::free(self.buf as *libc::c_void) + libc::free(self.buf as *mut libc::c_void) } } } @@ -459,7 +459,7 @@ mod tests { #[test] fn test_unwrap() { let c_str = "hello".to_c_str(); - unsafe { libc::free(c_str.unwrap() as *libc::c_void) } + unsafe { libc::free(c_str.unwrap() as *mut libc::c_void) } } #[test] diff --git a/src/libstd/libc.rs b/src/libstd/libc.rs index 77ac226a7f1..a2aa182216a 100644 --- a/src/libstd/libc.rs +++ b/src/libstd/libc.rs @@ -3225,7 +3225,7 @@ pub mod funcs { pub fn calloc(nobj: size_t, size: size_t) -> *c_void; pub fn malloc(size: size_t) -> *mut c_void; pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void; - pub fn free(p: *c_void); + pub fn free(p: *mut c_void); pub fn exit(status: c_int) -> !; // Omitted: atexit. pub fn system(s: *c_char) -> c_int; diff --git a/src/libstd/rt/global_heap.rs b/src/libstd/rt/global_heap.rs index 54442cedb68..ead78ce41ef 100644 --- a/src/libstd/rt/global_heap.rs +++ b/src/libstd/rt/global_heap.rs @@ -52,7 +52,7 @@ 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); + free(ptr); mut_null() } else { let p = realloc(ptr as *mut c_void, size as size_t); @@ -107,7 +107,7 @@ pub unsafe fn exchange_free_(ptr: *u8) { #[inline] pub unsafe fn exchange_free(ptr: *u8) { - free(ptr as *c_void); + free(ptr as *mut c_void); } #[cfg(test)] diff --git a/src/libstd/sync/deque.rs b/src/libstd/sync/deque.rs index e99e9ef0940..e740862fddf 100644 --- a/src/libstd/sync/deque.rs +++ b/src/libstd/sync/deque.rs @@ -389,7 +389,7 @@ impl<T: Send> Buffer<T> { impl<T: Send> Drop for Buffer<T> { fn drop(&mut self) { // It is assumed that all buffers are empty on drop. - unsafe { libc::free(self.storage as *libc::c_void) } + unsafe { libc::free(self.storage as *mut libc::c_void) } } } diff --git a/src/libstd/unstable/mutex.rs b/src/libstd/unstable/mutex.rs index ff38a8c0199..69c6204cc32 100644 --- a/src/libstd/unstable/mutex.rs +++ b/src/libstd/unstable/mutex.rs @@ -173,49 +173,49 @@ mod imp { type pthread_condattr_t = libc::c_void; pub unsafe fn init_lock() -> uint { - let block = malloc_raw(rust_pthread_mutex_t_size() as uint) as *pthread_mutex_t; + let block = malloc_raw(rust_pthread_mutex_t_size() as uint) as *mut pthread_mutex_t; let n = pthread_mutex_init(block, ptr::null()); assert_eq!(n, 0); return block as uint; } pub unsafe fn init_cond() -> uint { - let block = malloc_raw(rust_pthread_cond_t_size() as uint) as *pthread_cond_t; + let block = malloc_raw(rust_pthread_cond_t_size() as uint) as *mut pthread_cond_t; let n = pthread_cond_init(block, ptr::null()); assert_eq!(n, 0); return block as uint; } pub unsafe fn free_lock(h: uint) { - let block = h as *libc::c_void; + let block = h as *mut libc::c_void; assert_eq!(pthread_mutex_destroy(block), 0); libc::free(block); } pub unsafe fn free_cond(h: uint) { - let block = h as *pthread_cond_t; + let block = h as *mut pthread_cond_t; assert_eq!(pthread_cond_destroy(block), 0); libc::free(block); } pub unsafe fn lock(l: uint) { - assert_eq!(pthread_mutex_lock(l as *pthread_mutex_t), 0); + assert_eq!(pthread_mutex_lock(l as *mut pthread_mutex_t), 0); } pub unsafe fn trylock(l: uint) -> bool { - pthread_mutex_trylock(l as *pthread_mutex_t) == 0 + pthread_mutex_trylock(l as *mut pthread_mutex_t) == 0 } pub unsafe fn unlock(l: uint) { - assert_eq!(pthread_mutex_unlock(l as *pthread_mutex_t), 0); + assert_eq!(pthread_mutex_unlock(l as *mut pthread_mutex_t), 0); } pub unsafe fn wait(cond: uint, m: uint) { - assert_eq!(pthread_cond_wait(cond as *pthread_cond_t, m as *pthread_mutex_t), 0); + assert_eq!(pthread_cond_wait(cond as *mut pthread_cond_t, m as *mut pthread_mutex_t), 0); } pub unsafe fn signal(cond: uint) { - assert_eq!(pthread_cond_signal(cond as *pthread_cond_t), 0); + assert_eq!(pthread_cond_signal(cond as *mut pthread_cond_t), 0); } extern { @@ -224,19 +224,19 @@ mod imp { } extern { - fn pthread_mutex_init(lock: *pthread_mutex_t, + fn pthread_mutex_init(lock: *mut pthread_mutex_t, attr: *pthread_mutexattr_t) -> libc::c_int; - fn pthread_mutex_destroy(lock: *pthread_mutex_t) -> libc::c_int; - fn pthread_cond_init(cond: *pthread_cond_t, + fn pthread_mutex_destroy(lock: *mut pthread_mutex_t) -> libc::c_int; + fn pthread_cond_init(cond: *mut pthread_cond_t, attr: *pthread_condattr_t) -> libc::c_int; - fn pthread_cond_destroy(cond: *pthread_cond_t) -> libc::c_int; - fn pthread_mutex_lock(lock: *pthread_mutex_t) -> libc::c_int; - fn pthread_mutex_trylock(lock: *pthread_mutex_t) -> libc::c_int; - fn pthread_mutex_unlock(lock: *pthread_mutex_t) -> libc::c_int; + fn pthread_cond_destroy(cond: *mut pthread_cond_t) -> libc::c_int; + fn pthread_mutex_lock(lock: *mut pthread_mutex_t) -> libc::c_int; + fn pthread_mutex_trylock(lock: *mut pthread_mutex_t) -> libc::c_int; + fn pthread_mutex_unlock(lock: *mut pthread_mutex_t) -> libc::c_int; - fn pthread_cond_wait(cond: *pthread_cond_t, - lock: *pthread_mutex_t) -> libc::c_int; - fn pthread_cond_signal(cond: *pthread_cond_t) -> libc::c_int; + fn pthread_cond_wait(cond: *mut pthread_cond_t, + lock: *mut pthread_mutex_t) -> libc::c_int; + fn pthread_cond_signal(cond: *mut pthread_cond_t) -> libc::c_int; } } @@ -263,7 +263,7 @@ mod imp { pub unsafe fn free_lock(h: uint) { DeleteCriticalSection(h as LPCRITICAL_SECTION); - libc::free(h as *c_void); + libc::free(h as *mut c_void); } pub unsafe fn free_cond(h: uint) { |
