Skip to content

Commit 802d41f

Browse files
committed
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.
1 parent fce7922 commit 802d41f

File tree

11 files changed

+37
-37
lines changed

11 files changed

+37
-37
lines changed

doc/guide-ffi.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -230,7 +230,7 @@ impl<T: Send> Drop for Unique<T> {
230230
// We need to move the object out of the box, so that
231231
// the destructor is called (at the end of this scope.)
232232
ptr::replace_ptr(self.ptr, x);
233-
free(self.ptr as *c_void)
233+
free(self.ptr as *mut c_void)
234234
}
235235
}
236236
}

src/libextra/c_vec.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -172,7 +172,7 @@ mod tests {
172172
let mem = malloc_raw(n);
173173

174174
CVec::new_with_dtor(mem as *mut u8, n,
175-
proc() { libc::free(mem as *c_void); })
175+
proc() { libc::free(mem as *mut c_void); })
176176
}
177177
}
178178

src/libextra/flate.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ fn deflate_bytes_internal(bytes: &[u8], flags: c_int) -> ~[u8] {
5353
assert!(res as int != 0);
5454
let out = vec::raw::from_buf_raw(res as *u8,
5555
outsz as uint);
56-
libc::free(res);
56+
libc::free(res as *mut c_void);
5757
out
5858
}
5959
}
@@ -76,7 +76,7 @@ fn inflate_bytes_internal(bytes: &[u8], flags: c_int) -> ~[u8] {
7676
assert!(res as int != 0);
7777
let out = vec::raw::from_buf_raw(res as *u8,
7878
outsz as uint);
79-
libc::free(res);
79+
libc::free(res as *mut c_void);
8080
out
8181
}
8282
}

src/libnative/io/file.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -548,13 +548,13 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
548548
let p = Path::new(p);
549549
let star = p.join("*");
550550
as_utf16_p(star.as_str().unwrap(), |path_ptr| {
551-
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint) as *c_void;
551+
let wfd_ptr = malloc_raw(rust_list_dir_wfd_size() as uint);
552552
let find_handle = FindFirstFileW(path_ptr, wfd_ptr as HANDLE);
553553
if find_handle as libc::c_int != INVALID_HANDLE_VALUE {
554554
let mut paths = ~[];
555555
let mut more_files = 1 as libc::c_int;
556556
while more_files != 0 {
557-
let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr);
557+
let fp_buf = rust_list_dir_wfd_fp_buf(wfd_ptr as *c_void);
558558
if fp_buf as uint == 0 {
559559
fail!("os::list_dir() failure: got null ptr from wfd");
560560
}
@@ -567,7 +567,7 @@ pub fn readdir(p: &CString) -> IoResult<~[Path]> {
567567
more_files = FindNextFileW(find_handle, wfd_ptr as HANDLE);
568568
}
569569
FindClose(find_handle);
570-
free(wfd_ptr);
570+
free(wfd_ptr as *mut c_void);
571571
Ok(paths)
572572
} else {
573573
Err(super::last_error())

src/librustc/lib/llvm.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1836,7 +1836,7 @@ impl TypeNames {
18361836
unsafe {
18371837
let s = llvm::LLVMTypeToString(ty.to_ref());
18381838
let ret = from_c_str(s);
1839-
free(s as *c_void);
1839+
free(s as *mut c_void);
18401840
ret
18411841
}
18421842
}
@@ -1850,7 +1850,7 @@ impl TypeNames {
18501850
unsafe {
18511851
let s = llvm::LLVMValueToString(val);
18521852
let ret = from_c_str(s);
1853-
free(s as *c_void);
1853+
free(s as *mut c_void);
18541854
ret
18551855
}
18561856
}

src/librustuv/uvll.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -373,7 +373,7 @@ pub unsafe fn malloc_handle(handle: uv_handle_type) -> *c_void {
373373
}
374374

375375
pub unsafe fn free_handle(v: *c_void) {
376-
free(v)
376+
free(v as *mut c_void)
377377
}
378378

379379
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 {
383383
}
384384

385385
pub unsafe fn free_req(v: *c_void) {
386-
free(v)
386+
free(v as *mut c_void)
387387
}
388388

389389
#[test]

src/libstd/c_str.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -183,7 +183,7 @@ impl Drop for CString {
183183
fn drop(&mut self) {
184184
if self.owns_buffer_ {
185185
unsafe {
186-
libc::free(self.buf as *libc::c_void)
186+
libc::free(self.buf as *mut libc::c_void)
187187
}
188188
}
189189
}
@@ -459,7 +459,7 @@ mod tests {
459459
#[test]
460460
fn test_unwrap() {
461461
let c_str = "hello".to_c_str();
462-
unsafe { libc::free(c_str.unwrap() as *libc::c_void) }
462+
unsafe { libc::free(c_str.unwrap() as *mut libc::c_void) }
463463
}
464464

465465
#[test]

src/libstd/libc.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3225,7 +3225,7 @@ pub mod funcs {
32253225
pub fn calloc(nobj: size_t, size: size_t) -> *c_void;
32263226
pub fn malloc(size: size_t) -> *mut c_void;
32273227
pub fn realloc(p: *mut c_void, size: size_t) -> *mut c_void;
3228-
pub fn free(p: *c_void);
3228+
pub fn free(p: *mut c_void);
32293229
pub fn exit(status: c_int) -> !;
32303230
// Omitted: atexit.
32313231
pub fn system(s: *c_char) -> c_int;

src/libstd/rt/global_heap.rs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ pub unsafe fn realloc_raw(ptr: *mut u8, size: uint) -> *mut u8 {
5252
// `realloc(ptr, 0)` may allocate, but it may also return a null pointer
5353
// http://pubs.opengroup.org/onlinepubs/9699919799/functions/realloc.html
5454
if size == 0 {
55-
free(ptr as *c_void);
55+
free(ptr);
5656
mut_null()
5757
} else {
5858
let p = realloc(ptr as *mut c_void, size as size_t);
@@ -107,7 +107,7 @@ pub unsafe fn exchange_free_(ptr: *u8) {
107107

108108
#[inline]
109109
pub unsafe fn exchange_free(ptr: *u8) {
110-
free(ptr as *c_void);
110+
free(ptr as *mut c_void);
111111
}
112112

113113
#[cfg(test)]

src/libstd/sync/deque.rs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -389,7 +389,7 @@ impl<T: Send> Buffer<T> {
389389
impl<T: Send> Drop for Buffer<T> {
390390
fn drop(&mut self) {
391391
// It is assumed that all buffers are empty on drop.
392-
unsafe { libc::free(self.storage as *libc::c_void) }
392+
unsafe { libc::free(self.storage as *mut libc::c_void) }
393393
}
394394
}
395395

0 commit comments

Comments
 (0)