about summary refs log tree commit diff
path: root/src/liballoc_system
diff options
context:
space:
mode:
authorTamir Duberstein <tamird@gmail.com>2015-12-28 20:04:20 -0500
committerTamir Duberstein <tamird@gmail.com>2016-01-12 15:04:59 -0500
commit5657eefcd8f976e2558d8eae47e73ddb2119ccba (patch)
treee52353f3b9ceb2b7b1f19b5bf26efddaaa882a91 /src/liballoc_system
parent7cffc9b1951f5e51ad19bf3b854f7afa8073aadb (diff)
downloadrust-5657eefcd8f976e2558d8eae47e73ddb2119ccba.tar.gz
rust-5657eefcd8f976e2558d8eae47e73ddb2119ccba.zip
android has `posix_memalign` for API 16+ since NDK r10d
See: http://developer.android.com/ndk/downloads/revision_history.html

Also, use `libc`'s `posix_memalign`.
Diffstat (limited to 'src/liballoc_system')
-rw-r--r--src/liballoc_system/lib.rs32
1 files changed, 6 insertions, 26 deletions
diff --git a/src/liballoc_system/lib.rs b/src/liballoc_system/lib.rs
index fccc024603e..a4e98e413bb 100644
--- a/src/liballoc_system/lib.rs
+++ b/src/liballoc_system/lib.rs
@@ -75,37 +75,17 @@ mod imp {
     use libc;
     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 {
         if align <= MIN_ALIGN {
             libc::malloc(size as libc::size_t) as *mut u8
         } 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 ret = posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
-                if ret != 0 {
-                    ptr::null_mut()
-                } else {
-                    out as *mut u8
-                }
+            let mut out = ptr::null_mut();
+            let ret = libc::posix_memalign(&mut out, align as libc::size_t, size as libc::size_t);
+            if ret != 0 {
+                ptr::null_mut()
+            } else {
+                out as *mut u8
             }
-            more_aligned_malloc(size, align)
         }
     }