<html><head></head><body>Repeating myself but this patch does not change the fallback logic, so it can't break anything.<br>
<br>
And to paraphrase other devs "I don't care" about non-ISO toolchains.<br><br><div class="gmail_quote">Le 20 juin 2017 12:40:41 GMT+03:00, Steve Lhomme <robux4@gmail.com> 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 Tue, Jun 20, 2017 at 11:35 AM, Steve Lhomme <robux4@gmail.com> wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> On Tue, Jun 20, 2017 at 11:28 AM, <remi@remlab.net> wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"> The goal is to use aligned_alloc() instead of posix_memalign() since the<br /> earlier is required by ISO C and C++ (and slightly simpler to use).<br /><br /> This patch only changes the behaviour on supported non-POSIX toolchains by<br /> removing the need for POSIX emulation code. If the toolchain is broken, then<br /> the fallback logic is unchanged: posix_memalign(), else memalign() else<br /> screw-you.<br /></blockquote><br /> There is no posix_memalign() or memalign() on Windows. So right now<br /> VLC and libvlc cannot be used at all.<br /><br /> Proper support requires using __mingw_aligned_malloc() or<br /> _aligned_malloc(). But that means using __mingw_aligned_free() and<br /> _aligned_free() as well.<br /></blockquote><br />For the record, calling free() instead of these aligned free functions<br />results in a crash.<br /><br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #729fcf; padding-left: 1ex;"> Next time you may break the core, please submit patches for review first.<br /><br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #ad7fa8; padding-left: 1ex;"> Le 20 juin 2017 12:07:38 GMT+03:00, Steve Lhomme <robux4@gmail.com> a écrit<br /> :<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #8ae234; padding-left: 1ex;"><br /> On Sat, Jun 17, 2017 at 2:35 PM, Rémi Denis-Courmont <git@videolan.org><br /> wrote:<br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"><br /> vlc | branch: master | Rémi Denis-Courmont <remi@remlab.net> | Sat Jun<br /> 17 15:27:16 2017 +0300| [34cd965645cb0246f3d74515bbd5e55367f7d884] |<br /> committer: Rémi Denis-Courmont<br /><br /> compat: replace aligned_alloc() rather than posix_memalign()<br /><br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #e9b96e; padding-left: 1ex;"><br /> <a href="http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=34cd965645cb0246f3d74515bbd5e55367f7d884">http://git.videolan.org/gitweb.cgi/vlc.git/?a=commit;h=34cd965645cb0246f3d74515bbd5e55367f7d884</a><br /></blockquote><br /> ---<br /><br /> compat/{posix_memalign.c => aligned_alloc.c} | 62<br /> ++++++++++++++--------------<br /> <a href="http://configure.ac">configure.ac</a> | 4 +-<br /> include/vlc_common.h | 8 +---<br /> include/vlc_fixups.h | 6 +--<br /> 4 files changed, 36 insertions(+), 44 deletions(-)<br /><br /> diff --git a/compat/posix_memalign.c b/compat/aligned_alloc.c<br /> similarity index 55%<br /> rename from compat/posix_memalign.c<br /> rename to compat/aligned_alloc.c<br /> index 3c6ffdfe28..9a61c0010f 100644<br /> --- a/compat/posix_memalign.c<br /> +++ b/compat/aligned_alloc.c<br /> @@ -1,7 +1,7 @@<br /><br /> /*****************************************************************************<br /> - * posix_memalign.c: POSIX posix_memalign() replacement<br /> + * aligned_alloc.c: C11 aligned_alloc() replacement<br /><br /> *****************************************************************************<br /> - * Copyright © 2012 Rémi Denis-Courmont<br /> + * Copyright © 2012, 2017 Rémi Denis-Courmont<br /> *<br /> * This program is free software; you can redistribute it and/or modify<br /> it<br /> * under the terms of the GNU Lesser General Public License as<br /> published by<br /> @@ -22,46 +22,44 @@<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) && !defined<br /> (__APPLE__)<br /> +# include <malloc.h><br /> +#endif<br /><br /> -static int check_align (size_t align)<br /> +void *aligned_alloc(size_t align, size_t size)<br /> {<br /> - for (size_t i = sizeof (void *); i != 0; i *= 2)<br /> - if (align == i)<br /> - return 0;<br /> - return EINVAL;<br /> -}<br /> -<br /> -#if !defined (_WIN32) && !defined (__APPLE__)<br /> -#include <malloc.h><br /> + /* align must be a power of 2 */<br /> + /* size must be a multiple of align */<br /> + if ((align & (align - 1)) || (size & (align - 1)))<br /> + {<br /> + errno = EINVAL;<br /> + return NULL;<br /> + }<br /><br /> -int posix_memalign (void **ptr, size_t align, size_t size)<br /> -{<br /> - if (check_align (align))<br /> - return EINVAL;<br /> +#ifdef HAVE_POSIX_MEMALIGN<br /> + if (align < sizeof (void *)) /* POSIX does not allow small<br /> alignment */<br /> + align = sizeof (void *);<br /><br /> - int saved_errno = errno;<br /> - void *p = memalign (align, size);<br /> - if (p == NULL)<br /> + void *ptr;<br /> + int err = posix_memalign(&ptr, align, size);<br /> + if (err)<br /> {<br /> - errno = saved_errno;<br /> - return ENOMEM;<br /> + errno = err;<br /> + ptr = NULL;<br /> }<br /> + return ptr;<br /><br /> - *ptr = p;<br /> - return 0;<br /> -}<br /> +#elif !defined (_WIN32) && !defined (__APPLE__)<br /><br /> -#else<br /> -<br /> -int posix_memalign (void **ptr, size_t align, size_t size)<br /> -{<br /> - if (check_align (align))<br /> - return EINVAL;<br /> + return memalign(align, size);<br /></blockquote><br /><br /> Is the goal that this code is never called for Windows and Apple OSes<br /> ? Because it worked and this function always return NULL.<br /><br /><blockquote class="gmail_quote" style="margin: 0pt 0pt 1ex 0.8ex; border-left: 1px solid #fcaf3e; padding-left: 1ex;"> - *ptr = NULL;<br /> - return size ? ENOMEM : 0;<br /> -}<br /> +#else<br /><br /> + if (size > 0)<br /> + errno = ENOMEM;<br /> + return NULL;<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 b1883a18b7..67fc7deb1a 100644<br /> --- a/<a href="http://configure.ac">configure.ac</a><br /> +++ b/<a href="http://configure.ac">configure.ac</a><br /> @@ -597,8 +597,8 @@ dnl Check for system libs needed<br /> need_libc=false<br /><br /> dnl Check for usual libc functions<br /> -AC_CHECK_FUNCS([daemon fcntl flock fstatvfs fork getenv getpwuid_r<br /> isatty lstat memalign mkostemp mmap open_memstream openat pread<br /> posix_fadvise posix_madvise setlocale stricmp strnicmp strptime tdestroy<br /> uselocale])<br /> -AC_REPLACE_FUNCS([atof atoll dirfd fdopendir ffsll flockfile fsync<br /> getdelim getpid lldiv memrchr nrand48 poll posix_memalign recvmsg rewind<br /> sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr<br /> strsep strtof strtok_r strtoll swab tfind timegm timespec_get strverscmp<br /> pathconf])<br /> +AC_CHECK_FUNCS([daemon fcntl flock fstatvfs fork getenv getpwuid_r<br /> isatty lstat memalign mkostemp mmap open_memstream openat pread<br /> posix_fadvise posix_madvise posix_memalign setlocale stricmp strnicmp<br /> strptime tdestroy uselocale])<br /> +AC_REPLACE_FUNCS([aligned_alloc atof atoll dirfd fdopendir ffsll<br /> flockfile fsync getdelim getpid lldiv memrchr nrand48 poll recvmsg rewind<br /> sendmsg setenv strcasecmp strcasestr strdup strlcpy strndup strnlen strnstr<br /> strsep strtof strtok_r strtoll swab tfind timegm timespec_get strverscmp<br /> pathconf])<br /> AC_REPLACE_FUNCS([gettimeofday])<br /> AC_CHECK_FUNC(fdatasync,,<br /> [AC_DEFINE(fdatasync, fsync, [Alias fdatasync() to fsync() if<br /> missing.])<br /> diff --git a/include/vlc_common.h b/include/vlc_common.h<br /> index e1cf885379..0bfb1b9b04 100644<br /> --- a/include/vlc_common.h<br /> +++ b/include/vlc_common.h<br /> @@ -854,13 +854,7 @@ VLC_API bool vlc_ureduce( unsigned *, unsigned *,<br /> uint64_t, uint64_t, uint64_t )<br /> # define vlc_memalign(align, size) (_aligned_malloc(size, align))<br /> # define vlc_free(base) (_aligned_free(base))<br /> #else<br /> -static inline void *vlc_memalign(size_t align, size_t size)<br /> -{<br /> - void *base;<br /> - if (unlikely(posix_memalign(&base, align, size)))<br /> - base = NULL;<br /> - return base;<br /> -}<br /> +# define vlc_memalign(align, size) aligned_alloc(align, size)<br /> # define vlc_free(base) free(base)<br /> #endif<br /><br /> diff --git a/include/vlc_fixups.h b/include/vlc_fixups.h<br /> index 8bfb76888f..44b8426f2c 100644<br /> --- a/include/vlc_fixups.h<br /> +++ b/include/vlc_fixups.h<br /> @@ -88,7 +88,7 @@ typedef struct<br /> # include <stdio.h> /* FILE */<br /> #endif<br /><br /> -#if !defined (HAVE_POSIX_MEMALIGN) || \<br /> +#if !defined (HAVE_ALIGNED_ALLOC) || \<br /> !defined (HAVE_MEMRCHR) || \<br /> !defined (HAVE_STRLCPY) || \<br /> !defined (HAVE_STRNDUP) || \<br /> @@ -302,8 +302,8 @@ int setenv (const char *, const char *, int);<br /> int unsetenv (const char *);<br /> #endif<br /><br /> -#ifndef HAVE_POSIX_MEMALIGN<br /> -int posix_memalign (void **, size_t, size_t);<br /> +#ifndef HAVE_ALIGNED_ALLOC<br /> +void *aligned_alloc(size_t, size_t);<br /> #endif<br /><br /> #if defined(__native_client__) && defined(__cplusplus)<br /><br /><hr /><br /><br /> vlc-commits mailing list<br /> vlc-commits@videolan.org<br /> <a href="https://mailman.videolan.org/listinfo/vlc-commits">https://mailman.videolan.org/listinfo/vlc-commits</a><br /></blockquote><br /><hr /><br /><br /> vlc-devel mailing list<br /> To unsubscribe or modify your subscription options:<br /> <a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br /></blockquote><br /><br /> --<br /> Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma<br /> brièveté.<br /><br /><hr /><br /> vlc-devel mailing list<br /> To unsubscribe or modify your subscription options:<br /> <a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a><br /></blockquote></blockquote><hr /><br />vlc-devel mailing list<br />To unsubscribe or modify your subscription options:<br /><a href="https://mailman.videolan.org/listinfo/vlc-devel">https://mailman.videolan.org/listinfo/vlc-devel</a></pre></blockquote></div><br>
-- <br>
Envoyé de mon appareil Android avec Courriel K-9 Mail. Veuillez excuser ma brièveté.</body></html>