Thu, 15 Oct 2015 14:59:25 +0200
moved ucx_destructor type to ucx.h and added destructor argument to ucx_map_free_content
ucx/map.c | file | annotate | diff | comparison | revisions | |
ucx/map.h | file | annotate | diff | comparison | revisions | |
ucx/mempool.h | file | annotate | diff | comparison | revisions | |
ucx/ucx.h | file | annotate | diff | comparison | revisions |
1.1 --- a/ucx/map.c Thu Oct 15 14:21:38 2015 +0200 1.2 +++ b/ucx/map.c Thu Oct 15 14:59:25 2015 +0200 1.3 @@ -82,11 +82,11 @@ 1.4 alfree(map->allocator, map); 1.5 } 1.6 1.7 -void ucx_map_free_content(UcxMap *map) { 1.8 +void ucx_map_free_content(UcxMap *map, ucx_destructor destr) { 1.9 UcxMapIterator iter = ucx_map_iterator(map); 1.10 void *val; 1.11 UCX_MAP_FOREACH(key, val, iter) { 1.12 - free(val); 1.13 + destr(val); 1.14 } 1.15 } 1.16
2.1 --- a/ucx/map.h Thu Oct 15 14:21:38 2015 +0200 2.2 +++ b/ucx/map.h Thu Oct 15 14:59:25 2015 +0200 2.3 @@ -158,17 +158,19 @@ 2.4 * Frees the contents of a hash map. 2.5 * 2.6 * This is a convenience function that iterates over the map and passes all 2.7 - * values to the standard library free() function. 2.8 + * values to the specified destructor function (e.g. stdlib free()). 2.9 * 2.10 - * You must ensure, that it is valid to pass each value in the map to free(). 2.11 + * You must ensure, that it is valid to pass each value in the map to the same 2.12 + * destructor function. 2.13 * 2.14 * You should free or clear the map afterwards, as the contents will be invalid. 2.15 * 2.16 * @param map for which the contents shall be freed 2.17 + * @param destr pointer to the destructor function 2.18 * @see ucx_map_free() 2.19 * @see ucx_map_clear() 2.20 */ 2.21 -void ucx_map_free_content(UcxMap *map); 2.22 +void ucx_map_free_content(UcxMap *map, ucx_destructor destr); 2.23 2.24 /** 2.25 * Clears a hash map.
3.1 --- a/ucx/mempool.h Thu Oct 15 14:21:38 2015 +0200 3.2 +++ b/ucx/mempool.h Thu Oct 15 14:59:25 2015 +0200 3.3 @@ -47,13 +47,6 @@ 3.4 #endif 3.5 3.6 /** 3.7 - * A function pointer to a destructor function. 3.8 - * @see ucx_mempool_setdestr() 3.9 - * @see ucx_mempool_regdestr() 3.10 - */ 3.11 -typedef void(*ucx_destructor)(void*); 3.12 - 3.13 -/** 3.14 * UCX mempool structure. 3.15 */ 3.16 typedef struct {
4.1 --- a/ucx/ucx.h Thu Oct 15 14:21:38 2015 +0200 4.2 +++ b/ucx/ucx.h Thu Oct 15 14:59:25 2015 +0200 4.3 @@ -70,6 +70,14 @@ 4.4 /** Pointless in C. */ 4.5 #define UCX_EXTERN 4.6 #endif 4.7 + 4.8 + 4.9 +/** 4.10 + * A function pointer to a destructor function. 4.11 + * @see ucx_mempool_setdestr() 4.12 + * @see ucx_mempool_regdestr() 4.13 + */ 4.14 +typedef void(*ucx_destructor)(void*); 4.15 4.16 /** 4.17 * Function pointer to a compare function.