# HG changeset patch # User Mike Becker # Date 1716494792 -7200 # Node ID 4d12e34bb1304e4a2ca1e408ecf2fb85093de266 # Parent 6bbbf219251dd34e44c9f0427575feb0ec9e5d55 add missing convenience functions diff -r 6bbbf219251d -r 4d12e34bb130 src/cx/collection.h --- a/src/cx/collection.h Thu May 23 20:43:04 2024 +0200 +++ b/src/cx/collection.h Thu May 23 22:06:32 2024 +0200 @@ -100,6 +100,25 @@ #define CX_COLLECTION_BASE struct cx_collection_s collection /** + * Sets a simple destructor function for this collection. + * + * @param c the collection + * @param destr the destructor function + */ +#define cxDefineDestructor(c, destr) \ + (c)->collection.simple_destructor = (cx_destructor_func) destr + +/** + * Sets a simple destructor function for this collection. + * + * @param c the collection + * @param destr the destructor function + */ +#define cxDefineAdvancedDestructor(c, destr, data) \ + (c)->collection.advanced_destructor = (cx_destructor_func2) destr; \ + (c)->collection.destructor_data = data + +/** * Invokes the simple destructor function for a specific element. * * Usually only used by collection implementations. There should be no need diff -r 6bbbf219251d -r 4d12e34bb130 src/cx/map.h --- a/src/cx/map.h Thu May 23 20:43:04 2024 +0200 +++ b/src/cx/map.h Thu May 23 22:06:32 2024 +0200 @@ -187,6 +187,17 @@ map->collection.elem_size = sizeof(void *); } +/** + * Returns true, if this map is storing pointers instead of the actual data. + * + * @param map + * @return true, if this map is storing pointers + * @see cxMapStorePointers() + */ +__attribute__((__nonnull__)) +static inline bool cxMapIsStoringPointers(CxMap const *map) { + return map->collection.store_pointer; +} /** * Deallocates the memory of the specified map. diff -r 6bbbf219251d -r 4d12e34bb130 tests/test_list.c --- a/tests/test_list.c Thu May 23 20:43:04 2024 +0200 +++ b/tests/test_list.c Thu May 23 22:06:32 2024 +0200 @@ -1395,7 +1395,7 @@ roll_out_test_combos(simple_destr, { const size_t len = 60; int *testdata = int_test_data_added_to_list(list, isptrlist, len); - list->collection.simple_destructor = simple_destr_test_fun; + cxDefineDestructor(list, simple_destr_test_fun); CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len); free(testdata); }) @@ -1403,7 +1403,7 @@ roll_out_test_combos(advanced_destr, { const size_t len = 75; int *testdata = int_test_data_added_to_list(list, isptrlist, len); - list->collection.advanced_destructor = advanced_destr_test_fun; + cxDefineAdvancedDestructor(list, advanced_destr_test_fun, NULL); CX_TEST_CALL_SUBROUTINE(test_list_verify_destructor, list, testdata, len); free(testdata); })