|
| 1 | +#[cfg(all(target_os = "windows", feature = "mimalloc"))] |
| 2 | +#[global_allocator] |
| 3 | +static GLOBAL: mimalloc::MiMalloc = mimalloc::MiMalloc; |
| 4 | + |
| 5 | +#[cfg(all(target_os = "windows", feature = "mimalloc"))] |
| 6 | +pub mod fns { |
| 7 | + use std::os::raw::{c_char, c_int, c_void}; |
| 8 | + |
| 9 | + #[unsafe(no_mangle)] |
| 10 | + pub unsafe extern "C" fn calloc(items: usize, size: usize) -> *mut c_void { |
| 11 | + unsafe { libmimalloc_sys::mi_calloc(items, size) } |
| 12 | + } |
| 13 | + |
| 14 | + #[unsafe(no_mangle)] |
| 15 | + pub unsafe extern "C" fn posix_memalign( |
| 16 | + ptr: *mut *mut c_void, |
| 17 | + align: usize, |
| 18 | + size: usize, |
| 19 | + ) -> c_int { |
| 20 | + unsafe { libmimalloc_sys::mi_posix_memalign(ptr, align, size) } |
| 21 | + } |
| 22 | + |
| 23 | + #[unsafe(no_mangle)] |
| 24 | + pub unsafe extern "C" fn strndup(s: *const c_char, n: usize) -> *mut c_char { |
| 25 | + unsafe { libmimalloc_sys::mi_strndup(s, n) } |
| 26 | + } |
| 27 | + |
| 28 | + #[unsafe(no_mangle)] |
| 29 | + pub unsafe extern "C" fn strdup(s: *const c_char) -> *mut c_char { |
| 30 | + unsafe { libmimalloc_sys::mi_strdup(s) } |
| 31 | + } |
| 32 | + |
| 33 | + #[unsafe(no_mangle)] |
| 34 | + pub unsafe extern "C" fn aligned_alloc(align: usize, size: usize) -> *mut c_void { |
| 35 | + unsafe { libmimalloc_sys::mi_aligned_alloc(align, size) } |
| 36 | + } |
| 37 | + |
| 38 | + #[unsafe(no_mangle)] |
| 39 | + pub unsafe extern "C" fn malloc(size: usize) -> *mut c_void { |
| 40 | + unsafe { libmimalloc_sys::mi_malloc(size) } |
| 41 | + } |
| 42 | + |
| 43 | + #[unsafe(no_mangle)] |
| 44 | + pub unsafe extern "C" fn realloc(ptr: *mut c_void, size: usize) -> *mut c_void { |
| 45 | + unsafe { libmimalloc_sys::mi_realloc(ptr, size) } |
| 46 | + } |
| 47 | + |
| 48 | + #[unsafe(no_mangle)] |
| 49 | + pub unsafe extern "C" fn free(ptr: *mut c_void) { |
| 50 | + unsafe { |
| 51 | + libmimalloc_sys::mi_free(ptr); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments