On 06/03/15 18:26, Brian Paul wrote: > On Fri, Mar 6, 2015 at 9:32 AM, Emil Velikov <emil.l.veli...@gmail.com > <mailto:emil.l.veli...@gmail.com>> wrote: > > Used for aligned_alloc and other C11 functions missing from the header. > > Signed-off-by: Emil Velikov <emil.l.veli...@gmail.com > <mailto:emil.l.veli...@gmail.com>> > --- > include/c11_stdlib.h | 118 ++++++++++++++++++++++++++++++ > > > I wonder if this should be include/c11/stdlib.h instead. > > I also wonder if I should have put c99_math.h in c99/math.h Jose > followed my pattern with c99_alloca.h > > We should probably be more consistent about this. What do you think? > > > > > +++++++++++++++++++++ > 1 file changed, 118 insertions(+) > create mode 100644 include/c11_stdlib.h > > diff --git a/include/c11_stdlib.h b/include/c11_stdlib.h > new file mode 100644 > index 0000000..04e494f > --- /dev/null > +++ b/include/c11_stdlib.h > @@ -0,0 +1,118 @@ > +/* > + * Mesa 3-D graphics library > + * > + * Copyright (C) 1999-2007 Brian Paul All Rights Reserved. > + * > + * Permission is hereby granted, free of charge, to any person > obtaining a > + * copy of this software and associated documentation files (the > "Software"), > + * to deal in the Software without restriction, including without > limitation > + * the rights to use, copy, modify, merge, publish, distribute, > sublicense, > + * and/or sell copies of the Software, and to permit persons to > whom the > + * Software is furnished to do so, subject to the following conditions: > + * > + * The above copyright notice and this permission notice shall be > included > + * in all copies or substantial portions of the Software. > + * > + * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, > EXPRESS > + * OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF > MERCHANTABILITY, > + * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO > EVENT SHALL > + * THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR > + * OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR > OTHERWISE, > + * ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE > USE OR > + * OTHER DEALINGS IN THE SOFTWARE. > + */ > + > +/** > + * Wrapper for stdlib.h which makes sure we have definitions of all > the c11 > + * functions. > + */ > + > +#ifndef _C11_STDLIB_H_ > +#define _C11_STDLIB_H_ > + > +#include <stdint.h> > > > I stdint.h really needed here? > > Otherwise than the naming issue and the stdint.h question, the series > looks good to me. Reviewed-by: Brian Paul <bri...@vmware.com > <mailto:bri...@vmware.com>> > I've included it due to the uintptr_t below. I'm not 100% sure that stdlib.h will be sufficient to provide it for platforms which lack both posix_memalign and _aligned_malloc.
So better be safe than sorry :) -Emil ... > +static inline void * > +aligned_alloc(size_t alignment, size_t size) > +{ > +#if defined(HAVE_POSIX_MEMALIGN) > + void *mem; > + int err = posix_memalign(&mem, alignment, size); > + if (err) > + return NULL; > + return mem; > +#elif defined(_WIN32) && !defined(__CYGWIN__) > + return _aligned_malloc(size, alignment); > +#else > + uintptr_t ptr, buf; > + > + assert( alignment > 0 ); > + > + ptr = (uintptr_t)malloc(size + alignment + sizeof(void *)); > + if (!ptr) > + return NULL; > + > + buf = (ptr + alignment + sizeof(void *)) & > ~(uintptr_t)(alignment - 1); > + *(uintptr_t *)(buf - sizeof(void *)) = ptr; _______________________________________________ mesa-dev mailing list mesa-dev@lists.freedesktop.org http://lists.freedesktop.org/mailman/listinfo/mesa-dev