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
Pipeline #1684 passed with stages
in 2 minutes and 59 seconds
......@@ -31,7 +31,7 @@
#include <assert.h>
#include <stdlib.h>
#ifdef HAVE_ALIGNED_MALLOC
#if defined(HAVE_ALIGNED_MALLOC) || defined(HAVE_MEMALIGN)
#include <malloc.h>
#endif
......@@ -47,6 +47,8 @@ static inline void *dav1d_alloc_aligned(size_t sz, size_t align) {
return ptr;
#elif defined(HAVE_ALIGNED_MALLOC)
return _aligned_malloc(sz, align);
#elif defined(HAVE_MEMALIGN)
return memalign(align, sz);
#else
#error Missing aligned alloc implementation
#endif
......@@ -57,6 +59,8 @@ static inline void dav1d_free_aligned(void* ptr) {
free(ptr);
#elif defined(HAVE_ALIGNED_MALLOC)
_aligned_free(ptr);
#elif defined(HAVE_MEMALIGN)
free(ptr);
#endif
}
......
......@@ -130,6 +130,8 @@ if cc.has_function('posix_memalign', prefix : '#include <stdlib.h>', args : test
cdata.set('HAVE_POSIX_MEMALIGN', 1)
elif cc.has_function('_aligned_malloc', prefix : '#include <malloc.h>', args : test_args)
cdata.set('HAVE_ALIGNED_MALLOC', 1)
elif cc.has_function('memalign', prefix : '#include <malloc.h>', args : test_args)
cdata.set('HAVE_MEMALIGN', 1)
endif
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