tech-userlevel archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
Re: aligned_alloc c11 function
On Sat, 24 Oct 2015 21:43:36 +0000 (UTC)
christos%astron.com@localhost (Christos Zoulas) wrote:
> >void *
> >aligned_alloc(size_t alignment, size_t size)
> >{
> > void *memptr;
> > int err = 0;
>
> Overinitialization.
Fixed.
>
> >
> > /*
> > * Check that size is an integer multiple of alignment
> > * using n mod m. (n-1 & n) equals 0 is n is a power of 2.
> > * (n mod m) equals (n & m-1) when m is a power of 2.
> > * Since alignment must be a power of 2 we can use this
> > instead
> > * of size % alignment != 0.
> > */
> >
> > if (((alignment - 1) & alignment) != 0 ||
> > (size & (alignment-1)) != 0) {
>
> Whitespace.
Fixed.
>
> > errno = EINVAL;
> > return NULL;
> > }
> >
> > err = posix_memalign(&memptr, alignment, size);
> >
> > if (err) {
> > errno = err;
> > return NULL;
> > }
> >
> > return memptr;
> >}
> >+ATF_TC_BODY(aligned_alloc_basic, tc)
> >+{
> >+ size_t size[] = {
> >+ 1, 2, 3, 4, 10, 100, 16384, 32768, 65536, 10000
> >+ };
> >+ size_t align[] = {
> >+ 512, 1024, 16, 32, 64, 4, 2048, 16, 2, 2048
> >+ };
>
> static const.
Fixed.
>
> >+ size_t i;
> >+ void *p;
> >+
> >+ for (i = 0; i < __arraycount(size); i++) {
> >+ p = (void*)0x1;
>
> Whitespace.
Fixed
>
> >+
> >+ (void)printf("Checking aligned_alloc(%zd, %zd)...\n",
> >+ align[i], size[i]);
>
> %zu
Fixed.
>
> >+ p = aligned_alloc(align[i], size[i]);
> >+
> >+ if ( align[i] < sizeof(void *) || size[i] %
> >align[i] != 0 )
>
> Whitespace
Fixed.
>
> >+ ATF_REQUIRE_EQ_MSG(errno, EINVAL,
> >+ "aligned_alloc: %s", strerror(errno));
> >+ else {
> >+ ATF_REQUIRE_EQ_MSG(p == NULL, false,
> >+ "aligned_alloc: %s", strerror(errno));
> >+ ATF_REQUIRE_EQ_MSG(((intptr_t)p) &
> >(align[i]-1), 0,
>
> Whitespace
Where?
The things commented on in the test case also applies to the already
existing test case posix_memalign_basic.
Do you want these fixed as well?
Thanks,
Niclas
Home |
Main Index |
Thread Index |
Old Index