1.1 --- a/src/list.c Sun May 21 11:52:58 2023 +0200 1.2 +++ b/src/list.c Sun May 21 14:03:21 2023 +0200 1.3 @@ -195,6 +195,83 @@ 1.4 1.5 // </editor-fold> 1.6 1.7 +// <editor-fold desc="empty list implementation"> 1.8 + 1.9 +static void cx_emptyl_noop(__attribute__((__unused__)) CxList *list) { 1.10 + // this is a noop, but MUST be implemented 1.11 +} 1.12 + 1.13 +static void *cx_emptyl_at( 1.14 + __attribute__((__unused__)) struct cx_list_s const *list, 1.15 + __attribute__((__unused__)) size_t index 1.16 +) { 1.17 + return NULL; 1.18 +} 1.19 + 1.20 +static ssize_t cx_emptyl_find( 1.21 + __attribute__((__unused__)) struct cx_list_s const *list, 1.22 + __attribute__((__unused__)) void const *elem 1.23 +) { 1.24 + return -1; 1.25 +} 1.26 + 1.27 +static int cx_emptyl_compare( 1.28 + __attribute__((__unused__)) struct cx_list_s const *list, 1.29 + struct cx_list_s const *other 1.30 +) { 1.31 + if (other->size == 0) return 0; 1.32 + return -1; 1.33 +} 1.34 + 1.35 +static bool cx_emptyl_iter_valid(__attribute__((__unused__)) void const *iter) { 1.36 + return false; 1.37 +} 1.38 + 1.39 +static CxIterator cx_emptyl_iterator( 1.40 + struct cx_list_s const *list, 1.41 + size_t index, 1.42 + __attribute__((__unused__)) bool backwards 1.43 +) { 1.44 + CxIterator iter = {0}; 1.45 + iter.src_handle = list; 1.46 + iter.index = index; 1.47 + iter.base.valid = cx_emptyl_iter_valid; 1.48 + return iter; 1.49 +} 1.50 + 1.51 +static cx_list_class cx_empty_list_class = { 1.52 + cx_emptyl_noop, 1.53 + NULL, 1.54 + NULL, 1.55 + NULL, 1.56 + NULL, 1.57 + cx_emptyl_noop, 1.58 + NULL, 1.59 + cx_emptyl_at, 1.60 + cx_emptyl_find, 1.61 + cx_emptyl_noop, 1.62 + cx_emptyl_compare, 1.63 + cx_emptyl_noop, 1.64 + cx_emptyl_iterator, 1.65 +}; 1.66 + 1.67 +CxList cx_empty_list = { 1.68 + NULL, 1.69 + NULL, 1.70 + 0, 1.71 + 0, 1.72 + NULL, 1.73 + NULL, 1.74 + NULL, 1.75 + false, 1.76 + &cx_empty_list_class, 1.77 + NULL 1.78 +}; 1.79 + 1.80 +CxList *const cxEmptyList = &cx_empty_list; 1.81 + 1.82 +// </editor-fold> 1.83 + 1.84 void cxListDestroy(CxList *list) { 1.85 if (list->simple_destructor) { 1.86 CxIterator iter = cxListIterator(list); 1.87 @@ -212,7 +289,9 @@ 1.88 } 1.89 1.90 list->cl->destructor(list); 1.91 - cxFree(list->allocator, list); 1.92 + if (list->allocator) { 1.93 + cxFree(list->allocator, list); 1.94 + } 1.95 } 1.96 1.97 int cxListCompare(