Tue, 28 Dec 2021 17:38:02 +0100
add some const qualifiers
src/buffer.c | file | annotate | diff | comparison | revisions | |
src/cx/buffer.h | file | annotate | diff | comparison | revisions | |
src/cx/linked_list.h | file | annotate | diff | comparison | revisions | |
src/cx/list.h | file | annotate | diff | comparison | revisions | |
src/linked_list.c | file | annotate | diff | comparison | revisions | |
test/test_list.c | file | annotate | diff | comparison | revisions |
--- a/src/buffer.c Tue Dec 28 17:24:18 2021 +0100 +++ b/src/buffer.c Tue Dec 28 17:38:02 2021 +0100 @@ -158,7 +158,7 @@ } size_t cxBufferWrite( - const void *ptr, + void const *ptr, size_t size, size_t nitems, CxBuffer buffer
--- a/src/cx/buffer.h Tue Dec 28 17:24:18 2021 +0100 +++ b/src/cx/buffer.h Tue Dec 28 17:38:02 2021 +0100 @@ -302,7 +302,7 @@ * @return the total count of bytes written */ size_t cxBufferWrite( - const void *ptr, + void const *ptr, size_t size, size_t nitems, CxBuffer buffer
--- a/src/cx/linked_list.h Tue Dec 28 17:24:18 2021 +0100 +++ b/src/cx/linked_list.h Tue Dec 28 17:38:02 2021 +0100 @@ -90,7 +90,7 @@ CxListComparator comparator, size_t item_size, size_t num_items, - const void *array + void const *array ) __attribute__((__nonnull__)); /** @@ -139,12 +139,12 @@ * @return the index of the element or a past-one index if the element could not be found */ size_t cx_linked_list_find( - void *start, + void const *start, ptrdiff_t loc_advance, ptrdiff_t loc_data, bool follow_ptr, CxListComparator cmp_func, - void *elem + void const *elem ) __attribute__((__nonnull__)); /** @@ -355,7 +355,7 @@ * @return the size of the list or zero if \p node is \c NULL */ size_t cx_linked_list_size( - void *node, + void const *node, ptrdiff_t loc_next ); @@ -416,8 +416,8 @@ * @return */ int cx_linked_list_compare( - void *begin_left, - void *begin_right, + void const *begin_left, + void const *begin_right, ptrdiff_t loc_advance, ptrdiff_t loc_data, bool follow_ptr,
--- a/src/cx/list.h Tue Dec 28 17:24:18 2021 +0100 +++ b/src/cx/list.h Tue Dec 28 17:38:02 2021 +0100 @@ -47,7 +47,10 @@ /** * A comparator function comparing two list elements. */ -typedef int(*CxListComparator)(void const *left, void const *right); +typedef int(*CxListComparator)( + void const *left, + void const *right +); /** * Internal type for the list structure - use CxList instead. @@ -61,29 +64,42 @@ /** * Member function for adding an element. */ - int (*add)(cx_list_s *list, void *elem); + int (*add)( + cx_list_s *list, + void const *elem + ); /** * Member function for inserting an element. */ - int (*insert)(cx_list_s *list, size_t index, void *elem); + int (*insert)( + cx_list_s *list, + size_t index, + void const *elem + ); /** * Member function for removing an element. */ - int (*remove)(cx_list_s *list, size_t index); + int (*remove)( + cx_list_s *list, + size_t index + ); /** * Member function for element lookup. */ - void *(*at)(cx_list_s *list, size_t index); + void *(*at)( + cx_list_s const *list, + size_t index + ); /** * Member function for finding an element. */ size_t (*find)( - cx_list_s *list, - void *elem + cx_list_s const *list, + void const *elem ); /** @@ -95,8 +111,8 @@ * Member function for comparing this list to another list of the same type. */ int (*compare)( - cx_list_s *list, - cx_list_s *other + cx_list_s const *list, + cx_list_s const *other ); } cx_list_class; @@ -147,7 +163,10 @@ * @param elem a pointer to the element to add * @return zero on success, non-zero on memory allocation failure */ -static inline int cxListAdd(CxList list, void *elem) { +static inline int cxListAdd( + CxList list, + void const *elem +) { return list->cl->add(list, elem); } @@ -167,7 +186,11 @@ * @return zero on success, non-zero on memory allocation failure * or when the index is out of bounds */ -static inline int cxListInsert(CxList list, size_t index, void *elem) { +static inline int cxListInsert( + CxList list, + size_t index, + void const *elem +) { return list->cl->insert(list, index, elem); } @@ -177,7 +200,10 @@ * @param index the index of the element * @return zero on success, non-zero if the index is out of bounds */ -static inline int cxListRemove(CxList list, size_t index) { +static inline int cxListRemove( + CxList list, + size_t index +) { return list->cl->remove(list, index); } @@ -188,7 +214,10 @@ * @param index the index of the element * @return a pointer to the element or \c NULL if the index is out of bounds */ -static inline void *cxListAt(CxList list, size_t index) { +static inline void *cxListAt( + CxList list, + size_t index +) { return list->cl->at(list, index); } @@ -201,7 +230,10 @@ * @param elem the element to find * @return the index of the element or \c (size+1) if the element is not found */ -static inline size_t cxListFind(CxList list, void *elem) { +static inline size_t cxListFind( + CxList list, + void const *elem +) { return list->cl->find(list, elem); }
--- a/src/linked_list.c Tue Dec 28 17:24:18 2021 +0100 +++ b/src/linked_list.c Tue Dec 28 17:38:02 2021 +0100 @@ -57,19 +57,19 @@ } size_t cx_linked_list_find( - void *start, + void const *start, ptrdiff_t loc_advance, ptrdiff_t loc_data, bool follow_ptr, CxListComparator cmp_func, - void *elem + void const *elem ) { assert(start != NULL); assert(loc_advance >= 0); assert(loc_data >= 0); assert(cmp_func); - void *node = start; + void const *node = start; size_t index = 0; do { void *current = ll_data(node); @@ -268,7 +268,7 @@ } size_t cx_linked_list_size( - void *node, + void const *node, ptrdiff_t loc_next ) { assert(loc_next >= 0); @@ -397,14 +397,14 @@ } int cx_linked_list_compare( - void *begin_left, - void *begin_right, + void const *begin_left, + void const *begin_right, ptrdiff_t loc_advance, ptrdiff_t loc_data, bool follow_ptr, CxListComparator cmp_func ) { - void *left = begin_left, *right = begin_right; + void const *left = begin_left, *right = begin_right; while (left != NULL && right != NULL) { int result = cmp_func(ll_data(left), ll_data(right)); @@ -469,7 +469,7 @@ } cx_linked_list; static cx_linked_list_node *cx_ll_node_at( - cx_linked_list *list, + cx_linked_list const *list, size_t index ) { if (index >= list->base.size) { @@ -484,7 +484,7 @@ static int cx_ll_insert( cx_list_s *list, size_t index, - void *elem + void const *elem ) { // out-of bounds check if (index > list->size) return 1; @@ -520,7 +520,7 @@ static int cx_ll_add( cx_list_s *list, - void *elem + void const *elem ) { return cx_ll_insert(list, list->size, elem); } @@ -528,14 +528,14 @@ static int cx_pll_insert( cx_list_s *list, size_t index, - void *elem + void const *elem ) { return cx_ll_insert(list, index, &elem); } static int cx_pll_add( cx_list_s *list, - void *elem + void const *elem ) { return cx_ll_insert(list, list->size, &elem); } @@ -564,7 +564,7 @@ } static void *cx_ll_at( - cx_list_s *list, + cx_list_s const *list, size_t index ) { cx_linked_list *ll = (cx_linked_list *) list; @@ -573,7 +573,7 @@ } static void *cx_pll_at( - cx_list_s *list, + cx_list_s const *list, size_t index ) { cx_linked_list *ll = (cx_linked_list *) list; @@ -582,8 +582,8 @@ } static size_t cx_ll_find( - cx_list_s *list, - void *elem + cx_list_s const *list, + void const *elem ) { return cx_linked_list_find(((cx_linked_list *) list)->begin, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, @@ -591,8 +591,8 @@ } static size_t cx_pll_find( - cx_list_s *list, - void *elem + cx_list_s const *list, + void const *elem ) { return cx_linked_list_find(((cx_linked_list *) list)->begin, CX_LL_LOC_NEXT, CX_LL_LOC_DATA, @@ -614,8 +614,8 @@ } static int cx_ll_compare( - cx_list_s *list, - cx_list_s *other + cx_list_s const *list, + cx_list_s const *other ) { cx_linked_list *left = (cx_linked_list *) list; cx_linked_list *right = (cx_linked_list *) other; @@ -625,8 +625,8 @@ } static int cx_pll_compare( - cx_list_s *list, - cx_list_s *other + cx_list_s const *list, + cx_list_s const *other ) { cx_linked_list *left = (cx_linked_list *) list; cx_linked_list *right = (cx_linked_list *) other; @@ -703,7 +703,7 @@ CxListComparator comparator, size_t item_size, size_t num_items, - const void *array + void const *array ) { CxList list = cxLinkedListCreate(allocator, comparator, item_size); if (list == NULL) return NULL;