ref: 8e5f126f8fd53f7385afb71e74ca8786efcf8971
parent: 03d59ea50c9bae3fcb3f3224b3e60ab9c97e2ddb
author: Janne Grunau <[email protected]>
date: Thu Nov 1 18:53:18 EDT 2018
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
--- a/include/common/mem.h
+++ b/include/common/mem.h
@@ -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 @@
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 @@
free(ptr);
#elif defined(HAVE_ALIGNED_MALLOC)
_aligned_free(ptr);
+#elif defined(HAVE_MEMALIGN)
+ free(ptr);
#endif
}
--- a/meson.build
+++ b/meson.build
@@ -130,6 +130,8 @@
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