Important change: array_pop no longer checks if the array has elements; use array_pop_check in its place.
* }
*
* Author: Joey Adams
* }
*
* Author: Joey Adams
* Licence: BSD
*/
int main(int argc, char *argv[])
* Licence: BSD
*/
int main(int argc, char *argv[])
#include <ccan/talloc/talloc.h>
#endif
#include <ccan/talloc/talloc.h>
#endif
+#ifndef HAVE_ATTRIBUTE_MAY_ALIAS
#define HAVE_ATTRIBUTE_MAY_ALIAS 1
#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
//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
#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_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
#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
//We do just fine by ourselves
//We do just fine by ourselves
-#define array_pop_nocheck(array) ((array).item[--(array).size])
+#define array_pop(array) ((array).item[--(array).size])
- testing(array_prepend, array_pop_nocheck);
+ testing(array_prepend, array_pop);
{
for (i=countof(lotsOfNumbers); i;)
array_prepend(arr, lotsOfNumbers[--i]);
{
for (i=countof(lotsOfNumbers); i;)
array_prepend(arr, lotsOfNumbers[--i]);
ok1(!memcmp(arr.item, lotsOfNumbers, sizeof(lotsOfNumbers)));
for (i=countof(lotsOfNumbers); i;) {
ok1(!memcmp(arr.item, lotsOfNumbers, sizeof(lotsOfNumbers)));
for (i=countof(lotsOfNumbers); i;) {
- if (array_pop_nocheck(arr) != (long)lotsOfNumbers[--i]) {
+ if (array_pop(arr) != (long)lotsOfNumbers[--i]) {
- testing(array_appends, array_prepends, array_pop);
+ testing(array_appends, array_prepends, array_pop_check);
{
#ifndef ARRAY_USE_TALLOC
array(const char*) array = array_new();
{
#ifndef ARRAY_USE_TALLOC
array(const char*) array = array_new();
array.item[7]==n[7] &&
array.item[8]==n[8]);
array.item[7]==n[7] &&
array.item[8]==n[8]);
- ok1(array_pop(array)==n[8] &&
- array_pop(array)==n[7] &&
- array_pop(array)==n[6] &&
- array_pop(array)==n[5] &&
- array_pop(array)==n[4] &&
- array_pop(array)==n[3] &&
- array_pop(array)==n[2] &&
- array_pop(array)==n[1] &&
- array_pop(array)==n[0]);
+ ok1(array_pop_check(array)==n[8] &&
+ array_pop_check(array)==n[7] &&
+ array_pop_check(array)==n[6] &&
+ array_pop_check(array)==n[5] &&
+ array_pop_check(array)==n[4] &&
+ array_pop_check(array)==n[3] &&
+ array_pop_check(array)==n[2] &&
+ array_pop_check(array)==n[1] &&
+ array_pop_check(array)==n[0]);
- ok1(array_pop(array)==NULL && array_pop(array)==NULL && array_pop(array)==NULL);
+ ok1(array_pop_check(array)==NULL && array_pop_check(array)==NULL && array_pop_check(array)==NULL);
trace("Freeing amalgams (internal)");
freeAmalgams();
trace("Freeing amalgams (internal)");
freeAmalgams();
}
static void generateAmalgams(void) {
}
static void generateAmalgams(void) {