Auto merge of #30601 - tamird:delegate-libc, r=alexcrichton
See: http://developer.android.com/ndk/downloads/revision_history.html Also, use `libc`'s `posix_memalign`.
This commit is contained in:
commit
49c3827790
|
@ -75,38 +75,18 @@ mod imp {
|
||||||
use libc;
|
use libc;
|
||||||
use MIN_ALIGN;
|
use MIN_ALIGN;
|
||||||
|
|
||||||
extern "C" {
|
|
||||||
// Apparently android doesn't have posix_memalign
|
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
fn memalign(align: libc::size_t, size: libc::size_t) -> *mut libc::c_void;
|
|
||||||
|
|
||||||
#[cfg(not(target_os = "android"))]
|
|
||||||
fn posix_memalign(memptr: *mut *mut libc::c_void,
|
|
||||||
align: libc::size_t,
|
|
||||||
size: libc::size_t)
|
|
||||||
-> libc::c_int;
|
|
||||||
}
|
|
||||||
|
|
||||||
pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {
|
pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {
|
||||||
if align <= MIN_ALIGN {
|
if align <= MIN_ALIGN {
|
||||||
libc::malloc(size as libc::size_t) as *mut u8
|
libc::malloc(size as libc::size_t) as *mut u8
|
||||||
} else {
|
} else {
|
||||||
#[cfg(target_os = "android")]
|
|
||||||
unsafe fn more_aligned_malloc(size: usize, align: usize) -> *mut u8 {
|
|
||||||
memalign(align as libc::size_t, size as libc::size_t) as *mut u8
|
|
||||||
}
|
|
||||||
#[cfg(not(target_os = "android"))]
|
|
||||||
unsafe fn more_aligned_malloc(size: usize, align: usize) -> *mut u8 {
|
|
||||||
let mut out = ptr::null_mut();
|
let mut out = ptr::null_mut();
|
||||||
let ret = posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
|
let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
|
||||||
if ret != 0 {
|
if ret != 0 {
|
||||||
ptr::null_mut()
|
ptr::null_mut()
|
||||||
} else {
|
} else {
|
||||||
out as *mut u8
|
out as *mut u8
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
more_aligned_malloc(size, align)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 {
|
pub unsafe fn reallocate(ptr: *mut u8, old_size: usize, size: usize, align: usize) -> *mut u8 {
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit e0c0bf439add63a6a25a25ba47e4aec9547bf9af
|
Subproject commit 95d6a00134f284e6b889d98f4c2cb4b285950327
|
Loading…
Reference in New Issue