# HG changeset patch # User Mike Becker # Date 1680030033 -7200 # Node ID 4ad8ea3aee4932ca20a887f1a36a0fb24db97b0b # Parent dce9b84506566d99decc73cc4e573d4a5b7206bb allow NULL for allocator and comparator diff -r dce9b8450656 -r 4ad8ea3aee49 src/array_list.c --- a/src/array_list.c Tue Mar 28 19:13:33 2023 +0200 +++ b/src/array_list.c Tue Mar 28 21:00:33 2023 +0200 @@ -498,12 +498,16 @@ cx_arl_iterator, }; -static CxList *cx_array_list_create( +CxList *cxArrayListCreate( CxAllocator const *allocator, CxListComparator comparator, size_t item_size, size_t initial_capacity ) { + if (allocator == NULL) { + allocator = cxDefaultAllocator; + } + cx_array_list *list = cxCalloc(allocator, 1, sizeof(cx_array_list)); if (list == NULL) return NULL; @@ -530,21 +534,3 @@ return (CxList *) list; } - -CxList *cxArrayListCreate( - CxAllocator const *allocator, - CxListComparator comparator, - size_t item_size, - size_t initial_capacity -) { - return cx_array_list_create(allocator, comparator, - item_size, initial_capacity); -} - -CxList *cxArrayListCreateSimple( - size_t item_size, - size_t initial_capacity -) { - return cx_array_list_create(cxDefaultAllocator, NULL, - item_size, initial_capacity); -} diff -r dce9b8450656 -r 4ad8ea3aee49 src/cx/array_list.h --- a/src/cx/array_list.h Tue Mar 28 19:13:33 2023 +0200 +++ b/src/cx/array_list.h Tue Mar 28 21:00:33 2023 +0200 @@ -156,7 +156,9 @@ * cxListStorePointers() was called immediately after creation. * * @param allocator the allocator for allocating the list memory + * (if \c NULL the cxDefaultAllocator will be used) * @param comparator the comparator for the elements + * (if \c NULL sort and find functions will not work) * @param item_size the size of each element in bytes * @param initial_capacity the initial number of elements the array can store * @return the created list @@ -166,7 +168,7 @@ CxListComparator comparator, size_t item_size, size_t initial_capacity -) __attribute__((__nonnull__)); +); /** * Allocates an array list for storing elements with \p item_size bytes each. @@ -182,11 +184,8 @@ * @param initial_capacity the initial number of elements the array can store * @return the created list */ -CxList *cxArrayListCreateSimple( - size_t item_size, - size_t initial_capacity -); - +#define cxArrayListCreateSimple(item_size, initial_capacity) \ + cxArrayListCreate(NULL, NULL, item_size, initial_capacity) #ifdef __cplusplus } // extern "C" diff -r dce9b8450656 -r 4ad8ea3aee49 src/cx/linked_list.h --- a/src/cx/linked_list.h Tue Mar 28 19:13:33 2023 +0200 +++ b/src/cx/linked_list.h Tue Mar 28 21:00:33 2023 +0200 @@ -58,7 +58,9 @@ * cxListStorePointers() was called immediately after creation. * * @param allocator the allocator for allocating the list nodes + * (if \c NULL the cxDefaultAllocator will be used) * @param comparator the comparator for the elements + * (if \c NULL sort and find functions will not work) * @param item_size the size of each element in bytes * @return the created list */ @@ -66,7 +68,7 @@ CxAllocator const *allocator, CxListComparator comparator, size_t item_size -) __attribute__((__nonnull__)); +); /** * Allocates a linked list for storing elements with \p item_size bytes each. @@ -81,7 +83,8 @@ * @param item_size the size of each element in bytes * @return the created list */ -CxList *cxLinkedListCreateSimple(size_t item_size); +#define cxLinkedListCreateSimple(item_size) \ + cxLinkedListCreate(NULL, NULL, item_size) /** * Finds the node at a certain index. diff -r dce9b8450656 -r 4ad8ea3aee49 src/linked_list.c --- a/src/linked_list.c Tue Mar 28 19:13:33 2023 +0200 +++ b/src/linked_list.c Tue Mar 28 21:00:33 2023 +0200 @@ -925,11 +925,15 @@ cx_ll_iterator, }; -static CxList *cx_linked_list_create( +CxList *cxLinkedListCreate( CxAllocator const *allocator, CxListComparator comparator, size_t item_size ) { + if (allocator == NULL) { + allocator = cxDefaultAllocator; + } + cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list)); if (list == NULL) return NULL; @@ -946,15 +950,3 @@ return (CxList *) list; } - -CxList *cxLinkedListCreate( - CxAllocator const *allocator, - CxListComparator comparator, - size_t item_size -) { - return cx_linked_list_create(allocator, comparator, item_size); -} - -CxList *cxLinkedListCreateSimple(size_t item_size) { - return cx_linked_list_create(cxDefaultAllocator, NULL, item_size); -}