This function is like _aligned_malloc(), but part of the statically
linked mingw runtime, so it's available regardless of the targeted
MSVCRT version.
---
 configure       |    4 +++-
 libavutil/mem.c |    6 ++++++
 2 files changed, 9 insertions(+), 1 deletion(-)

diff --git a/configure b/configure
index 0baa755..16cadd5 100755
--- a/configure
+++ b/configure
@@ -1109,6 +1109,7 @@ HAVE_LIST="
     malloc_h
     MapViewOfFile
     memalign
+    mingw_aligned_malloc
     mkstemp
     mmap
     netinet_sctp_h
@@ -2840,6 +2841,7 @@ check_func  mkstemp
 check_func  mmap
 check_func  ${malloc_prefix}posix_memalign      && enable posix_memalign
 check_func_headers malloc.h _aligned_malloc     && enable aligned_malloc
+check_func  __mingw_aligned_malloc              && enable mingw_aligned_malloc
 check_func  setrlimit
 check_func  strerror_r
 check_func  strptime
@@ -3146,7 +3148,7 @@ check_deps $CONFIG_LIST       \
 
 enabled asm || { arch=c; disable $ARCH_LIST $ARCH_EXT_LIST; }
 
-! enabled_any memalign posix_memalign aligned_malloc &&
+! enabled_any memalign posix_memalign aligned_malloc mingw_aligned_malloc &&
     enabled_any $need_memalign && enable memalign_hack
 
 echo "install prefix            $prefix"
diff --git a/libavutil/mem.c b/libavutil/mem.c
index 0fe9f54..79fb179 100644
--- a/libavutil/mem.c
+++ b/libavutil/mem.c
@@ -86,6 +86,8 @@ void *av_malloc(size_t size)
         ptr = NULL;
 #elif HAVE_ALIGNED_MALLOC
     ptr = _aligned_malloc(size, 32);
+#elif HAVE_MINGW_ALIGNED_MALLOC
+    ptr = __mingw_aligned_malloc(size, 32);
 #elif HAVE_MEMALIGN
     ptr = memalign(32,size);
     /* Why 64?
@@ -135,6 +137,8 @@ void *av_realloc(void *ptr, size_t size)
     return (char*)realloc((char*)ptr - diff, size + diff) + diff;
 #elif HAVE_ALIGNED_MALLOC
     return _aligned_realloc(ptr, size, 32);
+#elif HAVE_MINGW_ALIGNED_MALLOC
+    return __mingw_aligned_realloc(ptr, size, 32);
 #else
     return realloc(ptr, size);
 #endif
@@ -147,6 +151,8 @@ void av_free(void *ptr)
         free((char*)ptr - ((char*)ptr)[-1]);
 #elif HAVE_ALIGNED_MALLOC
     _aligned_free(ptr);
+#elif HAVE_MINGW_ALIGNED_MALLOC
+    __mingw_aligned_free(ptr);
 #else
     free(ptr);
 #endif
-- 
1.7.9.4

_______________________________________________
libav-devel mailing list
[email protected]
https://lists.libav.org/mailman/listinfo/libav-devel

Reply via email to