mem: add support for __mingw_aligned_malloc()

Message ID 1340048029-21985-1-git-send-email-martin@martin.st
State New
Headers show

Commit Message

Martin Storsjö June 18, 2012, 7:33 p.m.
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(-)

Comments

Mans Rullgard June 18, 2012, 7:42 p.m. | #1
Martin Storsjö <martin@martin.st> writes:

> 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(-)

The question is, do we care about msvcrt versions that don't have
_aligned_malloc?  If not, selecting a recent enough msvcrt version (by
adding the appropriate -D flag) achieves the same goal without the
clutter.
Martin Storsjö June 18, 2012, 7:54 p.m. | #2
On Mon, 18 Jun 2012, Måns Rullgård wrote:

> Martin Storsjö <martin@martin.st> writes:
>
>> 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(-)
>
> The question is, do we care about msvcrt versions that don't have
> _aligned_malloc?  If not, selecting a recent enough msvcrt version (by
> adding the appropriate -D flag) achieves the same goal without the
> clutter.

That's a valid point.

I checked, and it doesn't seem to be present in the Win2k version of 
msvcrt.dll, and I think we still run on that platform.

// Martin
Mans Rullgard June 18, 2012, 8:04 p.m. | #3
Martin Storsjö <martin@martin.st> writes:

> On Mon, 18 Jun 2012, Måns Rullgård wrote:
>
>> Martin Storsjö <martin@martin.st> writes:
>>
>>> 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(-)
>>
>> The question is, do we care about msvcrt versions that don't have
>> _aligned_malloc?  If not, selecting a recent enough msvcrt version (by
>> adding the appropriate -D flag) achieves the same goal without the
>> clutter.
>
> That's a valid point.
>
> I checked, and it doesn't seem to be present in the Win2k version of
> msvcrt.dll, and I think we still run on that platform.

Maybe it's time to drop win2k support.  Does anyone actually still use it?
Derek Buitenhuis June 18, 2012, 8:05 p.m. | #4
On 18/06/2012 4:04 PM, Måns Rullgård wrote:
> Maybe it's time to drop win2k support.  Does anyone actually still use it?

I think we should. MS doesn't even support it anymore. If someone
is using it, they're already using unpatched and unsupported
software.

- Derek
Sean McGovern June 18, 2012, 8:20 p.m. | #5
On Monday, June 18, 2012, Derek Buitenhuis <derek.buitenhuis@gmail.com>
wrote:
> On 18/06/2012 4:04 PM, Måns Rullgård wrote:
>> Maybe it's time to drop win2k support.  Does anyone actually still use
it?
>
> I think we should. MS doesn't even support it anymore. If someone
> is using it, they're already using unpatched and unsupported
> software.

Aye, extended support for Win2K ended in 2005.

-- Sean McG.
Diego Biurrun June 19, 2012, 9:06 a.m. | #6
On Mon, Jun 18, 2012 at 04:20:53PM -0400, Sean McGovern wrote:
> On Monday, June 18, 2012, Derek Buitenhuis <derek.buitenhuis@gmail.com>
> wrote:
> > On 18/06/2012 4:04 PM, Måns Rullgård wrote:
> >> Maybe it's time to drop win2k support.  Does anyone actually still use
> it?
> >
> > I think we should. MS doesn't even support it anymore. If someone
> > is using it, they're already using unpatched and unsupported
> > software.
> 
> Aye, extended support for Win2K ended in 2005.

So let's settle on XP as required baseline.

Diego

Patch

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