Skip to content

Commit 49c3827

Browse files
committed
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`.
2 parents cf8b1ce + 5657eef commit 49c3827

File tree

2 files changed

+7
-27
lines changed

2 files changed

+7
-27
lines changed

src/liballoc_system/lib.rs

+6-26
Original file line numberDiff line numberDiff line change
@@ -75,37 +75,17 @@ mod imp {
7575
use libc;
7676
use MIN_ALIGN;
7777

78-
extern "C" {
79-
// Apparently android doesn't have posix_memalign
80-
#[cfg(target_os = "android")]
81-
fn memalign(align: libc::size_t, size: libc::size_t) -> *mut libc::c_void;
82-
83-
#[cfg(not(target_os = "android"))]
84-
fn posix_memalign(memptr: *mut *mut libc::c_void,
85-
align: libc::size_t,
86-
size: libc::size_t)
87-
-> libc::c_int;
88-
}
89-
9078
pub unsafe fn allocate(size: usize, align: usize) -> *mut u8 {
9179
if align <= MIN_ALIGN {
9280
libc::malloc(size as libc::size_t) as *mut u8
9381
} else {
94-
#[cfg(target_os = "android")]
95-
unsafe fn more_aligned_malloc(size: usize, align: usize) -> *mut u8 {
96-
memalign(align as libc::size_t, size as libc::size_t) as *mut u8
97-
}
98-
#[cfg(not(target_os = "android"))]
99-
unsafe fn more_aligned_malloc(size: usize, align: usize) -> *mut u8 {
100-
let mut out = ptr::null_mut();
101-
let ret = posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
102-
if ret != 0 {
103-
ptr::null_mut()
104-
} else {
105-
out as *mut u8
106-
}
82+
let mut out = ptr::null_mut();
83+
let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
84+
if ret != 0 {
85+
ptr::null_mut()
86+
} else {
87+
out as *mut u8
10788
}
108-
more_aligned_malloc(size, align)
10989
}
11090
}
11191

src/liblibc

0 commit comments

Comments
 (0)