<html><head></head><body>Replacing, in autoconf sense, a function that exists nowhere, makes no sense. The autoconf test is a literal complete waste.<br><br><div class="gmail_quote">Le 20 juin 2017 13:20:13 GMT+03:00, Steve Lhomme <robux4@videolabs.io> a écrit :<blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt 0.8ex; border-left: 1px solid rgb(204, 204, 204); padding-left: 1ex;">
<pre class="k9mail">On Windows if you allocate aligned memory you need to free it with an aligned<br />version of free.<br /><br />This is similar to the old vlc_memalign() + vlc_free()<br />---<br /> compat/aligned_alloc.c         | 16 ++++++++++------<br /> compat/aligned_free.c          | 43 ++++++++++++++++++++++++++++++++++++++++++<br /> <a href="http://configure.ac">configure.ac</a>                   |  2 +-<br /> include/vlc_fixups.h           |  3 +++<br /> modules/video_chroma/copy.c    |  2 +-<br /> modules/video_filter/gradfun.c |  2 +-<br /> modules/video_output/evas.c    |  2 +-<br /> src/misc/picture.c             |  2 +-<br /> src/misc/picture_pool.c        |  2 +-<br /> 9 files changed, 62 insertions(+), 12 deletions(-)<br /> create mode 100644 compat/aligned_free.c<br /><br />diff --git a/compat/aligned_alloc.c b/compat/aligned_alloc.c<br />index 9ea352b0c5..28fad07f79 100644<br />--- a/compat/aligned_alloc.c<br />+++ b/compat/aligned_alloc.c<br />@@ -52,14 +52,18 @@ void *aligned_alloc(size_t align, size_t size)<br />     }<br />     return ptr;<br /> <br />-#elif !defined (_WIN32)<br />+#elif defined (_WIN32)<br />+#ifdef __MINGW32__<br />+    return __mingw_aligned_malloc(size, align);<br />+#elif defined(_MSC_VER)<br />+    return _aligned_malloc(size, align);<br />+#endif<br />+    if (size > 0)<br />+        errno = ENOMEM;<br />+    return NULL;<br />+#else<br /> <br />    return memalign(align, size);<br /> <br />-#else<br />-<br />-   if (size > 0)<br />-       errno = ENOMEM;<br />-   return NULL;<br /> #endif<br /> }<br />diff --git a/compat/aligned_free.c b/compat/aligned_free.c<br />new file mode 100644<br />index 0000000000..380125f20d<br />--- /dev/null<br />+++ b/compat/aligned_free.c<br />@@ -0,0 +1,43 @@<br />+/*****************************************************************************<br />+ * aligned_free.c: C11 aligned_alloc() replacement counterpart<br />+ *****************************************************************************<br />+ * Copyright © 2012, 2017 Steve Lhomme<br />+ *<br />+ * This program is free software; you can redistribute it and/or modify it<br />+ * under the terms of the GNU Lesser General Public License as published by<br />+ * the Free Software Foundation; either version 2.1 of the License, or<br />+ * (at your option) any later version.<br />+ *<br />+ * This program is distributed in the hope that it will be useful,<br />+ * but WITHOUT ANY WARRANTY; without even the implied warranty of<br />+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the<br />+ * GNU Lesser General Public License for more details.<br />+ *<br />+ * You should have received a copy of the GNU Lesser General Public License<br />+ * along with this program; if not, write to the Free Software Foundation,<br />+ * Inc., 51 Franklin Street, Fifth Floor, Boston MA 02110-1301, USA.<br />+ *****************************************************************************/<br />+<br />+#ifdef HAVE_CONFIG_H<br />+# include <config.h><br />+#endif<br />+<br />+#include <assert.h><br />+#include <stdlib.h><br />+#include <errno.h><br />+#if !defined (HAVE_POSIX_MEMALIGN) && !defined (_WIN32)<br />+# include <malloc.h><br />+#endif<br />+<br />+void aligned_free(void *ptr)<br />+{<br />+#if defined (_WIN32)<br />+#ifdef __MINGW32__<br />+    return __mingw_aligned_free(ptr);<br />+#elif defined(_MSC_VER)<br />+    return _aligned_free(ptr);<br />+#endif<br />+#else<br />+    free(ptr);<br />+#endif<br />+}<br />diff --git a/<a href="http://configure.ac">configure.ac</a> b/<a href="http://configure.ac">configure.ac</a><br />index 67fc7deb1a..633dd8a034 100644<br />--- a/<a href="http://configure.ac">configure.ac</a><br />+++ b/<a href="http://configure.ac">configure.ac</a><br />@@ -598,7 +598,7 @@ need_libc=false<br /> <br /> dnl Check for usual libc functions<br /> AC_CHECK_FUNCS([daemon fcntl flock fstatvfs fork getenv getpwuid_r isatty lstat memalign mkostemp mmap open_memstream openat pread posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp strptime tdestroy uselocale])<br />-AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tfind timegm timespec_get strverscmp pathconf])<br />+AC_REPLACE_FUNCS([aligned_alloc aligned_free atof atoll dirfd fdopendir ffsll flockfile fsync getdelim getpid lldiv memrchr nrand48 poll recvmsg rewind sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr strsep strtof strtok_r strtoll swab tfind timegm timespec_get strverscmp pathconf])<br /> AC_REPLACE_FUNCS([gettimeofday])<br /> AC_CHECK_FUNC(fdatasync,,<br />   [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if missing.])<br />diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h<br />index 44b8426f2c..7037fe2f85 100644<br />--- a/include/vlc_fixups.h<br />+++ b/include/vlc_fixups.h<br />@@ -305,6 +305,9 @@ int unsetenv (const char *);<br /> #ifndef HAVE_ALIGNED_ALLOC<br /> void *aligned_alloc(size_t, size_t);<br /> #endif<br />+#ifndef HAVE_ALIGNED_FREE<br />+void aligned_free(void*);<br />+#endif<br /> <br /> #if defined(__native_client__) && defined(__cplusplus)<br /> # define HAVE_USELOCALE<br />diff --git a/modules/video_chroma/copy.c b/modules/video_chroma/copy.c<br />index 4bc2e91c45..6c20c132b0 100644<br />--- a/modules/video_chroma/copy.c<br />+++ b/modules/video_chroma/copy.c<br />@@ -49,7 +49,7 @@ int CopyInitCache(copy_cache_t *cache, unsigned width)<br /> void CopyCleanCache(copy_cache_t *cache)<br /> {<br /> #ifdef CAN_COMPILE_SSE2<br />-    free(cache->buffer);<br />+    aligned_free(cache->buffer);<br />     cache->buffer = NULL;<br />     cache->size   = 0;<br /> #else<br />diff --git a/modules/video_filter/gradfun.c b/modules/video_filter/gradfun.c<br />index 317c604f7b..8ebb95d0aa 100644<br />--- a/modules/video_filter/gradfun.c<br />+++ b/modules/video_filter/gradfun.c<br />@@ -168,7 +168,7 @@ static void Close(vlc_object_t *object)<br /> <br />     var_DelCallback(filter, CFG_PREFIX "radius",   Callback, NULL);<br />     var_DelCallback(filter, CFG_PREFIX "strength", Callback, NULL);<br />-    free(sys->cfg.buf);<br />+    aligned_free(sys->cfg.buf);<br />     vlc_mutex_destroy(&sys->lock);<br />     free(sys);<br /> }<br />diff --git a/modules/video_output/evas.c b/modules/video_output/evas.c<br />index 348a681de3..d31d4b7ca6 100644<br />--- a/modules/video_output/evas.c<br />+++ b/modules/video_output/evas.c<br />@@ -951,7 +951,7 @@ EvasImageBuffersFree( vout_display_t *vd )<br />     vout_display_sys_t *sys = vd->sys;<br /> <br />     for( unsigned int i = 0; i < sys->i_nb_buffers; i++ )<br />-        free( sys->p_buffers[i].p[0] );<br />+        align_free( sys->p_buffers[i].p[0] );<br />     free( sys->p_buffers );<br />     sys->p_buffers = NULL;<br />     sys->i_nb_buffers = 0;<br />diff --git a/src/misc/picture.c b/src/misc/picture.c<br />index 3bac926714..7c170f0fba 100644<br />--- a/src/misc/picture.c<br />+++ b/src/misc/picture.c<br />@@ -110,7 +110,7 @@ static void picture_DestroyFromResource( picture_t *p_picture )<br />  */<br /> static void picture_Destroy( picture_t *p_picture )<br /> {<br />-    free( p_picture->p[0].p_pixels );<br />+    aligned_free( p_picture->p[0].p_pixels );<br />     free( p_picture );<br /> }<br /> <br />diff --git a/src/misc/picture_pool.c b/src/misc/picture_pool.c<br />index 0c5ea39822..17bf3b7b82 100644<br />--- a/src/misc/picture_pool.c<br />+++ b/src/misc/picture_pool.c<br />@@ -58,7 +58,7 @@ static void picture_pool_Destroy(picture_pool_t *pool)<br /> <br />     vlc_cond_destroy(&pool->wait);<br />     vlc_mutex_destroy(&pool->lock);<br />-    free(pool);<br />+    aligned_free(pool);<br /> }<br /> <br /> void picture_pool_Release(picture_pool_t *pool)</pre></blockquote></div><br>
-- <br>
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>