Message ID | 1487095010.5165.4.camel@linux.vnet.ibm.com |
---|---|
State | New |
Headers | show |
On Tue, Feb 14, 2017 at 11:56:50AM -0600, Aaron Sawdey wrote: > This testcase I added failed to compile on AIX or older linux due to > the use of aligned_alloc(). Now fixed to use posix_memalign if > available, and valloc otherwise. > > Now it compiles and passes on x86_64 (fedora 25), ppc64 (RHEL6.8), and > AIX. OK for trunk? Is valloc preferable to aligned_alloc on all systems where posix_memalign does not exist? Okay for trunk if so. Thanks, Segher > 2017-02-14 Aaron Sawdey <acsawdey@linux.vnet.ibm.com> > > * gcc.dg/strncmp-2.c: Portability fixes.
On Tue, 2017-02-14 at 13:09 -0600, Segher Boessenkool wrote: > On Tue, Feb 14, 2017 at 11:56:50AM -0600, Aaron Sawdey wrote: > > This testcase I added failed to compile on AIX or older linux due > > to > > the use of aligned_alloc(). Now fixed to use posix_memalign if > > available, and valloc otherwise. > > > > Now it compiles and passes on x86_64 (fedora 25), ppc64 (RHEL6.8), > > and > > AIX. OK for trunk? > > Is valloc preferable to aligned_alloc on all systems where > posix_memalign > does not exist? Okay for trunk if so. Thanks, > > > Segher My reasoning here was to use the modern function (posix_memalign) if available and otherwise fall back to valloc which is in glibc dating back to 1996 and openbsd's man page says it was added in BSD 3.0 so pretty much anything should have it. Thanks, Aaron > > > > 2017-02-14 Aaron Sawdey <acsawdey@linux.vnet.ibm.com> > > > > * gcc.dg/strncmp-2.c: Portability fixes. > >
On Tue, Feb 14, 2017 at 2:24 PM, Aaron Sawdey <acsawdey@linux.vnet.ibm.com> wrote: > On Tue, 2017-02-14 at 13:09 -0600, Segher Boessenkool wrote: >> On Tue, Feb 14, 2017 at 11:56:50AM -0600, Aaron Sawdey wrote: >> > This testcase I added failed to compile on AIX or older linux due >> > to >> > the use of aligned_alloc(). Now fixed to use posix_memalign if >> > available, and valloc otherwise. >> > >> > Now it compiles and passes on x86_64 (fedora 25), ppc64 (RHEL6.8), >> > and >> > AIX. OK for trunk? >> >> Is valloc preferable to aligned_alloc on all systems where >> posix_memalign >> does not exist? Okay for trunk if so. Thanks, >> >> >> Segher > > My reasoning here was to use the modern function (posix_memalign) if > available and otherwise fall back to valloc which is in glibc dating > back to 1996 and openbsd's man page says it was added in BSD 3.0 so > pretty much anything should have it. Recent AIX does provide aligned_alloc() and posix_memalign(). - David
Index: strncmp-2.c =================================================================== --- strncmp-2.c (revision 245439) +++ strncmp-2.c (working copy) @@ -19,7 +19,12 @@ { long pgsz = sysconf(_SC_PAGESIZE); char buf1[sz+1]; - char *buf2 = aligned_alloc(pgsz,2*pgsz); + char *buf2; +#if _POSIX_C_SOURCE >= 200112L + if ( posix_memalign ((void **)&buf2, pgsz, 2*pgsz) ) abort (); +#else + if ( !(buf2 = valloc(2*pgsz))) abort (); +#endif char *p2; int r,i,e; @@ -35,6 +40,7 @@ e = lib_memcmp(buf1,p2,sz); (*test_memcmp)(buf1,p2,e); } + free(buf2); } #define RUN_TEST(SZ) test_driver_strncmp (test_strncmp_ ## SZ, test_memcmp_ ## SZ, SZ);