diff -r d4baf4dd55c3 -r fe0d69d72bcd src/list.c --- a/src/list.c Thu May 23 19:29:14 2024 +0200 +++ b/src/list.c Thu May 23 20:29:28 2024 +0200 @@ -47,14 +47,14 @@ static void cx_pl_hack_cmpfunc(struct cx_list_s const *list) { // cast away const - this is the hacky thing - struct cx_list_s *l = (struct cx_list_s *) list; + struct cx_collection_s *l = (struct cx_collection_s*) &list->base; cx_pl_cmpfunc_impl = l->cmpfunc; l->cmpfunc = cx_pl_cmpfunc; } static void cx_pl_unhack_cmpfunc(struct cx_list_s const *list) { // cast away const - this is the hacky thing - struct cx_list_s *l = (struct cx_list_s *) list; + struct cx_collection_s *l = (struct cx_collection_s*) &list->base; l->cmpfunc = cx_pl_cmpfunc_impl; } @@ -148,7 +148,7 @@ static void *cx_pl_iter_current(void const *it) { struct cx_iterator_s const *iter = it; - void **ptr = iter->current_impl(it); + void **ptr = iter->base.current_impl(it); return ptr == NULL ? NULL : *ptr; } @@ -158,8 +158,8 @@ bool backwards ) { struct cx_iterator_s iter = list->climpl->iterator(list, index, backwards); - iter.current_impl = iter.current; - iter.current = cx_pl_iter_current; + iter.base.current_impl = iter.base.current; + iter.base.current = cx_pl_iter_current; return iter; } @@ -180,7 +180,7 @@ }; void cxListStoreObjects(CxList *list) { - list->store_pointer = false; + list->base.store_pointer = false; if (list->climpl != NULL) { list->cl = list->climpl; list->climpl = NULL; @@ -188,8 +188,8 @@ } void cxListStorePointers(CxList *list) { - list->item_size = sizeof(void *); - list->store_pointer = true; + list->base.item_size = sizeof(void *); + list->base.store_pointer = true; list->climpl = list->cl; list->cl = &cx_pointer_list_class; } @@ -221,7 +221,7 @@ __attribute__((__unused__)) struct cx_list_s const *list, struct cx_list_s const *other ) { - if (other->size == 0) return 0; + if (other->base.size == 0) return 0; return -1; } @@ -237,7 +237,7 @@ CxIterator iter = {0}; iter.src_handle.c = list; iter.index = index; - iter.valid = cx_emptyl_iter_valid; + iter.base.valid = cx_emptyl_iter_valid; return iter; } @@ -258,14 +258,16 @@ }; CxList cx_empty_list = { - NULL, - NULL, - 0, - 0, - NULL, - NULL, - NULL, - false, + { + NULL, + NULL, + 0, + 0, + NULL, + NULL, + NULL, + false + }, &cx_empty_list_class, NULL }; @@ -284,7 +286,7 @@ ) { if ( // if one is storing pointers but the other is not - (list->store_pointer ^ other->store_pointer) || + (list->base.store_pointer ^ other->base.store_pointer) || // if one class is wrapped but the other is not ((list->climpl == NULL) ^ (other->climpl == NULL)) || @@ -294,13 +296,13 @@ (other->climpl != NULL ? other->climpl->compare : other->cl->compare)) ) { // lists are definitely different - cannot use internal compare function - if (list->size == other->size) { + if (list->base.size == other->base.size) { CxIterator left = list->cl->iterator(list, 0, false); CxIterator right = other->cl->iterator(other, 0, false); - for (size_t i = 0; i < list->size; i++) { + for (size_t i = 0; i < list->base.size; i++) { void *leftValue = cxIteratorCurrent(left); void *rightValue = cxIteratorCurrent(right); - int d = list->cmpfunc(leftValue, rightValue); + int d = list->base.cmpfunc(leftValue, rightValue); if (d != 0) { return d; } @@ -309,7 +311,7 @@ } return 0; } else { - return list->size < other->size ? -1 : 1; + return list->base.size < other->base.size ? -1 : 1; } } else { // lists are compatible @@ -322,7 +324,7 @@ size_t index ) { CxIterator it = list->cl->iterator(list, index, false); - it.mutating = true; + it.base.mutating = true; return it; } @@ -331,6 +333,6 @@ size_t index ) { CxIterator it = list->cl->iterator(list, index, true); - it.mutating = true; + it.base.mutating = true; return it; }