diff --git a/common/common.c b/common/common.c index 5e08c68..55fefa1 100644 --- a/common/common.c +++ b/common/common.c @@ -706,7 +706,11 @@ void *x264_malloc( int i_size ) /* Mac OS X always returns 16 bytes aligned memory */ return malloc( i_size ); #elif defined( HAVE_MALLOC_H ) +#ifdef SYS_MINGW + return __mingw_aligned_malloc( i_size, 16 ); +#else return memalign( 16, i_size ); +#endif #else uint8_t * buf; uint8_t * align_buf; @@ -728,7 +732,11 @@ void x264_free( void *p ) if( p ) { #if defined( HAVE_MALLOC_H ) || defined( SYS_MACOSX ) +#ifdef SYS_MINGW + __mingw_aligned_free( p ); +#else free( p ); +#endif #else free( *( ( ( void **) p ) - 1 ) ); #endif @@ -741,7 +749,11 @@ void x264_free( void *p ) void *x264_realloc( void *p, int i_size ) { #ifdef HAVE_MALLOC_H +#ifdef SYS_MINGW + return __mingw_aligned_realloc( p, i_size, 16 ); +#else return realloc( p, i_size ); +#endif #else int i_old_size = 0; uint8_t * p_new; diff --git a/common/osdep.h b/common/osdep.h index 25bb138..09c3535 100644 --- a/common/osdep.h +++ b/common/osdep.h @@ -64,6 +64,12 @@ #endif #endif +#ifdef MINGW64 +#define __mingw_aligned_free free +#define __mingw_aligned_malloc(s,a) malloc(s) +#define __mingw_aligned_realloc _aligned_realloc +#endif + #ifdef _MSC_VER #define DECLARE_ALIGNED( var, n ) __declspec(align(n)) var #else diff --git a/configure b/configure index eb51091..c37f68e 100755 --- a/configure +++ b/configure @@ -220,6 +220,7 @@ case $host_os in ;; mingw*) SYS="MINGW" + CFLAGS="$CFLAGS -DHAVE_MALLOC_H" EXE=".exe" DEVNULL="NUL" ;;