removes some bugs by redesigning the array API

Thu, 07 Nov 2019 10:10:36 +0100

author
Mike Becker <universe@uap-core.de>
date
Thu, 07 Nov 2019 10:10:36 +0100
changeset 369
28a8ccc442b0
parent 368
97c53f7ef5e4
child 370
07ac32b385e4

removes some bugs by redesigning the array API

src/array.c file | annotate | diff | comparison | revisions
src/ucx/array.h file | annotate | diff | comparison | revisions
test/array_tests.c file | annotate | diff | comparison | revisions
test/array_tests.h file | annotate | diff | comparison | revisions
test/main.c file | annotate | diff | comparison | revisions
     1.1 --- a/src/array.c	Wed Nov 06 21:01:25 2019 +0100
     1.2 +++ b/src/array.c	Thu Nov 07 10:10:36 2019 +0100
     1.3 @@ -70,7 +70,7 @@
     1.4  }
     1.5  
     1.6  int ucx_array_util_set_a(UcxAllocator* alloc, void** array, size_t* capacity,
     1.7 -    size_t elmsize, size_t index, ...) {
     1.8 +    size_t elmsize, size_t index, void* data) {
     1.9      
    1.10      if(!alloc || !capacity || !array) {
    1.11          errno = EINVAL;
    1.12 @@ -104,16 +104,18 @@
    1.13      
    1.14      char* dest = *array;
    1.15      dest += elmsize*index;
    1.16 -
    1.17 -    va_list ap;
    1.18 -    va_start(ap, index);
    1.19 -    int elem = va_arg(ap, int);    
    1.20 -    memcpy(dest, &elem, elmsize);
    1.21 -    va_end(ap);
    1.22 +    memcpy(dest, data, elmsize);
    1.23      
    1.24      return 0;
    1.25  }
    1.26  
    1.27 +int ucx_array_util_setptr_a(UcxAllocator* alloc, void** array, size_t* capacity,
    1.28 +    size_t index, void* data) {
    1.29 +    
    1.30 +    return ucx_array_util_set_a(alloc, array, capacity, sizeof(void*),
    1.31 +            index, &data);
    1.32 +}
    1.33 +
    1.34  UcxArray* ucx_array_new(size_t capacity, size_t elemsize) {
    1.35      return ucx_array_new_a(capacity, elemsize, ucx_default_allocator());
    1.36  }
    1.37 @@ -254,33 +256,6 @@
    1.38      return 0;
    1.39  }
    1.40  
    1.41 -int ucx_array_appendv(UcxArray *array, ...) {
    1.42 -    va_list ap;
    1.43 -    va_start(ap, array);
    1.44 -    int elem = va_arg(ap, int);
    1.45 -    int ret = ucx_array_append_from(array, &elem, 1);
    1.46 -    va_end(ap);
    1.47 -    return ret;
    1.48 -}
    1.49 -
    1.50 -int ucx_array_prependv(UcxArray *array, ...) {
    1.51 -    va_list ap;
    1.52 -    va_start(ap, array);
    1.53 -    int elem = va_arg(ap, int);
    1.54 -    int ret = ucx_array_prepend_from(array, &elem, 1);
    1.55 -    va_end(ap);
    1.56 -    return ret;
    1.57 -}
    1.58 -
    1.59 -int ucx_array_setv(UcxArray *array, size_t index, ...) {
    1.60 -    va_list ap;
    1.61 -    va_start(ap, index);
    1.62 -    int elem = va_arg(ap, int);
    1.63 -    int ret = ucx_array_set_from(array, index, &elem, 1);
    1.64 -    va_end(ap);
    1.65 -    return ret;
    1.66 -}
    1.67 -
    1.68  int ucx_array_concat(UcxArray *array1, const UcxArray *array2) {
    1.69      
    1.70      if (array1->elemsize != array2->elemsize)
    1.71 @@ -486,3 +461,7 @@
    1.72          }
    1.73      }
    1.74  }
    1.75 +
    1.76 +int ucx_array_grow(UcxArray* array, size_t count) {
    1.77 +    return ucx_array_reserve(array, array->size+count);
    1.78 +}
     2.1 --- a/src/ucx/array.h	Wed Nov 06 21:01:25 2019 +0100
     2.2 +++ b/src/ucx/array.h	Thu Nov 07 10:10:36 2019 +0100
     2.3 @@ -71,6 +71,7 @@
     2.4  
     2.5  /**
     2.6   * Sets an element in an arbitrary user defined array.
     2.7 + * The data is copied from the specified data location.
     2.8   * 
     2.9   * If the capacity is insufficient, the array is automatically reallocated and
    2.10   * the possibly new pointer is stored in the <code>array</code> argument.
    2.11 @@ -82,7 +83,7 @@
    2.12   * @param capacity a pointer to the capacity
    2.13   * @param elmsize the size of each element
    2.14   * @param idx the index of the element to set
    2.15 - * @param data the element data
    2.16 + * @param data a pointer to the element data
    2.17   * @return zero on success or non-zero on error (errno will be set)
    2.18   */
    2.19  #define ucx_array_util_set(array, capacity, elmsize, idx, data) \
    2.20 @@ -90,22 +91,8 @@
    2.21                           elmsize, idx, data)
    2.22  
    2.23  /**
    2.24 - * Convenience macro for ucx_array_util_set() which automatically computes
    2.25 - * <code>sizeof(data)</code>.
    2.26 - * 
    2.27 - * @param array a pointer to location of the array pointer
    2.28 - * @param capacity a pointer to the capacity
    2.29 - * @param idx the index of the element to set
    2.30 - * @param data the element data
    2.31 - * @return zero on success or non-zero on error (errno will be set)
    2.32 - * @see ucx_array_util_set()
    2.33 - */
    2.34 -#define UCX_ARRAY_UTIL_SET(array, capacity, idx, data) \
    2.35 -    ucx_array_util_set_a(ucx_default_allocator(), (void**)(array), capacity, \
    2.36 -                         sizeof(data), idx, data)
    2.37 -
    2.38 -/**
    2.39   * Sets an element in an arbitrary user defined array.
    2.40 + * The data is copied from the specified data location.
    2.41   * 
    2.42   * If the capacity is insufficient, the array is automatically reallocated
    2.43   * using the specified allocator and the possibly new pointer is stored in
    2.44 @@ -119,27 +106,53 @@
    2.45   * @param capacity a pointer to the capacity
    2.46   * @param elmsize the size of each element
    2.47   * @param idx the index of the element to set
    2.48 - * @param ... the element data
    2.49 + * @param data a pointer to the element data
    2.50   * @return zero on success or non-zero on error (errno will be set)
    2.51   */
    2.52  int ucx_array_util_set_a(UcxAllocator* alloc, void** array, size_t* capacity,
    2.53 -    size_t elmsize, size_t idx, ...);
    2.54 -
    2.55 +    size_t elmsize, size_t idx, void* data);
    2.56  
    2.57  /**
    2.58 - * Convenience macro for ucx_array_util_set_a() which automatically computes
    2.59 - * <code>sizeof(data)</code>.
    2.60 + * Stores a pointer in an arbitrary user defined array.
    2.61 + * The element size of the array must be sizeof(void*).
    2.62 + * 
    2.63 + * If the capacity is insufficient, the array is automatically reallocated and
    2.64 + * the possibly new pointer is stored in the <code>array</code> argument.
    2.65 + * 
    2.66 + * On reallocation the capacity of the array is doubled until it is sufficient.
    2.67 + * The new capacity is stored back to <code>capacity</code>.
    2.68 + *  
    2.69 + * @param array a pointer to location of the array pointer
    2.70 + * @param capacity a pointer to the capacity
    2.71 + * @param idx the index of the element to set
    2.72 + * @param ptr the pointer to store
    2.73 + * @return zero on success or non-zero on error (errno will be set)
    2.74 + */
    2.75 +#define ucx_array_util_setptr(array, capacity, idx, ptr) \
    2.76 +    ucx_array_util_setptr_a(ucx_default_allocator(), (void**)(array), \
    2.77 +                            capacity, idx, ptr)
    2.78 +
    2.79 +/**
    2.80 + * Stores a pointer in an arbitrary user defined array.
    2.81 + * The element size of the array must be sizeof(void*).
    2.82 + * 
    2.83 + * If the capacity is insufficient, the array is automatically reallocated
    2.84 + * using the specified allocator and the possibly new pointer is stored in
    2.85 + * the <code>array</code> argument.
    2.86 + * 
    2.87 + * On reallocation the capacity of the array is doubled until it is sufficient.
    2.88 + * The new capacity is stored back to <code>capacity</code>. 
    2.89   * 
    2.90   * @param alloc the allocator that shall be used to reallocate the array
    2.91   * @param array a pointer to location of the array pointer
    2.92   * @param capacity a pointer to the capacity
    2.93   * @param idx the index of the element to set
    2.94 - * @param data the element data
    2.95 + * @param ptr the pointer to store
    2.96   * @return zero on success or non-zero on error (errno will be set)
    2.97 - * @see ucx_array_util_set_a()
    2.98   */
    2.99 -#define UCX_ARRAY_UTIL_SET_A(alloc, array, capacity, idx, data) \
   2.100 -    ucx_array_util_set_a(alloc, capacity, sizeof(data), idx, data)
   2.101 +int ucx_array_util_setptr_a(UcxAllocator* alloc, void** array, size_t* capacity,
   2.102 +    size_t idx, void* ptr);
   2.103 +
   2.104  
   2.105  /**
   2.106   * Creates a new UCX array with the given capacity and element size.
   2.107 @@ -291,88 +304,6 @@
   2.108  int ucx_array_set_from(UcxArray *array, size_t index, void *data, size_t count);
   2.109  
   2.110  /**
   2.111 - * Inserts an element at the end of the array.
   2.112 - * 
   2.113 - * This is an O(1) operation.
   2.114 - * The array will automatically grow, if the capacity is exceeded.
   2.115 - * If the type of the argument has a different size than the element size of
   2.116 - * this array, the behavior is undefined.
   2.117 - * 
   2.118 - * @param array a pointer the array where to append the data
   2.119 - * @param elem the value to insert
   2.120 - * @return zero on success, non-zero if a reallocation was necessary but failed
   2.121 - * @see ucx_array_append_from()
   2.122 - * @see ucx_array_set()
   2.123 - */
   2.124 -#define ucx_array_append(array, elem) ucx_array_appendv(array, elem)
   2.125 -
   2.126 -/**
   2.127 - * For internal use.
   2.128 - * Use ucx_array_append()
   2.129 - * 
   2.130 - * @param array
   2.131 - * @param ... 
   2.132 - * @return 
   2.133 - * @see ucx_array_append()
   2.134 - */
   2.135 -int ucx_array_appendv(UcxArray *array, ...);
   2.136 -
   2.137 -
   2.138 -/**
   2.139 - * Inserts an element at the beginning of the array.
   2.140 - * 
   2.141 - * This is an expensive operation, because the contents must be moved.
   2.142 - * If there is no particular reason to prepend data, you should use
   2.143 - * ucx_array_append() instead.
   2.144 - * 
   2.145 - * @param array a pointer the array where to prepend the data
   2.146 - * @param elem the value to insert
   2.147 - * @return zero on success, non-zero if a reallocation was necessary but failed
   2.148 - * @see ucx_array_append()
   2.149 - * @see ucx_array_set_from()
   2.150 - * @see ucx_array_prepend_from()
   2.151 - */
   2.152 -#define ucx_array_prepend(array, elem) ucx_array_prependv(array, elem)
   2.153 -
   2.154 -/**
   2.155 - * For internal use.
   2.156 - * Use ucx_array_prepend()
   2.157 - * 
   2.158 - * @param array
   2.159 - * @param ... 
   2.160 - * @return 
   2.161 - * @see ucx_array_prepend()
   2.162 - */
   2.163 -int ucx_array_prependv(UcxArray *array, ...);
   2.164 -
   2.165 -
   2.166 -/**
   2.167 - * Sets an element at the specified index.
   2.168 - * 
   2.169 - * If the any index is out of bounds, the array automatically grows.
   2.170 - * 
   2.171 - * @param array a pointer the array where to set the data
   2.172 - * @param index the index of the element to set
   2.173 - * @param elem the value to set
   2.174 - * @return zero on success, non-zero if a reallocation was necessary but failed
   2.175 - * @see ucx_array_append()
   2.176 - * @see ucx_array_set_from()
   2.177 - */
   2.178 -#define ucx_array_set(array, index, elem) ucx_array_setv(array, index, elem)
   2.179 -
   2.180 -/**
   2.181 - * For internal use.
   2.182 - * Use ucx_array_set()
   2.183 - * 
   2.184 - * @param array
   2.185 - * @param index
   2.186 - * @param ... 
   2.187 - * @return 
   2.188 - * @see ucx_array_set()
   2.189 - */
   2.190 -int ucx_array_setv(UcxArray *array, size_t index, ...);
   2.191 -
   2.192 -/**
   2.193   * Concatenates two arrays.
   2.194   * 
   2.195   * The contents of the second array are appended to the first array in one
   2.196 @@ -507,6 +438,18 @@
   2.197   */
   2.198  int ucx_array_reserve(UcxArray* array, size_t capacity);
   2.199  
   2.200 +/**
   2.201 + * Resizes the capacity, if the specified number of elements would not fit.
   2.202 + * 
   2.203 + * A call to ucx_array_grow(array, count) is effectively the same as
   2.204 + * ucx_array_reserve(array, array->size+count).
   2.205 + * 
   2.206 + * @param array a pointer to the array
   2.207 + * @param count the number of elements that should additionally fit
   2.208 + * into the array
   2.209 + * @return zero on success, non-zero if reallocation failed
   2.210 + */
   2.211 +int ucx_array_grow(UcxArray* array, size_t count);
   2.212  
   2.213  
   2.214  #ifdef	__cplusplus
     3.1 --- a/test/array_tests.c	Wed Nov 06 21:01:25 2019 +0100
     3.2 +++ b/test/array_tests.c	Thu Nov 07 10:10:36 2019 +0100
     3.3 @@ -212,124 +212,6 @@
     3.4      ucx_array_free(array);
     3.5  }
     3.6  
     3.7 -UCX_TEST(test_ucx_array_append) {
     3.8 -    UcxArray *array = ucx_array_new(16, sizeof(int));
     3.9 -    int *elements;
    3.10 -    
    3.11 -    ucx_array_append(array, 42);
    3.12 -    UCX_TEST_BEGIN
    3.13 -    
    3.14 -    elements = array->data;
    3.15 -    UCX_TEST_ASSERT(elements[0] == 42, "failed");
    3.16 -    
    3.17 -    ucx_array_append(array, 13);
    3.18 -    ucx_array_append(array, 37);
    3.19 -    
    3.20 -    elements = array->data;
    3.21 -    UCX_TEST_ASSERT(array->size == 3, "incorrect size after append");
    3.22 -    UCX_TEST_ASSERT(elements[1] == 13, "failed");
    3.23 -    UCX_TEST_ASSERT(elements[2] == 37, "failed");
    3.24 -    UCX_TEST_ASSERT(elements[0] == 42,
    3.25 -            "append corrupted previously inserted data");
    3.26 -    
    3.27 -    UCX_TEST_END
    3.28 -    
    3.29 -    ucx_array_destroy(array);
    3.30 -}
    3.31 -
    3.32 -UCX_TEST(test_ucx_array_append_struct) {
    3.33 -    struct teststruct {
    3.34 -        unsigned long long x;
    3.35 -        unsigned long long y;
    3.36 -        unsigned long long z;
    3.37 -    };
    3.38 -    
    3.39 -    UcxArray *array = ucx_array_new(16, sizeof(struct teststruct));
    3.40 -    struct teststruct *elements;
    3.41 -    
    3.42 -    struct teststruct data;
    3.43 -    data.x = 13; data.y = 37; data.z = 47;
    3.44 -    
    3.45 -    ucx_array_append(array, data);
    3.46 -    UCX_TEST_BEGIN
    3.47 -    
    3.48 -    elements = array->data;
    3.49 -    UCX_TEST_ASSERT(elements[0].x == 13, "failed");
    3.50 -    UCX_TEST_ASSERT(elements[0].y == 37, "failed");
    3.51 -    UCX_TEST_ASSERT(elements[0].z == 47, "failed");
    3.52 -    
    3.53 -    data.x = 0; data.y = 8; data.z = 15;
    3.54 -    ucx_array_append(array, data);
    3.55 -    
    3.56 -    elements = array->data;
    3.57 -    UCX_TEST_ASSERT(array->size == 2, "incorrect size after append");
    3.58 -    UCX_TEST_ASSERT(elements[1].x == 0, "failed");
    3.59 -    UCX_TEST_ASSERT(elements[1].y == 8, "failed");
    3.60 -    UCX_TEST_ASSERT(elements[1].z == 15, "failed");
    3.61 -    
    3.62 -    UCX_TEST_ASSERT(elements[0].x == 13,
    3.63 -            "append corrupted previously inserted data");
    3.64 -    UCX_TEST_ASSERT(elements[0].y == 37,
    3.65 -            "append corrupted previously inserted data");
    3.66 -    UCX_TEST_ASSERT(elements[0].z == 47,
    3.67 -            "append corrupted previously inserted data");
    3.68 -    
    3.69 -    UCX_TEST_END
    3.70 -    
    3.71 -    ucx_array_destroy(array);
    3.72 -}
    3.73 -
    3.74 -UCX_TEST(test_ucx_array_prepend) {
    3.75 -    int *elems;
    3.76 -    UcxArray *array = ucx_array_new(16, sizeof(int));
    3.77 -    
    3.78 -    ucx_array_prepend(array, 42);
    3.79 -    UCX_TEST_BEGIN
    3.80 -    
    3.81 -    elems = array->data;
    3.82 -    UCX_TEST_ASSERT(elems[0] == 42, "failed");
    3.83 -    
    3.84 -    ucx_array_prepend(array, 37);
    3.85 -    ucx_array_prepend(array, 13);
    3.86 -    
    3.87 -    elems = array->data;
    3.88 -    UCX_TEST_ASSERT(array->size == 3, "incorrect size after prepend");
    3.89 -    UCX_TEST_ASSERT(elems[0] == 13, "failed");
    3.90 -    UCX_TEST_ASSERT(elems[1] == 37, "failed");
    3.91 -    UCX_TEST_ASSERT(elems[2] == 42,
    3.92 -            "prepend corrupted previously inserted data");
    3.93 -    
    3.94 -    UCX_TEST_END
    3.95 -    
    3.96 -    ucx_array_free(array);
    3.97 -}
    3.98 -
    3.99 -UCX_TEST(test_ucx_array_set) {
   3.100 -    int *elems;
   3.101 -    UcxArray *array = ucx_array_new(16, sizeof(int));
   3.102 -
   3.103 -    UCX_TEST_BEGIN
   3.104 -
   3.105 -    ucx_array_set(array, 7, 42);
   3.106 -    
   3.107 -    elems = array->data;
   3.108 -    UCX_TEST_ASSERT(elems[7] == 42, "failed");
   3.109 -    UCX_TEST_ASSERT(array->size == 8, "array not resized on set");
   3.110 -    UCX_TEST_ASSERT(array->capacity == 16, "capacity changed unnecessarily");
   3.111 -    
   3.112 -    ucx_array_set(array, 27, 13);
   3.113 -    ucx_array_set(array, 28, 37);
   3.114 -    
   3.115 -    elems = array->data;
   3.116 -    UCX_TEST_ASSERT(elems[27] == 13, "failed");
   3.117 -    UCX_TEST_ASSERT(elems[28] == 37, "failed");
   3.118 -    UCX_TEST_ASSERT(array->size == 29, "array not resized on set");
   3.119 -    UCX_TEST_ASSERT(array->capacity == 32, "capacity not grown");
   3.120 -        
   3.121 -    UCX_TEST_END
   3.122 -    
   3.123 -    ucx_array_free(array);
   3.124 -}
   3.125  
   3.126  UCX_TEST(test_ucx_array_equals) {
   3.127      UcxArray *a1 = ucx_array_new(16, sizeof(int32_t));
   3.128 @@ -643,32 +525,6 @@
   3.129      ucx_array_free(array);
   3.130  }
   3.131  
   3.132 -UCX_TEST(test_ucx_array_autogrow) {
   3.133 -    int *elems;
   3.134 -    UcxArray *array = ucx_array_new(4, sizeof(int));
   3.135 -    array->size = 3;
   3.136 -    elems = array->data;
   3.137 -    elems[0] = 47;
   3.138 -    elems[1] = 11;
   3.139 -    int x = 5;
   3.140 -    
   3.141 -    UCX_TEST_BEGIN
   3.142 -
   3.143 -    void* oldptr = array->data;
   3.144 -    
   3.145 -    ucx_array_append(array, 5);
   3.146 -    UCX_TEST_ASSERT(array->capacity == 4 && array->data == oldptr,
   3.147 -            "array should not grow too early");
   3.148 -    ucx_array_append(array, 5);
   3.149 -    elems = array->data;
   3.150 -    UCX_TEST_ASSERT(array->capacity == 8, "array did not grow");
   3.151 -    UCX_TEST_ASSERT(array->size == 5, "incorrect size after grow");
   3.152 -    UCX_TEST_ASSERT(elems[3] == 5 && elems[4] == 5, "corrupt data");
   3.153 -    
   3.154 -    UCX_TEST_END
   3.155 -    ucx_array_free(array);
   3.156 -}
   3.157 -
   3.158  UCX_TEST(test_ucx_array_shrink) {
   3.159      UcxArray *array = ucx_array_new(16, sizeof(int));
   3.160      array->size = 4;
   3.161 @@ -713,19 +569,42 @@
   3.162      ucx_array_free(array);
   3.163  }
   3.164  
   3.165 +UCX_TEST(test_ucx_array_grow) {
   3.166 +    UcxArray *array = ucx_array_new(16, sizeof(int));
   3.167 +    array->size = 12;
   3.168 +    
   3.169 +    UCX_TEST_BEGIN
   3.170 +
   3.171 +    UCX_TEST_ASSERT(!ucx_array_grow(array, 4), "failed");
   3.172 +    UCX_TEST_ASSERT(array->capacity == 16, "shall be noop if contents fit");
   3.173 +    /* subsequent calls shall also be noops */
   3.174 +    UCX_TEST_ASSERT(!ucx_array_grow(array, 4), "failed");
   3.175 +    UCX_TEST_ASSERT(array->capacity == 16, "shall be noop if contents fit");
   3.176 +            
   3.177 +    UCX_TEST_ASSERT(!ucx_array_grow(array, 6), "failed");
   3.178 +    UCX_TEST_ASSERT(array->capacity == 18, "incorrect capacity after grow");    
   3.179 +    
   3.180 +    UCX_TEST_END
   3.181 +    ucx_array_free(array);
   3.182 +}
   3.183 +
   3.184  UCX_TEST(test_ucx_array_util_set) {
   3.185      size_t capacity = 16;
   3.186      int* array = malloc(sizeof(int)*capacity);
   3.187 +    int x;
   3.188  
   3.189      UCX_TEST_BEGIN
   3.190  
   3.191 -    UCX_ARRAY_UTIL_SET(&array, &capacity, 7, 42);
   3.192 +    x = 42;
   3.193 +    ucx_array_util_set(&array, &capacity, sizeof(int), 7, &x);
   3.194      
   3.195      UCX_TEST_ASSERT(array[7] == 42, "failed");
   3.196      UCX_TEST_ASSERT(capacity == 16, "capacity changed unnecessarily");
   3.197      
   3.198 -    UCX_ARRAY_UTIL_SET(&array, &capacity, 37, 13);
   3.199 -    UCX_ARRAY_UTIL_SET(&array, &capacity, 38, 37);
   3.200 +    x = 13;
   3.201 +    ucx_array_util_set(&array, &capacity, sizeof(int), 37, &x);
   3.202 +    x = 37;
   3.203 +    ucx_array_util_set(&array, &capacity, sizeof(int), 38, &x);
   3.204      
   3.205      UCX_TEST_ASSERT(array[37] == 13, "failed");
   3.206      UCX_TEST_ASSERT(array[38] == 37, "failed");
   3.207 @@ -735,3 +614,29 @@
   3.208      
   3.209      free(array);
   3.210  }
   3.211 +
   3.212 +
   3.213 +UCX_TEST(test_ucx_array_util_setptr) {
   3.214 +    size_t capacity = 16;
   3.215 +    double** array = malloc(sizeof(double*)*capacity);
   3.216 +    double x, y, z;
   3.217 +
   3.218 +    UCX_TEST_BEGIN
   3.219 +
   3.220 +    ucx_array_util_setptr(&array, &capacity, 7, &x);
   3.221 +    
   3.222 +    UCX_TEST_ASSERT(array[7] == &x, "failed");
   3.223 +    UCX_TEST_ASSERT(capacity == 16, "capacity changed unnecessarily");
   3.224 +    
   3.225 +    ucx_array_util_setptr(&array, &capacity, 37, &y);
   3.226 +    ucx_array_util_setptr(&array, &capacity, 38, &z);
   3.227 +    
   3.228 +    UCX_TEST_ASSERT(array[37] == &y, "failed");
   3.229 +    UCX_TEST_ASSERT(array[38] == &z, "failed");
   3.230 +    UCX_TEST_ASSERT(capacity == 64, "capacity not grown");
   3.231 +        
   3.232 +    UCX_TEST_END
   3.233 +    
   3.234 +    free(array);
   3.235 +}
   3.236 +
     4.1 --- a/test/array_tests.h	Wed Nov 06 21:01:25 2019 +0100
     4.2 +++ b/test/array_tests.h	Thu Nov 07 10:10:36 2019 +0100
     4.3 @@ -43,11 +43,6 @@
     4.4  UCX_TEST(test_ucx_array_append_from_struct);
     4.5  UCX_TEST(test_ucx_array_prepend_from);
     4.6  UCX_TEST(test_ucx_array_set_from);
     4.7 -UCX_TEST(test_ucx_array_append);
     4.8 -UCX_TEST(test_ucx_array_append_struct);
     4.9 -UCX_TEST(test_ucx_array_prepend);
    4.10 -UCX_TEST(test_ucx_array_set);
    4.11 -UCX_TEST(test_ucx_array_autogrow);
    4.12  UCX_TEST(test_ucx_array_equals);
    4.13  UCX_TEST(test_ucx_array_concat);
    4.14  UCX_TEST(test_ucx_array_find);
    4.15 @@ -58,7 +53,9 @@
    4.16  UCX_TEST(test_ucx_array_shrink);
    4.17  UCX_TEST(test_ucx_array_resize);
    4.18  UCX_TEST(test_ucx_array_reserve);
    4.19 +UCX_TEST(test_ucx_array_grow);
    4.20  UCX_TEST(test_ucx_array_util_set);
    4.21 +UCX_TEST(test_ucx_array_util_setptr);
    4.22  
    4.23  #ifdef	__cplusplus
    4.24  }
     5.1 --- a/test/main.c	Wed Nov 06 21:01:25 2019 +0100
     5.2 +++ b/test/main.c	Thu Nov 07 10:10:36 2019 +0100
     5.3 @@ -151,11 +151,6 @@
     5.4          ucx_test_register(suite, test_ucx_array_append_from_struct);
     5.5          ucx_test_register(suite, test_ucx_array_prepend_from);
     5.6          ucx_test_register(suite, test_ucx_array_set_from);
     5.7 -        ucx_test_register(suite, test_ucx_array_append);
     5.8 -        ucx_test_register(suite, test_ucx_array_append_struct);
     5.9 -        ucx_test_register(suite, test_ucx_array_prepend);
    5.10 -        ucx_test_register(suite, test_ucx_array_set);
    5.11 -        ucx_test_register(suite, test_ucx_array_autogrow);
    5.12          ucx_test_register(suite, test_ucx_array_equals);
    5.13          ucx_test_register(suite, test_ucx_array_concat);
    5.14          ucx_test_register(suite, test_ucx_array_find);
    5.15 @@ -166,7 +161,9 @@
    5.16          ucx_test_register(suite, test_ucx_array_shrink);
    5.17          ucx_test_register(suite, test_ucx_array_resize);
    5.18          ucx_test_register(suite, test_ucx_array_reserve);
    5.19 +        ucx_test_register(suite, test_ucx_array_grow);
    5.20          ucx_test_register(suite, test_ucx_array_util_set);
    5.21 +        ucx_test_register(suite, test_ucx_array_util_setptr);
    5.22          
    5.23          /* UcxList Tests */
    5.24          ucx_test_register(suite, test_ucx_list_append);

mercurial