1.1 --- a/src/list.c Thu May 23 19:29:14 2024 +0200 1.2 +++ b/src/list.c Thu May 23 20:29:28 2024 +0200 1.3 @@ -47,14 +47,14 @@ 1.4 1.5 static void cx_pl_hack_cmpfunc(struct cx_list_s const *list) { 1.6 // cast away const - this is the hacky thing 1.7 - struct cx_list_s *l = (struct cx_list_s *) list; 1.8 + struct cx_collection_s *l = (struct cx_collection_s*) &list->base; 1.9 cx_pl_cmpfunc_impl = l->cmpfunc; 1.10 l->cmpfunc = cx_pl_cmpfunc; 1.11 } 1.12 1.13 static void cx_pl_unhack_cmpfunc(struct cx_list_s const *list) { 1.14 // cast away const - this is the hacky thing 1.15 - struct cx_list_s *l = (struct cx_list_s *) list; 1.16 + struct cx_collection_s *l = (struct cx_collection_s*) &list->base; 1.17 l->cmpfunc = cx_pl_cmpfunc_impl; 1.18 } 1.19 1.20 @@ -148,7 +148,7 @@ 1.21 1.22 static void *cx_pl_iter_current(void const *it) { 1.23 struct cx_iterator_s const *iter = it; 1.24 - void **ptr = iter->current_impl(it); 1.25 + void **ptr = iter->base.current_impl(it); 1.26 return ptr == NULL ? NULL : *ptr; 1.27 } 1.28 1.29 @@ -158,8 +158,8 @@ 1.30 bool backwards 1.31 ) { 1.32 struct cx_iterator_s iter = list->climpl->iterator(list, index, backwards); 1.33 - iter.current_impl = iter.current; 1.34 - iter.current = cx_pl_iter_current; 1.35 + iter.base.current_impl = iter.base.current; 1.36 + iter.base.current = cx_pl_iter_current; 1.37 return iter; 1.38 } 1.39 1.40 @@ -180,7 +180,7 @@ 1.41 }; 1.42 1.43 void cxListStoreObjects(CxList *list) { 1.44 - list->store_pointer = false; 1.45 + list->base.store_pointer = false; 1.46 if (list->climpl != NULL) { 1.47 list->cl = list->climpl; 1.48 list->climpl = NULL; 1.49 @@ -188,8 +188,8 @@ 1.50 } 1.51 1.52 void cxListStorePointers(CxList *list) { 1.53 - list->item_size = sizeof(void *); 1.54 - list->store_pointer = true; 1.55 + list->base.item_size = sizeof(void *); 1.56 + list->base.store_pointer = true; 1.57 list->climpl = list->cl; 1.58 list->cl = &cx_pointer_list_class; 1.59 } 1.60 @@ -221,7 +221,7 @@ 1.61 __attribute__((__unused__)) struct cx_list_s const *list, 1.62 struct cx_list_s const *other 1.63 ) { 1.64 - if (other->size == 0) return 0; 1.65 + if (other->base.size == 0) return 0; 1.66 return -1; 1.67 } 1.68 1.69 @@ -237,7 +237,7 @@ 1.70 CxIterator iter = {0}; 1.71 iter.src_handle.c = list; 1.72 iter.index = index; 1.73 - iter.valid = cx_emptyl_iter_valid; 1.74 + iter.base.valid = cx_emptyl_iter_valid; 1.75 return iter; 1.76 } 1.77 1.78 @@ -258,14 +258,16 @@ 1.79 }; 1.80 1.81 CxList cx_empty_list = { 1.82 - NULL, 1.83 - NULL, 1.84 - 0, 1.85 - 0, 1.86 - NULL, 1.87 - NULL, 1.88 - NULL, 1.89 - false, 1.90 + { 1.91 + NULL, 1.92 + NULL, 1.93 + 0, 1.94 + 0, 1.95 + NULL, 1.96 + NULL, 1.97 + NULL, 1.98 + false 1.99 + }, 1.100 &cx_empty_list_class, 1.101 NULL 1.102 }; 1.103 @@ -284,7 +286,7 @@ 1.104 ) { 1.105 if ( 1.106 // if one is storing pointers but the other is not 1.107 - (list->store_pointer ^ other->store_pointer) || 1.108 + (list->base.store_pointer ^ other->base.store_pointer) || 1.109 1.110 // if one class is wrapped but the other is not 1.111 ((list->climpl == NULL) ^ (other->climpl == NULL)) || 1.112 @@ -294,13 +296,13 @@ 1.113 (other->climpl != NULL ? other->climpl->compare : other->cl->compare)) 1.114 ) { 1.115 // lists are definitely different - cannot use internal compare function 1.116 - if (list->size == other->size) { 1.117 + if (list->base.size == other->base.size) { 1.118 CxIterator left = list->cl->iterator(list, 0, false); 1.119 CxIterator right = other->cl->iterator(other, 0, false); 1.120 - for (size_t i = 0; i < list->size; i++) { 1.121 + for (size_t i = 0; i < list->base.size; i++) { 1.122 void *leftValue = cxIteratorCurrent(left); 1.123 void *rightValue = cxIteratorCurrent(right); 1.124 - int d = list->cmpfunc(leftValue, rightValue); 1.125 + int d = list->base.cmpfunc(leftValue, rightValue); 1.126 if (d != 0) { 1.127 return d; 1.128 } 1.129 @@ -309,7 +311,7 @@ 1.130 } 1.131 return 0; 1.132 } else { 1.133 - return list->size < other->size ? -1 : 1; 1.134 + return list->base.size < other->base.size ? -1 : 1; 1.135 } 1.136 } else { 1.137 // lists are compatible 1.138 @@ -322,7 +324,7 @@ 1.139 size_t index 1.140 ) { 1.141 CxIterator it = list->cl->iterator(list, index, false); 1.142 - it.mutating = true; 1.143 + it.base.mutating = true; 1.144 return it; 1.145 } 1.146 1.147 @@ -331,6 +333,6 @@ 1.148 size_t index 1.149 ) { 1.150 CxIterator it = list->cl->iterator(list, index, true); 1.151 - it.mutating = true; 1.152 + it.base.mutating = true; 1.153 return it; 1.154 }