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 |
--- a/ucx/map.c Thu Oct 15 14:21:38 2015 +0200 +++ b/ucx/map.c Thu Oct 15 14:59:25 2015 +0200 @@ -82,11 +82,11 @@ alfree(map->allocator, map); } -void ucx_map_free_content(UcxMap *map) { +void ucx_map_free_content(UcxMap *map, ucx_destructor destr) { UcxMapIterator iter = ucx_map_iterator(map); void *val; UCX_MAP_FOREACH(key, val, iter) { - free(val); + destr(val); } }
--- a/ucx/map.h Thu Oct 15 14:21:38 2015 +0200 +++ b/ucx/map.h Thu Oct 15 14:59:25 2015 +0200 @@ -158,17 +158,19 @@ * Frees the contents of a hash map. * * This is a convenience function that iterates over the map and passes all - * values to the standard library free() function. + * values to the specified destructor function (e.g. stdlib free()). * - * You must ensure, that it is valid to pass each value in the map to free(). + * You must ensure, that it is valid to pass each value in the map to the same + * destructor function. * * You should free or clear the map afterwards, as the contents will be invalid. * * @param map for which the contents shall be freed + * @param destr pointer to the destructor function * @see ucx_map_free() * @see ucx_map_clear() */ -void ucx_map_free_content(UcxMap *map); +void ucx_map_free_content(UcxMap *map, ucx_destructor destr); /** * Clears a hash map.
--- a/ucx/mempool.h Thu Oct 15 14:21:38 2015 +0200 +++ b/ucx/mempool.h Thu Oct 15 14:59:25 2015 +0200 @@ -47,13 +47,6 @@ #endif /** - * A function pointer to a destructor function. - * @see ucx_mempool_setdestr() - * @see ucx_mempool_regdestr() - */ -typedef void(*ucx_destructor)(void*); - -/** * UCX mempool structure. */ typedef struct {
--- a/ucx/ucx.h Thu Oct 15 14:21:38 2015 +0200 +++ b/ucx/ucx.h Thu Oct 15 14:59:25 2015 +0200 @@ -70,6 +70,14 @@ /** Pointless in C. */ #define UCX_EXTERN #endif + + +/** + * A function pointer to a destructor function. + * @see ucx_mempool_setdestr() + * @see ucx_mempool_regdestr() + */ +typedef void(*ucx_destructor)(void*); /** * Function pointer to a compare function.