Skip to content
Snippets Groups Projects

allow builds on systems without a supported aligned allocation function

Open Joey Reinhart requested to merge Un1q32/dav1d:master into master
+ 9
2
@@ -101,15 +101,22 @@ static inline void *dav1d_alloc_aligned_internal(const size_t sz, const size_t a
// must be an integral multiple of alignment.
return aligned_alloc(align, ROUND_UP(sz, align));
#else
#error No aligned allocation functions are available
void *const buf = malloc(sz + align + sizeof(void *));
if (!buf) return NULL;
void *const ptr = (void *)(((uintptr_t)buf + sizeof(void *) + align - 1) & ~(align - 1));
((void **)ptr)[-1] = buf;
return ptr;
#endif
}
static inline void dav1d_free_aligned_internal(void *ptr) {
#ifdef _WIN32
_aligned_free(ptr);
#else
#elif HAVE_POSIX_MEMALIGN || HAVE_MEMALIGN || HAVE_ALIGNED_ALLOC
free(ptr);
#else
if (ptr) free(((void **)ptr)[-1]);
#endif
}
Loading