Commit 88a111e2 authored by Joey Adams's avatar Joey Adams

Updated array module to version 0.1.1 .

Important change:  array_pop no longer checks if the array has elements; use array_pop_check in its place.
parent 570c9c55
......@@ -42,7 +42,7 @@
* }
*
* Author: Joey Adams
* Version: 0.1
* Version: 0.1.1
* Licence: BSD
*/
int main(int argc, char *argv[])
......
......@@ -38,7 +38,9 @@
#include <ccan/talloc/talloc.h>
#endif
#ifndef HAVE_ATTRIBUTE_MAY_ALIAS
#define HAVE_ATTRIBUTE_MAY_ALIAS 1
#endif
//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
......@@ -88,7 +90,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,7 +99,7 @@
//We do just fine by ourselves
#define array_pop_nocheck(array) ((array).item[--(array).size])
#define array_pop(array) ((array).item[--(array).size])
#if HAVE_TYPEOF==1
......
......@@ -58,7 +58,7 @@ int main(void) {
}
reset(arr);
testing(array_prepend, array_pop_nocheck);
testing(array_prepend, array_pop);
{
for (i=countof(lotsOfNumbers); i;)
array_prepend(arr, lotsOfNumbers[--i]);
......@@ -67,7 +67,7 @@ int main(void) {
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]) {
i++;
break;
}
......@@ -251,7 +251,7 @@ int main(void) {
}
reset(str);
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();
......@@ -276,19 +276,19 @@ int main(void) {
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.size==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);
array_free(array);
}
......@@ -296,7 +296,7 @@ int main(void) {
trace("Freeing amalgams (internal)");
freeAmalgams();
return 0;
return exit_status();
}
static void generateAmalgams(void) {
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment