Skip to content

Commit 07376f7

Browse files
authored
Merge pull request #20 from ordian/change_mutability_to_match_c_lib
libmimalloc-sys: change ptr mutability to match the mimalloc c lib
2 parents 8036c7b + 4c0dc5d commit 07376f7

File tree

2 files changed

+14
-14
lines changed

2 files changed

+14
-14
lines changed

libmimalloc-sys/src/lib.rs

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@
33
use core::ffi::c_void;
44

55
extern "C" {
6-
pub fn mi_zalloc(size: usize) -> *const c_void;
7-
pub fn mi_malloc(size: usize) -> *const c_void;
8-
pub fn mi_realloc(p: *const c_void, size: usize) -> *const c_void;
9-
pub fn mi_zalloc_aligned(size: usize, alignment: usize) -> *const c_void;
10-
pub fn mi_malloc_aligned(size: usize, alignment: usize) -> *const c_void;
11-
pub fn mi_realloc_aligned(p: *const c_void, size: usize, alignment: usize) -> *const c_void;
12-
pub fn mi_free(p: *const c_void) -> c_void;
6+
pub fn mi_zalloc(size: usize) -> *mut c_void;
7+
pub fn mi_malloc(size: usize) -> *mut c_void;
8+
pub fn mi_realloc(p: *mut c_void, size: usize) -> *mut c_void;
9+
pub fn mi_zalloc_aligned(size: usize, alignment: usize) -> *mut c_void;
10+
pub fn mi_malloc_aligned(size: usize, alignment: usize) -> *mut c_void;
11+
pub fn mi_realloc_aligned(p: *mut c_void, size: usize, alignment: usize) -> *mut c_void;
12+
pub fn mi_free(p: *mut c_void) -> c_void;
1313
pub fn mi_usable_size(p: *mut c_void) -> usize;
1414
}
1515

@@ -20,20 +20,20 @@ mod tests {
2020
#[test]
2121
fn it_frees_memory_malloc() {
2222
let ptr = unsafe { mi_malloc_aligned(8, 8) } as *mut u8;
23-
unsafe { mi_free(ptr as *const c_void) };
23+
unsafe { mi_free(ptr as *mut c_void) };
2424
}
2525

2626
#[test]
2727
fn it_frees_memory_zalloc() {
2828
let ptr = unsafe { mi_zalloc_aligned(8, 8) } as *mut u8;
29-
unsafe { mi_free(ptr as *const c_void) };
29+
unsafe { mi_free(ptr as *mut c_void) };
3030
}
3131

3232
#[test]
3333
fn it_frees_memory_realloc() {
3434
let ptr = unsafe { mi_malloc_aligned(8, 8) } as *mut u8;
35-
let ptr = unsafe { mi_realloc_aligned(ptr as *const c_void, 8, 8) } as *mut u8;
36-
unsafe { mi_free(ptr as *const c_void) };
35+
let ptr = unsafe { mi_realloc_aligned(ptr as *mut c_void, 8, 8) } as *mut u8;
36+
unsafe { mi_free(ptr as *mut c_void) };
3737
}
3838

3939
#[test]

src/lib.rs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -94,15 +94,15 @@ unsafe impl GlobalAlloc for MiMalloc {
9494

9595
#[inline]
9696
unsafe fn dealloc(&self, ptr: *mut u8, _layout: Layout) {
97-
mi_free(ptr as *const c_void);
97+
mi_free(ptr as *mut c_void);
9898
}
9999

100100
#[inline]
101101
unsafe fn realloc(&self, ptr: *mut u8, layout: Layout, new_size: usize) -> *mut u8 {
102102
if layout.align() <= MIN_ALIGN && layout.align() <= layout.size() {
103-
mi_realloc(ptr as *const c_void, new_size) as *mut u8
103+
mi_realloc(ptr as *mut c_void, new_size) as *mut u8
104104
} else {
105-
mi_realloc_aligned(ptr as *const c_void, new_size, layout.align()) as *mut u8
105+
mi_realloc_aligned(ptr as *mut c_void, new_size, layout.align()) as *mut u8
106106
}
107107
}
108108
}

0 commit comments

Comments
 (0)