--- a/ucx/linked_list.c Sun Oct 19 21:20:08 2025 +0200 +++ b/ucx/linked_list.c Mon Nov 10 21:52:51 2025 +0100 @@ -30,7 +30,6 @@ #include "cx/compare.h" #include <string.h> #include <assert.h> -#include <unistd.h> // LOW LEVEL LINKED LIST FUNCTIONS @@ -475,6 +474,16 @@ return removed; } +void cx_linked_list_remove( + void **begin, + void **end, + ptrdiff_t loc_prev, + ptrdiff_t loc_next, + void *node +) { + cx_linked_list_remove_chain(begin, end, loc_prev, loc_next, node, 1); +} + size_t cx_linked_list_size( const void *node, ptrdiff_t loc_next @@ -742,7 +751,9 @@ // we can add the remaining nodes and immediately advance to the inserted node const char *source = array; for (size_t i = 1; i < n; i++) { - source += list->collection.elem_size; + if (source != NULL) { + source += list->collection.elem_size; + } if (0 != cx_ll_insert_at(list, node, source)) return i; node = CX_LL_PTR(node, ll->loc_next); } @@ -1116,10 +1127,10 @@ static void cx_ll_iter_next(void *it) { struct cx_iterator_s *iter = it; + cx_linked_list *ll = iter->src_handle; if (iter->base.remove) { iter->base.remove = false; - struct cx_list_s *list = iter->src_handle.m; - cx_linked_list *ll = iter->src_handle.m; + struct cx_list_s *list = iter->src_handle; char *node = iter->elem_handle; iter->elem_handle = CX_LL_PTR(node, ll->loc_next); cx_invoke_destructor(list, node + ll->loc_data); @@ -1129,7 +1140,6 @@ iter->elem_count--; cxFree(list->collection.allocator, node); } else { - const cx_linked_list *ll = iter->src_handle.c; iter->index++; void *node = iter->elem_handle; iter->elem_handle = CX_LL_PTR(node, ll->loc_next); @@ -1138,10 +1148,10 @@ static void cx_ll_iter_prev(void *it) { struct cx_iterator_s *iter = it; + cx_linked_list *ll = iter->src_handle; if (iter->base.remove) { iter->base.remove = false; - struct cx_list_s *list = iter->src_handle.m; - cx_linked_list *ll = iter->src_handle.m; + struct cx_list_s *list = iter->src_handle; char *node = iter->elem_handle; iter->elem_handle = CX_LL_PTR(node, ll->loc_prev); iter->index--; @@ -1152,7 +1162,6 @@ iter->elem_count--; cxFree(list->collection.allocator, node); } else { - const cx_linked_list *ll = iter->src_handle.c; iter->index--; char *node = iter->elem_handle; iter->elem_handle = CX_LL_PTR(node, ll->loc_prev); @@ -1161,7 +1170,7 @@ static void *cx_ll_iter_current(const void *it) { const struct cx_iterator_s *iter = it; - const cx_linked_list *ll = iter->src_handle.c; + const cx_linked_list *ll = iter->src_handle; char *node = iter->elem_handle; return node + ll->loc_data; } @@ -1173,14 +1182,14 @@ ) { CxIterator iter; iter.index = index; - iter.src_handle.c = list; + iter.src_handle = (void*)list; iter.elem_handle = cx_ll_node_at((const cx_linked_list *) list, index); iter.elem_size = list->collection.elem_size; iter.elem_count = list->collection.size; iter.base.valid = cx_ll_iter_valid; iter.base.current = cx_ll_iter_current; iter.base.next = backwards ? cx_ll_iter_prev : cx_ll_iter_next; - iter.base.mutating = false; + iter.base.allow_remove = true; iter.base.remove = false; return iter; } @@ -1190,8 +1199,8 @@ const void *elem, int prepend ) { - struct cx_list_s *list = iter->src_handle.m; - cx_linked_list *ll = iter->src_handle.m; + struct cx_list_s *list = iter->src_handle; + cx_linked_list *ll = iter->src_handle; void *node = iter->elem_handle; if (node != NULL) { assert(prepend >= 0 && prepend <= 1); @@ -1243,6 +1252,7 @@ cx_ll_sort, cx_ll_compare, cx_ll_reverse, + NULL, // no overallocation supported cx_ll_iterator, };