removes unnecessary macros from ucx.h + removes the usage of restrict and _Bool completely, instead of defining macros

Wed, 18 Oct 2017 14:23:57 +0200

author
Mike Becker <universe@uap-core.de>
date
Wed, 18 Oct 2017 14:23:57 +0200
changeset 253
e19825a1430a
parent 252
6342cbbd1922
child 254
c45c385ac578

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
     1.1 --- a/configure.ac	Wed Oct 18 12:03:44 2017 +0200
     1.2 +++ b/configure.ac	Wed Oct 18 14:23:57 2017 +0200
     1.3 @@ -1,4 +1,6 @@
     1.4 -AC_INIT([ucx], [0.13], [olaf.wintermann@gmail.com])
     1.5 +# the package version must match the macros in ucx.h
     1.6 +# if you change the package version, don't forget to adjust the library version
     1.7 +AC_INIT([ucx], [0.14], [olaf.wintermann@gmail.com])
     1.8  AC_CONFIG_AUX_DIR([build-aux])
     1.9  AC_CONFIG_MACRO_DIR([m4])
    1.10  AM_INIT_AUTOMAKE([foreign -Wall -Werror])
     2.1 --- a/src/Makefile.am	Wed Oct 18 12:03:44 2017 +0200
     2.2 +++ b/src/Makefile.am	Wed Oct 18 14:23:57 2017 +0200
     2.3 @@ -1,4 +1,5 @@
     2.4  lib_LTLIBRARIES = libucx.la
     2.5 +libucx_la_LDFLAGS = -version-info 1:0:0
     2.6  libucx_la_SOURCES = utils.c
     2.7  libucx_la_SOURCES += list.c
     2.8  libucx_la_SOURCES += map.c
     3.1 --- a/src/list.c	Wed Oct 18 12:03:44 2017 +0200
     3.2 +++ b/src/list.c	Wed Oct 18 14:23:57 2017 +0200
     3.3 @@ -241,7 +241,7 @@
     3.4  }
     3.5  
     3.6  static UcxList *ucx_list_sort_merge(int length,
     3.7 -        UcxList* restrict ls, UcxList* restrict le, UcxList* restrict re,
     3.8 +        UcxList* ls, UcxList* le, UcxList* re,
     3.9          cmp_func fnc, void* data) {
    3.10  
    3.11      UcxList** sorted = (UcxList**) malloc(sizeof(UcxList*)*length);
    3.12 @@ -291,7 +291,7 @@
    3.13      UcxList *lc;
    3.14      int ln = 1;
    3.15  
    3.16 -    UcxList *restrict ls = l, *restrict le, *restrict re;
    3.17 +    UcxList *ls = l, *le, *re;
    3.18      
    3.19      // check how many elements are already sorted
    3.20      lc = ls;
     4.1 --- a/src/map.c	Wed Oct 18 12:03:44 2017 +0200
     4.2 +++ b/src/map.c	Wed Oct 18 14:23:57 2017 +0200
     4.3 @@ -99,8 +99,7 @@
     4.4      map->count = 0;
     4.5  }
     4.6  
     4.7 -int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to,
     4.8 -        copy_func fnc, void *data) {
     4.9 +int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data) {
    4.10      UcxMapIterator i = ucx_map_iterator(from);
    4.11      void *value;
    4.12      UCX_MAP_FOREACH(key, value, i) {
    4.13 @@ -155,8 +154,8 @@
    4.14      }
    4.15  
    4.16      size_t slot = key.hash%map->size;
    4.17 -    UcxMapElement *restrict elm = map->map[slot];
    4.18 -    UcxMapElement *restrict prev = NULL;
    4.19 +    UcxMapElement *elm = map->map[slot];
    4.20 +    UcxMapElement *prev = NULL;
    4.21  
    4.22      while (elm && elm->key.hash < key.hash) {
    4.23          prev = elm;
    4.24 @@ -194,14 +193,14 @@
    4.25      return 0;
    4.26  }
    4.27  
    4.28 -void* ucx_map_get_and_remove(UcxMap *map, UcxKey key, _Bool remove) {
    4.29 +static void* ucx_map_get_and_remove(UcxMap *map, UcxKey key, int remove) {
    4.30      if(key.hash == 0) {
    4.31          key.hash = ucx_hash((char*)key.data, key.len);
    4.32      }
    4.33      
    4.34      size_t slot = key.hash%map->size;
    4.35 -    UcxMapElement *restrict elm = map->map[slot];
    4.36 -    UcxMapElement *restrict pelm = NULL;
    4.37 +    UcxMapElement *elm = map->map[slot];
    4.38 +    UcxMapElement *pelm = NULL;
    4.39      while (elm && elm->key.hash <= key.hash) {
    4.40          if(elm->key.hash == key.hash) {
    4.41              int n = (key.len > elm->key.len) ? elm->key.len : key.len;
     5.1 --- a/src/mempool.c	Wed Oct 18 12:03:44 2017 +0200
     5.2 +++ b/src/mempool.c	Wed Oct 18 14:23:57 2017 +0200
     5.3 @@ -56,7 +56,10 @@
     5.4      void           *ptr;
     5.5  } ucx_regdestr;
     5.6  
     5.7 -UCX_EXTERN void ucx_mempool_shared_destr(void* ptr) {
     5.8 +#ifdef __cplusplus
     5.9 +extern "C"
    5.10 +#endif
    5.11 +void ucx_mempool_shared_destr(void* ptr) {
    5.12      ucx_regdestr *rd = (ucx_regdestr*)ptr;
    5.13      rd->destructor(rd->ptr);
    5.14  }
     6.1 --- a/src/ucx/map.h	Wed Oct 18 12:03:44 2017 +0200
     6.2 +++ b/src/ucx/map.h	Wed Oct 18 14:23:57 2017 +0200
     6.3 @@ -198,8 +198,7 @@
     6.4   * @param data additional data for the copy function
     6.5   * @return 0 on success or a non-zero value on memory allocation errors
     6.6   */
     6.7 -int ucx_map_copy(UcxMap *restrict from, UcxMap *restrict to,
     6.8 -        copy_func fnc, void *data);
     6.9 +int ucx_map_copy(UcxMap *from, UcxMap *to, copy_func fnc, void *data);
    6.10  
    6.11  /**
    6.12   * Clones the map and rehashes if necessary.
     7.1 --- a/src/ucx/ucx.h	Wed Oct 18 12:03:44 2017 +0200
     7.2 +++ b/src/ucx/ucx.h	Wed Oct 18 14:23:57 2017 +0200
     7.3 @@ -40,7 +40,7 @@
     7.4  #define UCX_VERSION_MAJOR   0
     7.5  
     7.6  /** Minor UCX version as integer constant. */
     7.7 -#define UCX_VERSION_MINOR   13
     7.8 +#define UCX_VERSION_MINOR   14
     7.9  
    7.10  #include <stdlib.h>
    7.11  #include <stdint.h>
    7.12 @@ -57,16 +57,7 @@
    7.13  #endif /* _WIN32 */
    7.14  
    7.15  #ifdef	__cplusplus
    7.16 -#ifndef _Bool
    7.17 -#define _Bool bool
    7.18 -#define restrict
    7.19 -#endif
    7.20 -/** Use C naming even when compiling with C++.  */
    7.21 -#define UCX_EXTERN extern "C"
    7.22  extern "C" {
    7.23 -#else
    7.24 -/** Pointless in C. */
    7.25 -#define UCX_EXTERN
    7.26  #endif
    7.27      
    7.28  
     8.1 --- a/test/main.c	Wed Oct 18 12:03:44 2017 +0200
     8.2 +++ b/test/main.c	Wed Oct 18 14:23:57 2017 +0200
     8.3 @@ -45,58 +45,60 @@
     8.4  #include "utils_tests.h"
     8.5  #include "avl_tests.h"
     8.6  
     8.7 -UCX_EXTERN UCX_TEST(testTestSuitePositive) {
     8.8 -    UCX_TEST_BEGIN
     8.9 -    UCX_TEST_ASSERT(2*2 == 4, "the test framework fails");
    8.10 -    UCX_TEST_END
    8.11 -}
    8.12 +extern "C" {
    8.13 +    UCX_TEST(testTestSuitePositive) {
    8.14 +        UCX_TEST_BEGIN
    8.15 +        UCX_TEST_ASSERT(2*2 == 4, "the test framework fails");
    8.16 +        UCX_TEST_END
    8.17 +    }
    8.18  
    8.19 -UCX_EXTERN UCX_TEST(testTestSuiteNegative) {
    8.20 -    UCX_TEST_BEGIN
    8.21 -    UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works");
    8.22 -    UCX_TEST_END
    8.23 -}
    8.24 +    UCX_TEST(testTestSuiteNegative) {
    8.25 +        UCX_TEST_BEGIN
    8.26 +        UCX_TEST_ASSERT(2*(-2) == 4, "the test framework works");
    8.27 +        UCX_TEST_END
    8.28 +    }
    8.29  
    8.30 -UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) {
    8.31 -    UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails");
    8.32 -}
    8.33 +    UCX_TEST_SUBROUTINE(testTestSuiteRoutineRoutine, float f) {
    8.34 +        UCX_TEST_ASSERT(f == 3.14f, "calling routine in a routine fails");
    8.35 +    }
    8.36  
    8.37 -UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) {
    8.38 -    UCX_TEST_ASSERT(i == 42, "two parameter routine fails");
    8.39 -    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f);
    8.40 -}
    8.41 +    UCX_TEST_SUBROUTINE(testTestSuiteRoutine2Param, int i, float f) {
    8.42 +        UCX_TEST_ASSERT(i == 42, "two parameter routine fails");
    8.43 +        UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineRoutine, f);
    8.44 +    }
    8.45  
    8.46 -UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) {
    8.47 -    *i += 2;
    8.48 -    UCX_TEST_ASSERT(*i==4, "the test framework fails");
    8.49 -}
    8.50 +    UCX_TEST_SUBROUTINE(testTestSuiteRoutineSuccess, int* i) {
    8.51 +        *i += 2;
    8.52 +        UCX_TEST_ASSERT(*i==4, "the test framework fails");
    8.53 +    }
    8.54  
    8.55 -UCX_EXTERN UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) {
    8.56 -    *i += 2;
    8.57 -    // Next test shall fail!
    8.58 -    UCX_TEST_ASSERT(*i==4, "the test framework works");
    8.59 -}
    8.60 +    UCX_TEST_SUBROUTINE(testTestSuiteRoutineFailure, int* i) {
    8.61 +        *i += 2;
    8.62 +        // Next test shall fail!
    8.63 +        UCX_TEST_ASSERT(*i==4, "the test framework works");
    8.64 +    }
    8.65  
    8.66 -UCX_EXTERN UCX_TEST(testTestSuiteRoutinePositive) {
    8.67 -    int i = 2;
    8.68 -    UCX_TEST_BEGIN
    8.69 -    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i);
    8.70 -    UCX_TEST_ASSERT(i==4, "the test framework fails");
    8.71 -    UCX_TEST_END
    8.72 -}
    8.73 +    UCX_TEST(testTestSuiteRoutinePositive) {
    8.74 +        int i = 2;
    8.75 +        UCX_TEST_BEGIN
    8.76 +        UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineSuccess, &i);
    8.77 +        UCX_TEST_ASSERT(i==4, "the test framework fails");
    8.78 +        UCX_TEST_END
    8.79 +    }
    8.80  
    8.81 -UCX_EXTERN UCX_TEST(testTestSuiteRoutineNegative) {
    8.82 -    int i = 0;
    8.83 -    UCX_TEST_BEGIN
    8.84 -    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i);
    8.85 -    UCX_TEST_ASSERT(1, "the test framework fails");
    8.86 -    UCX_TEST_END
    8.87 -}
    8.88 +    UCX_TEST(testTestSuiteRoutineNegative) {
    8.89 +        int i = 0;
    8.90 +        UCX_TEST_BEGIN
    8.91 +        UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutineFailure, &i);
    8.92 +        UCX_TEST_ASSERT(1, "the test framework fails");
    8.93 +        UCX_TEST_END
    8.94 +    }
    8.95  
    8.96 -UCX_EXTERN UCX_TEST(testTestSuiteRoutineMultiparam) {
    8.97 -    UCX_TEST_BEGIN
    8.98 -    UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f);
    8.99 -    UCX_TEST_END
   8.100 +    UCX_TEST(testTestSuiteRoutineMultiparam) {
   8.101 +        UCX_TEST_BEGIN
   8.102 +        UCX_TEST_CALL_SUBROUTINE(testTestSuiteRoutine2Param, 42, 3.14f);
   8.103 +        UCX_TEST_END
   8.104 +    }   
   8.105  }
   8.106  
   8.107  int main(int argc, char **argv) {
     9.1 --- a/test/mpool_tests.c	Wed Oct 18 12:03:44 2017 +0200
     9.2 +++ b/test/mpool_tests.c	Wed Oct 18 14:23:57 2017 +0200
     9.3 @@ -123,7 +123,10 @@
     9.4      ucx_mempool_destroy(pool);
     9.5  }
     9.6  
     9.7 -UCX_EXTERN void test_setdestr(void* elem) {
     9.8 +#ifdef __cplusplus
     9.9 +extern "C"
    9.10 +#endif
    9.11 +void test_setdestr(void* elem) {
    9.12      intptr_t *cb = (intptr_t*) ((intptr_t*) elem)[1];
    9.13      *cb = 42;
    9.14  }

mercurial