1.1 --- a/src/cx/list.h Mon Apr 18 16:56:29 2022 +0200 1.2 +++ b/src/cx/list.h Mon Apr 18 17:26:21 2022 +0200 1.3 @@ -71,13 +71,6 @@ 1.4 */ 1.5 CxAllocator const *allocator; 1.6 /** 1.7 - * An optional destructor for the list contents. 1.8 - * 1.9 - * @attention Read the documentation of the particular list implementation 1.10 - * whether this destructor shall only destroy the contents or also free the memory. 1.11 - */ 1.12 - cx_destructor_func content_destructor; 1.13 - /** 1.14 * The comparator function for the elements. 1.15 */ 1.16 CxListComparator cmpfunc; 1.17 @@ -93,6 +86,30 @@ 1.18 * The capacity of the list (maximum number of elements). 1.19 */ 1.20 size_t capacity; 1.21 + union { 1.22 + /** 1.23 + * An optional simple destructor for the list contents that admits the free() interface. 1.24 + * 1.25 + * @remark Set content_destructor_type to #CX_DESTRUCTOR_SIMPLE. 1.26 + * 1.27 + * @attention Read the documentation of the particular list implementation 1.28 + * whether this destructor shall only destroy the contents or also free the memory. 1.29 + */ 1.30 + cx_destructor_func simple_destructor; 1.31 + /** 1.32 + * An optional advanced destructor for the list contents providing additional data. 1.33 + * 1.34 + * @remark Set content_destructor_type to #CX_DESTRUCTOR_ADVANCED. 1.35 + * 1.36 + * @attention Read the documentation of the particular list implementation 1.37 + * whether this destructor shall only destroy the contents or also free the memory. 1.38 + */ 1.39 + cx_advanced_destructor advanced_destructor; 1.40 + }; 1.41 + /** 1.42 + * The type of destructor to use. 1.43 + */ 1.44 + enum cx_destructor_type content_destructor_type; 1.45 }; 1.46 1.47 /** 1.48 @@ -389,19 +406,17 @@ 1.49 } 1.50 1.51 /** 1.52 - * Calls the list's destructor function for every element. 1.53 - * If CxList.autofree_content is \c true, the elements are automatically free'd 1.54 - * unless the content destructor function did not already do that. 1.55 - * Similarly, if CxList.autofree is \c true, the list structure is free'd, unless 1.56 - * the list destructor function did not already do that. 1.57 + * Deallocates the memory of the specified list structure. 1.58 + * 1.59 + * Also calls content a destructor function, depending on the configuration 1.60 + * in CxList.content_destructor_type. 1.61 * 1.62 * This function itself is a destructor function for the CxList. 1.63 * 1.64 - * @param list the list which contents shall be destroyed 1.65 - * @return \p list if the list structure has not been free'd during the process 1.66 + * @param list the list which shall be destroyed 1.67 */ 1.68 __attribute__((__nonnull__)) 1.69 -CxList *cxListDestroy(CxList *list); 1.70 +void cxListDestroy(CxList *list); 1.71 1.72 #ifdef __cplusplus 1.73 } /* extern "C" */