src/linked_list.c

changeset 508
8aea65ae1eaf
parent 503
a89857072ace
child 509
0d3c6075f82c
     1.1 --- a/src/linked_list.c	Sun Mar 06 13:57:36 2022 +0100
     1.2 +++ b/src/linked_list.c	Sat Apr 09 16:37:43 2022 +0200
     1.3 @@ -40,7 +40,7 @@
     1.4  #define ll_data(node) (follow_ptr?CX_LL_PTR(node, loc_data):(((char*)node)+loc_data))
     1.5  
     1.6  void *cx_linked_list_at(
     1.7 -        void *start,
     1.8 +        void const *start,
     1.9          size_t start_index,
    1.10          ptrdiff_t loc_advance,
    1.11          size_t index
    1.12 @@ -48,12 +48,12 @@
    1.13      assert(start != NULL);
    1.14      assert(loc_advance >= 0);
    1.15      size_t i = start_index;
    1.16 -    void *cur = start;
    1.17 +    void const *cur = start;
    1.18      while (i != index && cur != NULL) {
    1.19          cur = ll_advance(cur);
    1.20          i < index ? i++ : i--;
    1.21      }
    1.22 -    return cur;
    1.23 +    return (void *) cur;
    1.24  }
    1.25  
    1.26  size_t cx_linked_list_find(
    1.27 @@ -83,42 +83,42 @@
    1.28  }
    1.29  
    1.30  void *cx_linked_list_first(
    1.31 -        void *node,
    1.32 +        void const *node,
    1.33          ptrdiff_t loc_prev
    1.34  ) {
    1.35      return cx_linked_list_last(node, loc_prev);
    1.36  }
    1.37  
    1.38  void *cx_linked_list_last(
    1.39 -        void *node,
    1.40 +        void const *node,
    1.41          ptrdiff_t loc_next
    1.42  ) {
    1.43      assert(node != NULL);
    1.44      assert(loc_next >= 0);
    1.45  
    1.46 -    void *cur = node;
    1.47 -    void *last;
    1.48 +    void const *cur = node;
    1.49 +    void const *last;
    1.50      do {
    1.51          last = cur;
    1.52      } while ((cur = ll_next(cur)) != NULL);
    1.53  
    1.54 -    return last;
    1.55 +    return (void *) last;
    1.56  }
    1.57  
    1.58  void *cx_linked_list_prev(
    1.59 -        void *begin,
    1.60 +        void const *begin,
    1.61          ptrdiff_t loc_next,
    1.62 -        void *node
    1.63 +        void const *node
    1.64  ) {
    1.65      assert(begin != NULL);
    1.66      assert(node != NULL);
    1.67      assert(loc_next >= 0);
    1.68      if (begin == node) return NULL;
    1.69 -    void *cur = begin;
    1.70 -    void *next;
    1.71 +    void const *cur = begin;
    1.72 +    void const *next;
    1.73      while (1) {
    1.74          next = ll_next(cur);
    1.75 -        if (next == node) return cur;
    1.76 +        if (next == node) return (void *) cur;
    1.77          cur = next;
    1.78      }
    1.79  }
    1.80 @@ -294,6 +294,7 @@
    1.81      const size_t sbo_len = 1024;
    1.82      void *sbo[sbo_len];
    1.83      void **sorted = (length >= sbo_len) ? malloc(sizeof(void *) * length) : sbo;
    1.84 +    if (sorted == NULL) abort();
    1.85      void *rc, *lc;
    1.86  
    1.87      lc = ls;
    1.88 @@ -772,7 +773,7 @@
    1.89  }
    1.90  
    1.91  CxList *cxLinkedListCreate(
    1.92 -        CxAllocator *allocator,
    1.93 +        CxAllocator const *allocator,
    1.94          CxListComparator comparator,
    1.95          size_t item_size
    1.96  ) {
    1.97 @@ -791,7 +792,7 @@
    1.98  }
    1.99  
   1.100  CxList *cxPointerLinkedListCreate(
   1.101 -        CxAllocator *allocator,
   1.102 +        CxAllocator const *allocator,
   1.103          CxListComparator comparator
   1.104  ) {
   1.105      cx_linked_list *list = cxCalloc(allocator, 1, sizeof(cx_linked_list));
   1.106 @@ -809,7 +810,7 @@
   1.107  }
   1.108  
   1.109  CxList *cxLinkedListFromArray(
   1.110 -        CxAllocator *allocator,
   1.111 +        CxAllocator const *allocator,
   1.112          CxListComparator comparator,
   1.113          size_t item_size,
   1.114          size_t num_items,

mercurial