X-Git-Url: http://git.ozlabs.org/?a=blobdiff_plain;f=ccan%2Farray%2Farray.h;h=35248409371a1683b2b1f23ce3a1bb50cb9c65f0;hb=f2c286c95f808520e0904b320dccc3680868f6ab;hp=69b25ec6677ae18dcc87db7ac7949318e7f3ca58;hpb=c1daa044b22fce3ca80d3430e3e1ad9360f8a4f1;p=ccan diff --git a/ccan/array/array.h b/ccan/array/array.h index 69b25ec6..35248409 100644 --- a/ccan/array/array.h +++ b/ccan/array/array.h @@ -38,10 +38,8 @@ #include #endif -#define HAVE_ATTRIBUTE_MAY_ALIAS 1 - //Use the array_alias macro to indicate that a pointer has changed but strict aliasing rules are too stupid to know it -#if HAVE_ATTRIBUTE_MAY_ALIAS==1 +#if HAVE_ATTRIBUTE_MAY_ALIAS #define array_alias(ptr) /* nothing */ #define array(type) struct {type *item; size_t size; size_t alloc;} __attribute__((__may_alias__)) #else @@ -88,7 +86,7 @@ #define array_append_items(array, items, count) do {size_t __count = (count); array_resize(array, (array).size+__count); memcpy((array).item+(array).size-__count, items, __count*sizeof(*(array).item));} while(0) #define array_prepend(array, ...) do {array_resize(array, (array).size+1); memmove((array).item+1, (array).item, ((array).size-1)*sizeof(*(array).item)); *(array).item = (__VA_ARGS__);} while(0) #define array_push(array, ...) array_append(array, __VA_ARGS__) -#define array_pop(array) ((array).size ? array_pop_nocheck(array) : NULL) +#define array_pop_check(array) ((array).size ? array_pop(array) : NULL) #define array_growalloc(array, newAlloc) do {size_t __newAlloc=(newAlloc); if (__newAlloc > (array).alloc) array_realloc(array, (__newAlloc+63)&~63); } while(0) #if HAVE_STATEMENT_EXPR==1 @@ -97,13 +95,16 @@ //We do just fine by ourselves -#define array_pop_nocheck(array) ((array).item[--(array).size]) +#define array_pop(array) ((array).item[--(array).size]) + +#define array_for_t(var, array, type, ...) do {type *var=(void*)(array).item; size_t _r=(array).size, _i=0; for (;_r--;_i++, var++) { __VA_ARGS__ ;} } while(0) +#define array_appends_t(array, type, ...) do {type __src[] = {__VA_ARGS__}; array_append_items(array, __src, sizeof(__src)/sizeof(*__src));} while(0) #if HAVE_TYPEOF==1 -#define array_appends(array, ...) do {typeof((*(array).item)) __src[] = {__VA_ARGS__}; array_append_items(array, __src, sizeof(__src)/sizeof(*__src));} while(0) +#define array_appends(array, ...) array_appends_t(array, typeof((*(array).item)), __VA_ARGS__)) #define array_prepends(array, ...) do {typeof((*(array).item)) __src[] = {__VA_ARGS__}; array_prepend_items(array, __src, sizeof(__src)/sizeof(*__src));} while(0) -#define array_for(var, array, ...) do {typeof(*(array).item) *var=(void*)(array).item; size_t _r=(array).size, _i=0; for (;_r--;_i++, var++) { __VA_ARGS__ ;} } while(0) +#define array_for(var, array, ...) array_for_t(var, array, typeof(*(array).item), __VA_ARGS__) #define array_rof(var, array, ...) do {typeof(*(array).item) *var=(void*)(array).item; size_t _i=(array).size, _r=0; var += _i; for (;_i--;_r++) { var--; __VA_ARGS__ ;} } while(0) #endif