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.
This commit is contained in:
parent
fce792249e
commit
802d41fe23
|
@ -230,7 +230,7 @@ impl<T: Send> Drop for Unique<T> {
|
|||
// We need to move the object out of the box, so that
|
||||
// the destructor is called (at the end of this scope.)
|
||||
ptr::replace_ptr(self.ptr, x);
|
||||
free(self.ptr as *c_void)
|
||||
free(self.ptr as *mut c_void)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -172,7 +172,7 @@ mod tests {
|
|||
let mem = malloc_raw(n);
|
||||
|
||||
CVec::new_with_dtor(mem as *mut u8, n,
|
||||
proc() { libc::free(mem as *c_void); })
|
||||
proc() { libc::free(mem as *mut c_void); })
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -53,7 +53,7 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> ~[u8] {
|
|||
assert!(res as int != 0);
|
||||
let out = vec::raw::from_buf_raw(res as *u8,
|
||||
outsz as uint);
|
||||
libc::free(res);
|
||||
libc::free(res as *mut c_void);
|
||||
out
|
||||
}
|
||||
}
|
||||
|
@ -76,7 +76,7 @@ fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> ~[u8] {
|
|||
assert!(res as int != 0);
|
||||
let out = vec::raw::from_buf_raw(res as *u8,
|
||||
outsz as uint);
|
||||
libc::free(res);
|
||||
libc::free(res as *mut c_void);
|
||||
out
|
||||
}
|
||||
}
|
||||
|
|
|
@ -548,13 +548,13 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
|
|||
let p = Path::new(p);
|
||||
let star = p.join("*");
|
||||
as_utf16_p(star.as_str().unwrap(), |path_ptr| {
|
||||
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint) as *c_void;
|
||||
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
|
||||
let find_handle = FindFirstFileW(path_ptr, wfd_ptr as HANDLE);
|
||||
if find_handle as libc::c_int != INVALID_HANDLE_VALUE {
|
||||
let mut paths = ~[];
|
||||
let mut more_files = 1 as libc::c_int;
|
||||
while more_files != 0 {
|
||||
let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr);
|
||||
let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr as *c_void);
|
||||
if fp_buf as uint == 0 {
|
||||
fail!("os::list_dir() failure: got null ptr from wfd");
|
||||
}
|
||||
|
@ -567,7 +567,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
|
|||
more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);
|
||||
}
|
||||
FindClose(find_handle);
|
||||
free(wfd_ptr);
|
||||
free(wfd_ptr as *mut c_void);
|
||||
Ok(paths)
|
||||
} else {
|
||||
Err(super::last_error())
|
||||
|
|
|
@ -1836,7 +1836,7 @@ impl TypeNames {
|
|||
unsafe {
|
||||
let s = llvm::LLVMTypeToString(ty.to_ref());
|
||||
let ret = from_c_str(s);
|
||||
free(s as *c_void);
|
||||
free(s as *mut c_void);
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
@ -1850,7 +1850,7 @@ impl TypeNames {
|
|||
unsafe {
|
||||
let s = llvm::LLVMValueToString(val);
|
||||
let ret = from_c_str(s);
|
||||
free(s as *c_void);
|
||||
free(s as *mut c_void);
|
||||
ret
|
||||
}
|
||||
}
|
||||
|
|
|
@ -373,7 +373,7 @@ pub unsafe fn malloc_handle(handle: uv_handle_type) -> *c_void {
|
|||
}
|
||||
|
||||
pub unsafe fn free_handle(v: *c_void) {
|
||||
free(v)
|
||||
free(v as *mut c_void)
|
||||
}
|
||||
|
||||
pub unsafe fn malloc_req(req: uv_req_type) -> *c_void {
|
||||
|
@ -383,7 +383,7 @@ pub unsafe fn malloc_req(req: uv_req_type) -> *c_void {
|
|||
}
|
||||
|
||||
pub unsafe fn free_req(v: *c_void) {
|
||||
free(v)
|
||||
free(v as *mut c_void)
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
|
|
@ -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]
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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)]
|
||||
|
|
|
@ -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) }
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -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) {
|
||||
|
|
Loading…
Reference in New Issue