Tue, 05 Oct 2021 11:19:32 +0200
remove convenience macros
Users should write their own wrappers s.t. the type
information does not have to be repeated on every
call site.
src/cx/list.h | file | annotate | diff | comparison | revisions | |
test/test_list.c | file | annotate | diff | comparison | revisions |
--- a/src/cx/list.h Sun Oct 03 18:51:44 2021 +0200 +++ b/src/cx/list.h Tue Oct 05 11:19:32 2021 +0200 @@ -85,12 +85,6 @@ void *cxListLast(CxList list); -#define cxTypedListAdd(type, list, elem) (cxListAdd(list, (type*) (elem))) -#define cxTypedListInsert(type, list, index, elem) (cxListInsert(list, index, (type*) (elem))) -#define cxTypedListAt(type, list, index) ((type*)cxListAt(list, index)) -#define cxTypedListFind(type, list, elem) (cxListFind(list, (type*) (elem))) -#define cxTypedListLast(type, list) ((type*)cxListLast(list)) - #ifdef __cplusplus } /* extern "C" */ #endif
--- a/test/test_list.c Sun Oct 03 18:51:44 2021 +0200 +++ b/test/test_list.c Tue Oct 05 11:19:32 2021 +0200 @@ -181,18 +181,18 @@ CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); data = 5; - CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) + CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) data = 47; - CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) + CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) data = 13; - CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) + CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) CU_ASSERT_EQUAL(list->size, 3) CU_ASSERT_TRUE(list->capacity >= list->size) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 5) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 47) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 2), 13) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) cxLinkedListDestroy(list); CU_ASSERT_TRUE(cxTestingAllocatorVerify()) @@ -204,15 +204,15 @@ int data; CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); - CU_ASSERT_PTR_NULL(cxTypedListLast(int, list)) + CU_ASSERT_PTR_NULL(cxListLast(list)) data = 5; - CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) - CU_ASSERT_EQUAL(*cxTypedListLast(int, list), 5) + CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) + CU_ASSERT_EQUAL(*(int*)cxListLast(list), 5) data = 47; - CU_ASSERT_EQUAL(cxTypedListAdd(int, list, &data), 0) - CU_ASSERT_EQUAL(*cxTypedListLast(int, list), 47) + CU_ASSERT_EQUAL(cxListAdd(list, &data), 0) + CU_ASSERT_EQUAL(*(int*)cxListLast(list), 47) cxLinkedListDestroy(list); CU_ASSERT_TRUE(cxTestingAllocatorVerify()) @@ -225,26 +225,26 @@ CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); data = 5; - CU_ASSERT_NOT_EQUAL(cxTypedListInsert(int, list, 1, &data), 0) + CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &data), 0) CU_ASSERT_EQUAL(list->size, 0) - CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 0, &data), 0) + CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0) CU_ASSERT_EQUAL(list->size, 1) data = 47; - CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 0, &data), 0) + CU_ASSERT_EQUAL(cxListInsert(list, 0, &data), 0) CU_ASSERT_EQUAL(list->size, 2) data = 13; - CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 1, &data), 0) + CU_ASSERT_EQUAL(cxListInsert(list, 1, &data), 0) CU_ASSERT_EQUAL(list->size, 3) data = 42; - CU_ASSERT_EQUAL(cxTypedListInsert(int, list, 3, &data), 0) + CU_ASSERT_EQUAL(cxListInsert(list, 3, &data), 0) CU_ASSERT_EQUAL(list->size, 4) CU_ASSERT_TRUE(list->capacity >= list->size) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 47) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 13) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 2), 5) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 3), 42) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 47) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 13) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 5) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 3), 42) cxLinkedListDestroy(list); CU_ASSERT_TRUE(cxTestingAllocatorVerify()) @@ -257,13 +257,13 @@ CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); data = 5; - cxTypedListAdd(int, list, &data); + cxListAdd(list, &data); data = 47; - cxTypedListAdd(int, list, &data); + cxListAdd(list, &data); data = 42; - cxTypedListAdd(int, list, &data); + cxListAdd(list, &data); data = 13; - cxTypedListAdd(int, list, &data); + cxListAdd(list, &data); CU_ASSERT_EQUAL(list->size, 4) CU_ASSERT_TRUE(list->capacity >= list->size) @@ -273,20 +273,20 @@ CU_ASSERT_EQUAL(cxListRemove(list, 2), 0) CU_ASSERT_EQUAL(list->size, 3) CU_ASSERT_TRUE(list->capacity >= list->size) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 5) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 47) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 2), 13) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 5) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 47) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 2), 13) CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) CU_ASSERT_EQUAL(list->size, 2) CU_ASSERT_TRUE(list->capacity >= list->size) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 47) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 1), 13) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 47) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 1), 13) CU_ASSERT_EQUAL(cxListRemove(list, 1), 0) CU_ASSERT_EQUAL(list->size, 1) CU_ASSERT_TRUE(list->capacity >= list->size) - CU_ASSERT_EQUAL(*cxTypedListAt(int, list, 0), 47) + CU_ASSERT_EQUAL(*(int*)cxListAt(list, 0), 47) CU_ASSERT_EQUAL(cxListRemove(list, 0), 0) CU_ASSERT_EQUAL(list->size, 0) @@ -305,25 +305,25 @@ CxList list = cxLinkedListCreate(cxTestingAllocator, (CxListComparator) cmp_int, sizeof(int)); data = 5; - cxTypedListAdd(int, list, &data); + cxListAdd(list, &data); data = 47; - cxTypedListAdd(int, list, &data); + cxListAdd(list, &data); data = 13; - cxTypedListAdd(int, list, &data); + cxListAdd(list, &data); CU_ASSERT_EQUAL(list->size, 3) CU_ASSERT_TRUE(list->capacity >= list->size) criteria = 5; - CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 0) + CU_ASSERT_EQUAL(cxListFind(list, &criteria), 0) criteria = 47; - CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 1) + CU_ASSERT_EQUAL(cxListFind(list, &criteria), 1) criteria = 13; - CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 2) + CU_ASSERT_EQUAL(cxListFind(list, &criteria), 2) criteria = 9000; - CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 3) + CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) criteria = -5; - CU_ASSERT_EQUAL(cxTypedListFind(int, list, &criteria), 3) + CU_ASSERT_EQUAL(cxListFind(list, &criteria), 3) cxLinkedListDestroy(list); CU_ASSERT_TRUE(cxTestingAllocatorVerify())