# HG changeset patch # User Mike Becker # Date 1644950905 -3600 # Node ID aaf89ce0cbf67310e19ac2c32262703afed9c043 # Parent a89857072ace322151c9992c4dcf4a87ca433b51 add convenience function to configure list memory management diff -r a89857072ace -r aaf89ce0cbf6 src/cx/list.h --- a/src/cx/list.h Tue Feb 15 19:41:48 2022 +0100 +++ b/src/cx/list.h Tue Feb 15 19:48:25 2022 +0100 @@ -193,6 +193,28 @@ typedef struct cx_list_s CxList; /** + * Convenience function to configure the memory management for this a list. + * @param list the list to configure + * @param list_destructor an alternative list destructor to use (if \c NULL, the current destructor remains unchanged) + * @param content_destructor the content destructor to use (if \c NULL, no content destructor is used) + * @param list_autofree a flag indicating, if the list allocator shall free the list, if the destructor did not do that + * @param content_autofree a flag indicating, if the list allocator shall free an element, + * if the content destructor did not do that or no content destructor exists + */ +static inline void cxListMemoryMgmt( + CxList *list, + cx_destructor_func list_destructor, + cx_destructor_func content_destructor, + bool list_autofree, + bool content_autofree +) { + if (list_destructor != NULL) list->list_destructor = list_destructor; + list->content_destructor = content_destructor; + list->autofree = list_autofree; + list->autofree_contents = content_autofree; +} + +/** * Adds an item to the end of the list. * * @param list the list