Wed, 18 Oct 2017 14:23:57 +0200
removes unnecessary macros from ucx.h + removes the usage of restrict and _Bool completely, instead of defining macros
configure.ac | file | annotate | diff | comparison | revisions | |
src/Makefile.am | file | annotate | diff | comparison | revisions | |
src/list.c | file | annotate | diff | comparison | revisions | |
src/map.c | file | annotate | diff | comparison | revisions | |
src/mempool.c | file | annotate | diff | comparison | revisions | |
src/ucx/map.h | file | annotate | diff | comparison | revisions | |
src/ucx/ucx.h | file | annotate | diff | comparison | revisions | |
test/main.c | file | annotate | diff | comparison | revisions | |
test/mpool_tests.c | file | annotate | diff | comparison | revisions |
--- a/configure.ac Wed Oct 18 12:03:44 2017 +0200 +++ b/configure.ac Wed Oct 18 14:23:57 2017 +0200 @@ -1,4 +1,6 @@ -AC_INIT([ucx], [0.13], [olaf.wintermann@gmail.com]) +# the package version must match the macros in ucx.h +# if you change the package version, don't forget to adjust the library version +AC_INIT([ucx], [0.14], [olaf.wintermann@gmail.com]) AC_CONFIG_AUX_DIR([build-aux]) AC_CONFIG_MACRO_DIR([m4]) AM_INIT_AUTOMAKE([foreign -Wall -Werror])
--- a/src/Makefile.am Wed Oct 18 12:03:44 2017 +0200 +++ b/src/Makefile.am Wed Oct 18 14:23:57 2017 +0200 @@ -1,4 +1,5 @@ lib_LTLIBRARIES = libucx.la +libucx_la_LDFLAGS = -version-info 1:0:0 libucx_la_SOURCES = utils.c libucx_la_SOURCES += list.c libucx_la_SOURCES += map.c
--- a/src/list.c Wed Oct 18 12:03:44 2017 +0200 +++ b/src/list.c Wed Oct 18 14:23:57 2017 +0200 @@ -241,7 +241,7 @@ } static UcxList *ucx_list_sort_merge(int length, - UcxList* restrict ls, UcxList* restrict le, UcxList* restrict re, + UcxList* ls, UcxList* le, UcxList* re, cmp_func fnc, void* data) { UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length); @@ -291,7 +291,7 @@ UcxList *lc; int ln = 1; - UcxList *restrict ls = l, *restrict le, *restrict re; + UcxList *ls = l, *le, *re; // check how many elements are already sorted lc = ls;
--- a/src/map.c Wed Oct 18 12:03:44 2017 +0200 +++ b/src/map.c Wed Oct 18 14:23:57 2017 +0200 @@ -99,8 +99,7 @@ map->count = 0; } -int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to, - copy_func fnc, void *data) { +int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data) { UcxMapIterator i = ucx_map_iterator(from); void *value; UCX_MAP_FOREACH(key, value, i) { @@ -155,8 +154,8 @@ } size_t slot = key.hash%map->size; - UcxMapElement *restrict elm = map->map[slot]; - UcxMapElement *restrict prev = NULL; + UcxMapElement *elm = map->map[slot]; + UcxMapElement *prev = NULL; while (elm && elm->key.hash < key.hash) { prev = elm; @@ -194,14 +193,14 @@ return 0; } -void* ucx_map_get_and_remove(UcxMap *map, UcxKey key, _Bool remove) { +static void* ucx_map_get_and_remove(UcxMap *map, UcxKey key, int remove) { if(key.hash == 0) { key.hash = ucx_hash((char*)key.data, key.len); } size_t slot = key.hash%map->size; - UcxMapElement *restrict elm = map->map[slot]; - UcxMapElement *restrict pelm = NULL; + UcxMapElement *elm = map->map[slot]; + UcxMapElement *pelm = NULL; while (elm && elm->key.hash <= key.hash) { if(elm->key.hash == key.hash) { int n = (key.len > elm->key.len) ? elm->key.len : key.len;
--- a/src/mempool.c Wed Oct 18 12:03:44 2017 +0200 +++ b/src/mempool.c Wed Oct 18 14:23:57 2017 +0200 @@ -56,7 +56,10 @@ void *ptr; } ucx_regdestr; -UCX_EXTERN void ucx_mempool_shared_destr(void* ptr) { +#ifdef __cplusplus +extern "C" +#endif +void ucx_mempool_shared_destr(void* ptr) { ucx_regdestr *rd = (ucx_regdestr*)ptr; rd->destructor(rd->ptr); }
--- a/src/ucx/map.h Wed Oct 18 12:03:44 2017 +0200 +++ b/src/ucx/map.h Wed Oct 18 14:23:57 2017 +0200 @@ -198,8 +198,7 @@ * @param data additional data for the copy function * @return 0 on success or a non-zero value on memory allocation errors */ -int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to, - copy_func fnc, void *data); +int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data); /** * Clones the map and rehashes if necessary.
--- a/src/ucx/ucx.h Wed Oct 18 12:03:44 2017 +0200 +++ b/src/ucx/ucx.h Wed Oct 18 14:23:57 2017 +0200 @@ -40,7 +40,7 @@ #define UCX_VERSION_MAJOR 0 /** Minor UCX version as integer constant. */ -#define UCX_VERSION_MINOR 13 +#define UCX_VERSION_MINOR 14 #include <stdlib.h> #include <stdint.h> @@ -57,16 +57,7 @@ #endif /* _WIN32 */ #ifdef __cplusplus -#ifndef _Bool -#define _Bool bool -#define restrict -#endif -/** Use C naming even when compiling with C++. */ -#define UCX_EXTERN extern "C" extern "C" { -#else -/** Pointless in C. */ -#define UCX_EXTERN #endif
--- a/test/main.c Wed Oct 18 12:03:44 2017 +0200 +++ b/test/main.c Wed Oct 18 14:23:57 2017 +0200 @@ -45,58 +45,60 @@ #include "utils_tests.h" #include "avl_tests.h" -UCX_EXTERN UCX_TEST(testTestSuitePositive) { - UCX_TEST_BEGIN - UCX_TEST_ASSERT(2*2 == 4, "the test framework fails"); - UCX_TEST_END -} +extern "C" { + UCX_TEST(testTestSuitePositive) { + UCX_TEST_BEGIN + UCX_TEST_ASSERT(2*2 == 4, "the test framework fails"); + UCX_TEST_END + } -UCX_EXTERN UCX_TEST(testTestSuiteNegative) { - UCX_TEST_BEGIN - UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works"); - UCX_TEST_END -} + UCX_TEST(testTestSuiteNegative) { + UCX_TEST_BEGIN + UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works"); + UCX_TEST_END + } -UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) { - UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails"); -} + UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) { + UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails"); + } -UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) { - UCX_TEST_ASSERT(i == 42, "two parameter routine fails"); - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f); -} + UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) { + UCX_TEST_ASSERT(i == 42, "two parameter routine fails"); + UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f); + } -UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) { - *i += 2; - UCX_TEST_ASSERT(*i==4, "the test framework fails"); -} + UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) { + *i += 2; + UCX_TEST_ASSERT(*i==4, "the test framework fails"); + } -UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) { - *i += 2; - // Next test shall fail! - UCX_TEST_ASSERT(*i==4, "the test framework works"); -} + UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) { + *i += 2; + // Next test shall fail! + UCX_TEST_ASSERT(*i==4, "the test framework works"); + } + + UCX_TEST(testTestSuiteRoutinePositive) { + int i = 2; + UCX_TEST_BEGIN + UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i); + UCX_TEST_ASSERT(i==4, "the test framework fails"); + UCX_TEST_END + } -UCX_EXTERN UCX_TEST(testTestSuiteRoutinePositive) { - int i = 2; - UCX_TEST_BEGIN - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i); - UCX_TEST_ASSERT(i==4, "the test framework fails"); - UCX_TEST_END -} + UCX_TEST(testTestSuiteRoutineNegative) { + int i = 0; + UCX_TEST_BEGIN + UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i); + UCX_TEST_ASSERT(1, "the test framework fails"); + UCX_TEST_END + } -UCX_EXTERN UCX_TEST(testTestSuiteRoutineNegative) { - int i = 0; - UCX_TEST_BEGIN - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i); - UCX_TEST_ASSERT(1, "the test framework fails"); - UCX_TEST_END -} - -UCX_EXTERN UCX_TEST(testTestSuiteRoutineMultiparam) { - UCX_TEST_BEGIN - UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f); - UCX_TEST_END + UCX_TEST(testTestSuiteRoutineMultiparam) { + UCX_TEST_BEGIN + UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f); + UCX_TEST_END + } } int main(int argc, char **argv) {
--- a/test/mpool_tests.c Wed Oct 18 12:03:44 2017 +0200 +++ b/test/mpool_tests.c Wed Oct 18 14:23:57 2017 +0200 @@ -123,7 +123,10 @@ ucx_mempool_destroy(pool); } -UCX_EXTERN void test_setdestr(void* elem) { +#ifdef __cplusplus +extern "C" +#endif +void test_setdestr(void* elem) { intptr_t *cb = (intptr_t*) ((intptr_t*) elem)[1]; *cb = 42; }