# HG changeset patch # User Olaf Wintermann # Date 1376657338 -7200 # Node ID 1aa598f36872b12fb9eaea37f905011686d41fa8 # Parent aa376dba1ba8fc99f5231a50b4d3398dad6617a1 added printf for UcxBuffer + fixed memory leaks diff -r aa376dba1ba8 -r 1aa598f36872 test/buffer_tests.c --- a/test/buffer_tests.c Fri Aug 16 13:40:10 2013 +0200 +++ b/test/buffer_tests.c Fri Aug 16 14:48:58 2013 +0200 @@ -129,7 +129,7 @@ UCX_TEST_END - + ucx_buffer_free(b); } UCX_TEST(test_ucx_buffer_getc) { @@ -262,7 +262,7 @@ UCX_TEST_END - + ucx_buffer_free(b); } UCX_TEST(test_ucx_buffer_extract) { diff -r aa376dba1ba8 -r 1aa598f36872 test/prop_tests.c --- a/test/prop_tests.c Fri Aug 16 13:40:10 2013 +0200 +++ b/test/prop_tests.c Fri Aug 16 14:48:58 2013 +0200 @@ -27,6 +27,7 @@ */ #include "prop_tests.h" +#include "ucx/mempool.h" UCX_TEST(test_ucx_properties_new) { UcxProperties *parser = ucx_properties_new(); @@ -363,7 +364,9 @@ } UCX_TEST(test_ucx_properties2map) { - UcxMap *map = ucx_map_new(16); + UcxMempool *mp = ucx_mempool_new(64); + UcxAllocator *a = ucx_mempool_allocator(mp); + UcxMap *map = ucx_map_new_a(a, 16); UcxProperties *parser = ucx_properties_new(); UCX_TEST_BEGIN @@ -390,10 +393,7 @@ // second test ucx_map_free(map); - free(v1); - free(v2); - free(v3); - map = ucx_map_new(16); + map = ucx_map_new_a(a, 16); str = "\n#comment\n"; ucx_properties_fill(parser, (char*)str, strlen(str)); @@ -414,6 +414,7 @@ UCX_TEST_END + ucx_mempool_destroy(mp); ucx_properties_free(parser); } @@ -477,6 +478,9 @@ ucx_map_free(map); fclose(f); + free(long_name); + free(long_value); + UCX_TEST_END } diff -r aa376dba1ba8 -r 1aa598f36872 test/string_tests.c --- a/test/string_tests.c Fri Aug 16 13:40:10 2013 +0200 +++ b/test/string_tests.c Fri Aug 16 14:48:58 2013 +0200 @@ -91,6 +91,9 @@ "original string shall be returned as single list element"); UCX_TEST_ASSERT(strcmp(test.ptr, original) == 0, "ndo, original has been modified"); + for(int i=0;ispace, "Hello World\nend.\n"), "wrong content in b1 after second fprintf"); - ucx_fprintf(b2, (write_func)ucx_buffer_write, "%s%s", teststr1, teststr2); + ucx_bprintf(b2, "%s%s", teststr1, teststr2); UCX_TEST_ASSERT(b2->pos == 2046, "wrong length"); UCX_TEST_ASSERT(!memcmp(b2->space, teststr1, 1023), "wrong first half in b2"); @@ -57,6 +57,8 @@ ucx_buffer_free(b1); ucx_buffer_free(b2); + free(teststr1); + free(teststr2); } UCX_TEST(test_ucx_asprintf) { @@ -84,4 +86,7 @@ free(s2.ptr); UCX_TEST_END + + free(teststr1); + free(teststr2); } diff -r aa376dba1ba8 -r 1aa598f36872 ucx/map.c --- a/ucx/map.c Fri Aug 16 13:40:10 2013 +0200 +++ b/ucx/map.c Fri Aug 16 14:48:58 2013 +0200 @@ -200,6 +200,7 @@ } else { map->map[slot] = elm->next; } + map->allocator->free(map->allocator->pool, elm->key.data); map->allocator->free(map->allocator->pool, elm); map->count--; } diff -r aa376dba1ba8 -r 1aa598f36872 ucx/utils.h --- a/ucx/utils.h Fri Aug 16 13:40:10 2013 +0200 +++ b/ucx/utils.h Fri Aug 16 14:48:58 2013 +0200 @@ -29,7 +29,7 @@ /** * @file utils.h * - * Common utilities like compare and copy functions. + * Compare, copy and printf functions. * * @author Mike Becker * @author Olaf Wintermann @@ -230,6 +230,18 @@ */ sstr_t ucx_vasprintf(UcxAllocator *allocator, const char *fmt, va_list ap); +/** + * A printf() like function which writes the output to an + * UcxBuffer. + * + * @param buffer the buffer the data is written to + * @param ... format string and additional arguments + * @return the total number of bytes written + * @see ucx_fprintf() + */ +#define ucx_bprintf(buffer, ...) ucx_fprintf((UcxBuffer*)buffer, \ + (write_func)ucx_buffer_write, __VA_ARGS__) + #ifdef __cplusplus } #endif