Commit 8e5f126f authored by Janne Grunau's avatar Janne Grunau

mem: use memalign as fallback for posix_memalign and _aligned_malloc

posix_memalign is not available in Android <= 4.1 (API level 16 and
below). Fixes #140
parent 03d59ea5
...@@ -31,7 +31,7 @@ ...@@ -31,7 +31,7 @@
#include <assert.h> #include <assert.h>
#include <stdlib.h> #include <stdlib.h>
#ifdef HAVE_ALIGNED_MALLOC #if defined(HAVE_ALIGNED_MALLOC) || defined(HAVE_MEMALIGN)
#include <malloc.h> #include <malloc.h>
#endif #endif
...@@ -47,6 +47,8 @@ static inline void *dav1d_alloc_aligned(size_t sz, size_t align) { ...@@ -47,6 +47,8 @@ static inline void *dav1d_alloc_aligned(size_t sz, size_t align) {
return ptr; return ptr;
#elif defined(HAVE_ALIGNED_MALLOC) #elif defined(HAVE_ALIGNED_MALLOC)
return _aligned_malloc(sz, align); return _aligned_malloc(sz, align);
#elif defined(HAVE_MEMALIGN)
return memalign(align, sz);
#else #else
#error Missing aligned alloc implementation #error Missing aligned alloc implementation
#endif #endif
...@@ -57,6 +59,8 @@ static inline void dav1d_free_aligned(void* ptr) { ...@@ -57,6 +59,8 @@ static inline void dav1d_free_aligned(void* ptr) {
free(ptr); free(ptr);
#elif defined(HAVE_ALIGNED_MALLOC) #elif defined(HAVE_ALIGNED_MALLOC)
_aligned_free(ptr); _aligned_free(ptr);
#elif defined(HAVE_MEMALIGN)
free(ptr);
#endif #endif
} }
......
...@@ -130,6 +130,8 @@ if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test ...@@ -130,6 +130,8 @@ if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test
cdata.set('HAVE_POSIX_MEMALIGN', 1) cdata.set('HAVE_POSIX_MEMALIGN', 1)
elif cc.has_function('_aligned_malloc', prefix : '#include <malloc.h>', args : test_args) elif cc.has_function('_aligned_malloc', prefix : '#include <malloc.h>', args : test_args)
cdata.set('HAVE_ALIGNED_MALLOC', 1) cdata.set('HAVE_ALIGNED_MALLOC', 1)
elif cc.has_function('memalign', prefix : '#include <malloc.h>', args : test_args)
cdata.set('HAVE_MEMALIGN', 1)
endif endif
if (host_machine.cpu_family() == 'aarch64' or if (host_machine.cpu_family() == 'aarch64' or
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment