Thu, 03 Oct 2019 10:55:39 +0200
changes UcxArray from value to pointer semantics
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 Tue Sep 24 20:16:00 2019 +0200 1.2 +++ b/src/array.c Thu Oct 03 10:55:39 2019 +0200 1.3 @@ -113,61 +113,70 @@ 1.4 return 0; 1.5 } 1.6 1.7 -UcxArray ucx_array_new(size_t capacity, size_t elemsize) { 1.8 +UcxArray* ucx_array_new(size_t capacity, size_t elemsize) { 1.9 return ucx_array_new_a(capacity, elemsize, ucx_default_allocator()); 1.10 } 1.11 1.12 -UcxArray ucx_array_new_a(size_t capacity, size_t elemsize, 1.13 +UcxArray* ucx_array_new_a(size_t capacity, size_t elemsize, 1.14 UcxAllocator* allocator) { 1.15 - UcxArray array; 1.16 - 1.17 - array.allocator = allocator; 1.18 - array.elemsize = elemsize; 1.19 - array.size = 0; 1.20 - array.data = alcalloc(allocator, capacity, elemsize); 1.21 - 1.22 - if (array.data) { 1.23 - array.capacity = capacity; 1.24 - } else { 1.25 - array.capacity = 0; 1.26 + UcxArray* array = almalloc(allocator, sizeof(UcxArray)); 1.27 + if(array) { 1.28 + ucx_array_init_a(array, capacity, elemsize, allocator); 1.29 } 1.30 - 1.31 return array; 1.32 } 1.33 1.34 -UcxArray ucx_array_clone(UcxArray array) { 1.35 - UcxArray clone; 1.36 +void ucx_array_init(UcxArray* array, size_t capacity, size_t elemsize) { 1.37 + ucx_array_init_a(array, capacity, elemsize, ucx_default_allocator()); 1.38 +} 1.39 + 1.40 +void ucx_array_init_a(UcxArray* array, size_t capacity, size_t elemsize, 1.41 + UcxAllocator* allocator) { 1.42 1.43 - clone.allocator = array.allocator; 1.44 - clone.elemsize = array.elemsize; 1.45 - clone.size = array.size; 1.46 - clone.data = alcalloc(array.allocator, array.capacity, array.elemsize); 1.47 + array->allocator = allocator; 1.48 + array->elemsize = elemsize; 1.49 + array->size = 0; 1.50 + array->data = alcalloc(allocator, capacity, elemsize); 1.51 1.52 - if (clone.data) { 1.53 - clone.capacity = array.capacity; 1.54 - memcpy(clone.data, array.data, array.size*array.elemsize); 1.55 + if (array->data) { 1.56 + array->capacity = capacity; 1.57 } else { 1.58 - clone.capacity = clone.size = 0; 1.59 + array->capacity = 0; 1.60 + } 1.61 +} 1.62 + 1.63 +int ucx_array_clone(UcxArray* dest, UcxArray const* src) { 1.64 + if (ucx_array_ensurecap(dest, src->capacity)) { 1.65 + return 1; 1.66 } 1.67 1.68 - return clone; 1.69 + dest->elemsize = src->elemsize; 1.70 + dest->size = src->size; 1.71 + 1.72 + if (dest->data) { 1.73 + memcpy(dest->data, src->data, src->size*src->elemsize); 1.74 + } 1.75 + 1.76 + return 0; 1.77 } 1.78 1.79 -int ucx_array_equals(UcxArray array1, UcxArray array2, 1.80 +int ucx_array_equals(UcxArray const *array1, UcxArray const *array2, 1.81 cmp_func cmpfnc, void* data) { 1.82 1.83 - if (array1.size != array2.size || array1.elemsize != array2.elemsize) { 1.84 + if (array1->size != array2->size || array1->elemsize != array2->elemsize) { 1.85 return 0; 1.86 } else { 1.87 - if (array1.size == 0) 1.88 + if (array1->size == 0) 1.89 return 1; 1.90 1.91 + size_t elemsize; 1.92 if (cmpfnc == NULL) { 1.93 cmpfnc = ucx_cmp_mem; 1.94 - data = &array1.elemsize; 1.95 + elemsize = array1->elemsize; 1.96 + data = &elemsize; 1.97 } 1.98 1.99 - for (size_t i = 0 ; i < array1.size ; i++) { 1.100 + for (size_t i = 0 ; i < array1->size ; i++) { 1.101 int r = cmpfnc( 1.102 ucx_array_at(array1, i), 1.103 ucx_array_at(array2, i), 1.104 @@ -180,16 +189,22 @@ 1.105 } 1.106 1.107 void ucx_array_destroy(UcxArray *array) { 1.108 - alfree(array->allocator, array->data); 1.109 + if(array->data) 1.110 + alfree(array->allocator, array->data); 1.111 array->data = NULL; 1.112 array->capacity = array->size = 0; 1.113 } 1.114 1.115 +void ucx_array_free(UcxArray *array) { 1.116 + ucx_array_destroy(array); 1.117 + alfree(array->allocator, array); 1.118 +} 1.119 + 1.120 int ucx_array_append_from(UcxArray *array, void *data, size_t count) { 1.121 if (ucx_array_ensurecap(array, array->size + count)) 1.122 return 1; 1.123 1.124 - void* dest = ucx_array_at(*array, array->size); 1.125 + void* dest = ucx_array_at(array, array->size); 1.126 if (data) { 1.127 memcpy(dest, data, array->elemsize*count); 1.128 } else { 1.129 @@ -205,7 +220,7 @@ 1.130 return 1; 1.131 1.132 if (array->size > 0) { 1.133 - void *dest = ucx_array_at(*array, count); 1.134 + void *dest = ucx_array_at(array, count); 1.135 memmove(dest, array->data, array->elemsize*array->size); 1.136 } 1.137 1.138 @@ -228,7 +243,7 @@ 1.139 array->size = index+count; 1.140 } 1.141 1.142 - void *dest = ucx_array_at(*array, index); 1.143 + void *dest = ucx_array_at(array, index); 1.144 if (data) { 1.145 memcpy(dest, data, array->elemsize*count); 1.146 } else { 1.147 @@ -278,7 +293,7 @@ 1.148 } 1.149 } 1.150 1.151 - void* dest = ucx_array_at(*array1, array1->size); 1.152 + void* dest = ucx_array_at(array1, array1->size); 1.153 memcpy(dest, array2->data, array2->size*array2->elemsize); 1.154 1.155 array1->size += array2->size; 1.156 @@ -286,34 +301,38 @@ 1.157 return 0; 1.158 } 1.159 1.160 -void *ucx_array_at(UcxArray array, size_t index) { 1.161 - char* memory = array.data; 1.162 - char* loc = memory + index*array.elemsize; 1.163 +void *ucx_array_at(UcxArray const *array, size_t index) { 1.164 + char* memory = array->data; 1.165 + char* loc = memory + index*array->elemsize; 1.166 return loc; 1.167 } 1.168 1.169 -size_t ucx_array_find(UcxArray array, void *elem, cmp_func cmpfnc, void *data) { 1.170 +size_t ucx_array_find(UcxArray const *array, void *elem, 1.171 + cmp_func cmpfnc, void *data) { 1.172 1.173 + size_t elemsize; 1.174 if (cmpfnc == NULL) { 1.175 cmpfnc = ucx_cmp_mem; 1.176 - data = &array.elemsize; 1.177 + elemsize = array->elemsize; 1.178 + data = &elemsize; 1.179 } 1.180 1.181 - if (array.size > 0) { 1.182 - for (size_t i = 0 ; i < array.size ; i++) { 1.183 + if (array->size > 0) { 1.184 + for (size_t i = 0 ; i < array->size ; i++) { 1.185 void* ptr = ucx_array_at(array, i); 1.186 if (cmpfnc(ptr, elem, data) == 0) { 1.187 return i; 1.188 } 1.189 } 1.190 - return array.size; 1.191 + return array->size; 1.192 } else { 1.193 return 0; 1.194 } 1.195 } 1.196 1.197 -int ucx_array_contains(UcxArray array, void *elem, cmp_func cmpfnc, void *data) { 1.198 - return ucx_array_find(array, elem, cmpfnc, data) != array.size; 1.199 +int ucx_array_contains(UcxArray const *array, void *elem, 1.200 + cmp_func cmpfnc, void *data) { 1.201 + return ucx_array_find(array, elem, cmpfnc, data) != array->size; 1.202 } 1.203 1.204 static void ucx_mergesort_merge(void *arrdata,size_t elemsize, 1.205 @@ -397,15 +416,16 @@ 1.206 } 1.207 #endif /* USE_UCX_QSORT_R */ 1.208 1.209 -void ucx_array_sort(UcxArray array, cmp_func cmpfnc, void *data) { 1.210 - ucx_array_sort_impl(array.data, array.size, array.elemsize, cmpfnc, data); 1.211 +void ucx_array_sort(UcxArray* array, cmp_func cmpfnc, void *data) { 1.212 + ucx_array_sort_impl(array->data, array->size, array->elemsize, 1.213 + cmpfnc, data); 1.214 } 1.215 1.216 void ucx_array_remove(UcxArray *array, size_t index) { 1.217 array->size--; 1.218 if (index < array->size) { 1.219 - void* dest = ucx_array_at(*array, index); 1.220 - void* src = ucx_array_at(*array, index+1); 1.221 + void* dest = ucx_array_at(array, index); 1.222 + void* src = ucx_array_at(array, index+1); 1.223 memmove(dest, src, (array->size - index)*array->elemsize); 1.224 } 1.225 } 1.226 @@ -413,8 +433,8 @@ 1.227 void ucx_array_remove_fast(UcxArray *array, size_t index) { 1.228 array->size--; 1.229 if (index < array->size) { 1.230 - void* dest = ucx_array_at(*array, index); 1.231 - void* src = ucx_array_at(*array, array->size); 1.232 + void* dest = ucx_array_at(array, index); 1.233 + void* src = ucx_array_at(array, array->size); 1.234 memcpy(dest, src, array->elemsize); 1.235 } 1.236 }
2.1 --- a/src/ucx/array.h Tue Sep 24 20:16:00 2019 +0200 2.2 +++ b/src/ucx/array.h Thu Oct 03 10:55:39 2019 +0200 2.3 @@ -145,9 +145,9 @@ 2.4 * Creates a new UCX array with the given capacity and element size. 2.5 * @param capacity the initial capacity 2.6 * @param elemsize the element size 2.7 - * @return a new UCX array structure 2.8 + * @return a pointer to a new UCX array structure 2.9 */ 2.10 -UcxArray ucx_array_new(size_t capacity, size_t elemsize); 2.11 +UcxArray* ucx_array_new(size_t capacity, size_t elemsize); 2.12 2.13 /** 2.14 * Creates a new UCX array using the specified allocator. 2.15 @@ -155,20 +155,44 @@ 2.16 * @param capacity the initial capacity 2.17 * @param elemsize the element size 2.18 * @param allocator the allocator to use 2.19 - * @return a new UCX array structure 2.20 + * @return a pointer to new UCX array structure 2.21 */ 2.22 -UcxArray ucx_array_new_a(size_t capacity, size_t elemsize, 2.23 +UcxArray* ucx_array_new_a(size_t capacity, size_t elemsize, 2.24 + UcxAllocator* allocator); 2.25 + 2.26 +/** 2.27 + * Initializes a UCX array structure with the given capacity and element size. 2.28 + * The structure must be uninitialized as the data pointer will be overwritten. 2.29 + * 2.30 + * @param array the structure to initialize 2.31 + * @param capacity the initial capacity 2.32 + * @param elemsize the element size 2.33 + */ 2.34 +void ucx_array_init(UcxArray* array, size_t capacity, size_t elemsize); 2.35 + 2.36 +/** 2.37 + * Initializes a UCX array structure using the specified allocator. 2.38 + * The structure must be uninitialized as the data pointer will be overwritten. 2.39 + * 2.40 + * @param capacity the initial capacity 2.41 + * @param elemsize the element size 2.42 + * @param allocator the allocator to use 2.43 + */ 2.44 +void ucx_array_init_a(UcxArray* array, size_t capacity, size_t elemsize, 2.45 UcxAllocator* allocator); 2.46 2.47 /** 2.48 * Creates an shallow copy of an array. 2.49 * 2.50 * This function clones the specified array by using memcpy(). 2.51 + * If the destination capacity is insufficient, an automatic reallocation is 2.52 + * attempted. 2.53 * 2.54 - * @param array the array to copy 2.55 - * @return the copy (may be an empty array on allocation errors) 2.56 + * @param dest the array to copy to 2.57 + * @param src the array to copy from 2.58 + * @return zero on success, non-zero on reallocation failure. 2.59 */ 2.60 -UcxArray ucx_array_clone(UcxArray array); 2.61 +int ucx_array_clone(UcxArray* dest, UcxArray const* src); 2.62 2.63 2.64 /** 2.65 @@ -187,7 +211,7 @@ 2.66 * @param data additional data for the compare function 2.67 * @return 1, if and only if the two arrays equal element-wise, 0 otherwise 2.68 */ 2.69 -int ucx_array_equals(UcxArray array1, UcxArray array2, 2.70 +int ucx_array_equals(UcxArray const *array1, UcxArray const *array2, 2.71 cmp_func cmpfnc, void* data); 2.72 2.73 /** 2.74 @@ -202,6 +226,13 @@ 2.75 void ucx_array_destroy(UcxArray *array); 2.76 2.77 /** 2.78 + * Destroys and frees the array. 2.79 + * 2.80 + * @param array the array to free 2.81 + */ 2.82 +void ucx_array_free(UcxArray *array); 2.83 + 2.84 +/** 2.85 * Inserts elements at the end of the array. 2.86 * 2.87 * This is an O(1) operation. 2.88 @@ -362,7 +393,7 @@ 2.89 * @return a pointer to the element at the specified index or <code>NULL</code>, 2.90 * if the index is greater than the array size 2.91 */ 2.92 -void *ucx_array_at(UcxArray array, size_t index); 2.93 +void *ucx_array_at(UcxArray const* array, size_t index); 2.94 2.95 /** 2.96 * Returns the index of an element containing the specified data. 2.97 @@ -381,7 +412,8 @@ 2.98 * @return the index of the element containing the specified data or the size of 2.99 * the array, if the data is not found in this array 2.100 */ 2.101 -size_t ucx_array_find(UcxArray array, void *elem, cmp_func cmpfnc, void *data); 2.102 +size_t ucx_array_find(UcxArray const *array, void *elem, 2.103 + cmp_func cmpfnc, void *data); 2.104 2.105 /** 2.106 * Checks, if an array contains a specific element. 2.107 @@ -395,7 +427,8 @@ 2.108 * @return 1, if and only if the array contains the specified element data 2.109 * @see ucx_array_find() 2.110 */ 2.111 -int ucx_array_contains(UcxArray array, void *elem, cmp_func cmpfnc, void *data); 2.112 +int ucx_array_contains(UcxArray const *array, void *elem, 2.113 + cmp_func cmpfnc, void *data); 2.114 2.115 /** 2.116 * Sorts a UcxArray with the best available sort algorithm. 2.117 @@ -411,7 +444,7 @@ 2.118 * @param cmpfnc the function that shall be used to compare the element data 2.119 * @param data additional data for the cmp_func() or <code>NULL</code> 2.120 */ 2.121 -void ucx_array_sort(UcxArray array, cmp_func cmpfnc, void *data); 2.122 +void ucx_array_sort(UcxArray* array, cmp_func cmpfnc, void *data); 2.123 2.124 /** 2.125 * Removes an element from the array.
3.1 --- a/test/array_tests.c Tue Sep 24 20:16:00 2019 +0200 3.2 +++ b/test/array_tests.c Thu Oct 03 10:55:39 2019 +0200 3.3 @@ -29,58 +29,59 @@ 3.4 #include "array_tests.h" 3.5 #include <ucx/utils.h> 3.6 3.7 -UCX_TEST(test_ucx_array_free) { 3.8 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.9 +UCX_TEST(test_ucx_array_destroy) { 3.10 + UcxArray array; 3.11 + ucx_array_init(&array, 16, sizeof(int)); 3.12 3.13 UCX_TEST_BEGIN 3.14 ucx_array_destroy(&array); 3.15 - UCX_TEST_ASSERT(array.data == NULL, "data pointer not NULL after free"); 3.16 - UCX_TEST_ASSERT(array.size == 0, "size not zero after free"); 3.17 - UCX_TEST_ASSERT(array.capacity == 0, "capacity not zero after free"); 3.18 + UCX_TEST_ASSERT(array.data == NULL, "data pointer not NULL after destroy"); 3.19 + UCX_TEST_ASSERT(array.size == 0, "size not zero after destroy"); 3.20 + UCX_TEST_ASSERT(array.capacity == 0, "capacity not zero after destroy"); 3.21 UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(), 3.22 - "allocator corrupted during free"); 3.23 + "allocator corrupted during destroy"); 3.24 UCX_TEST_END 3.25 } 3.26 3.27 UCX_TEST(test_ucx_array_new) { 3.28 - UcxArray array = ucx_array_new(16, 47); 3.29 + UcxArray* array = ucx_array_new(16, 47); 3.30 3.31 UCX_TEST_BEGIN 3.32 - UCX_TEST_ASSERT(array.data, "no memory allocated"); 3.33 - UCX_TEST_ASSERT(array.size == 0, "size not initially zero"); 3.34 - UCX_TEST_ASSERT(array.capacity == 16, "capacity not as requested"); 3.35 - UCX_TEST_ASSERT(array.elemsize == 47, "element size not as requested"); 3.36 - UCX_TEST_ASSERT(array.allocator == ucx_default_allocator(), 3.37 + UCX_TEST_ASSERT(array->data, "no memory allocated"); 3.38 + UCX_TEST_ASSERT(array->size == 0, "size not initially zero"); 3.39 + UCX_TEST_ASSERT(array->capacity == 16, "capacity not as requested"); 3.40 + UCX_TEST_ASSERT(array->elemsize == 47, "element size not as requested"); 3.41 + UCX_TEST_ASSERT(array->allocator == ucx_default_allocator(), 3.42 "array not using the default allocator"); 3.43 UCX_TEST_END 3.44 - ucx_array_destroy(&array); 3.45 + ucx_array_free(array); 3.46 } 3.47 3.48 UCX_TEST(test_ucx_array_append_from) { 3.49 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.50 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.51 int *elements; 3.52 3.53 int x = 42; 3.54 - ucx_array_append_from(&array, &x, 1); 3.55 + ucx_array_append_from(array, &x, 1); 3.56 UCX_TEST_BEGIN 3.57 3.58 - elements = array.data; 3.59 + elements = array->data; 3.60 UCX_TEST_ASSERT(elements[0] == 42, "failed"); 3.61 3.62 int y[2] = {13, 37}; 3.63 - ucx_array_append_from(&array, y, 2); 3.64 + ucx_array_append_from(array, y, 2); 3.65 3.66 - elements = array.data; 3.67 - UCX_TEST_ASSERT(array.size == 3, "incorrect size after append"); 3.68 + elements = array->data; 3.69 + UCX_TEST_ASSERT(array->size == 3, "incorrect size after append"); 3.70 UCX_TEST_ASSERT(elements[1] == 13, "failed"); 3.71 UCX_TEST_ASSERT(elements[2] == 37, "failed"); 3.72 UCX_TEST_ASSERT(elements[0] == 42, 3.73 "append corrupted previously inserted data"); 3.74 3.75 - ucx_array_append_from(&array, NULL, 2); 3.76 + ucx_array_append_from(array, NULL, 2); 3.77 3.78 - elements = array.data; 3.79 - UCX_TEST_ASSERT(array.size == 5, "incorrect size after NULL append"); 3.80 + elements = array->data; 3.81 + UCX_TEST_ASSERT(array->size == 5, "incorrect size after NULL append"); 3.82 UCX_TEST_ASSERT(elements[3] == 0, "element is not zeroed"); 3.83 UCX_TEST_ASSERT(elements[4] == 0, "element is not zeroed"); 3.84 UCX_TEST_ASSERT(elements[0] == 42, 3.85 @@ -92,34 +93,34 @@ 3.86 3.87 UCX_TEST_END 3.88 3.89 - ucx_array_destroy(&array); 3.90 + ucx_array_free(array); 3.91 } 3.92 3.93 UCX_TEST(test_ucx_array_prepend_from) { 3.94 int *elems; 3.95 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.96 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.97 3.98 int x = 42; 3.99 - ucx_array_prepend_from(&array, &x, 1); 3.100 + ucx_array_prepend_from(array, &x, 1); 3.101 UCX_TEST_BEGIN 3.102 3.103 - elems = array.data; 3.104 + elems = array->data; 3.105 UCX_TEST_ASSERT(elems[0] == 42, "failed"); 3.106 3.107 int y[2] = {13, 37}; 3.108 - ucx_array_prepend_from(&array, y, 2); 3.109 + ucx_array_prepend_from(array, y, 2); 3.110 3.111 - elems = array.data; 3.112 - UCX_TEST_ASSERT(array.size == 3, "incorrect size after prepend"); 3.113 + elems = array->data; 3.114 + UCX_TEST_ASSERT(array->size == 3, "incorrect size after prepend"); 3.115 UCX_TEST_ASSERT(elems[0] == 13, "failed"); 3.116 UCX_TEST_ASSERT(elems[1] == 37, "failed"); 3.117 UCX_TEST_ASSERT(elems[2] == 42, 3.118 "prepend corrupted previously inserted data"); 3.119 3.120 - ucx_array_prepend_from(&array, NULL, 2); 3.121 + ucx_array_prepend_from(array, NULL, 2); 3.122 3.123 - elems = array.data; 3.124 - UCX_TEST_ASSERT(array.size == 5, "incorrect size after NULL prepend"); 3.125 + elems = array->data; 3.126 + UCX_TEST_ASSERT(array->size == 5, "incorrect size after NULL prepend"); 3.127 UCX_TEST_ASSERT(elems[0] == 0, "element is not zeroed"); 3.128 UCX_TEST_ASSERT(elems[1] == 0, "element is not zeroed"); 3.129 UCX_TEST_ASSERT(elems[2] == 13, 3.130 @@ -131,59 +132,59 @@ 3.131 3.132 UCX_TEST_END 3.133 3.134 - ucx_array_destroy(&array); 3.135 + ucx_array_free(array); 3.136 } 3.137 3.138 UCX_TEST(test_ucx_array_set_from) { 3.139 int *elems; 3.140 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.141 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.142 3.143 int x = 42; 3.144 3.145 UCX_TEST_BEGIN 3.146 3.147 - ucx_array_set_from(&array, 7, &x, 1); 3.148 + ucx_array_set_from(array, 7, &x, 1); 3.149 3.150 - elems = array.data; 3.151 + elems = array->data; 3.152 UCX_TEST_ASSERT(elems[7] == 42, "failed"); 3.153 - UCX_TEST_ASSERT(array.size >= 8, "array not resized on set"); 3.154 - UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily"); 3.155 + UCX_TEST_ASSERT(array->size >= 8, "array not resized on set"); 3.156 + UCX_TEST_ASSERT(array->capacity == 16, "capacity changed unnecessarily"); 3.157 3.158 int y[2] = {13, 37}; 3.159 - ucx_array_set_from(&array, 27, y, 2); 3.160 + ucx_array_set_from(array, 27, y, 2); 3.161 3.162 - elems = array.data; 3.163 + elems = array->data; 3.164 UCX_TEST_ASSERT(elems[27] == 13, "failed"); 3.165 UCX_TEST_ASSERT(elems[28] == 37, "failed"); 3.166 - UCX_TEST_ASSERT(array.size == 29, "array not resized on set"); 3.167 - UCX_TEST_ASSERT(array.capacity == 32, "capacity not grown"); 3.168 + UCX_TEST_ASSERT(array->size == 29, "array not resized on set"); 3.169 + UCX_TEST_ASSERT(array->capacity == 32, "capacity not grown"); 3.170 3.171 - ucx_array_set_from(&array, 7, NULL, 2); 3.172 + ucx_array_set_from(array, 7, NULL, 2); 3.173 3.174 - elems = array.data; 3.175 + elems = array->data; 3.176 UCX_TEST_ASSERT(elems[7] == 0, "not zeroed on NULL set"); 3.177 UCX_TEST_ASSERT(elems[8] == 0, "not zeroed on NULL set"); 3.178 3.179 UCX_TEST_END 3.180 3.181 - ucx_array_destroy(&array); 3.182 + ucx_array_free(array); 3.183 } 3.184 3.185 UCX_TEST(test_ucx_array_append) { 3.186 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.187 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.188 int *elements; 3.189 3.190 - ucx_array_append(&array, 42); 3.191 + ucx_array_append(array, 42); 3.192 UCX_TEST_BEGIN 3.193 3.194 - elements = array.data; 3.195 + elements = array->data; 3.196 UCX_TEST_ASSERT(elements[0] == 42, "failed"); 3.197 3.198 - ucx_array_append(&array, 13); 3.199 - ucx_array_append(&array, 37); 3.200 + ucx_array_append(array, 13); 3.201 + ucx_array_append(array, 37); 3.202 3.203 - elements = array.data; 3.204 - UCX_TEST_ASSERT(array.size == 3, "incorrect size after append"); 3.205 + elements = array->data; 3.206 + UCX_TEST_ASSERT(array->size == 3, "incorrect size after append"); 3.207 UCX_TEST_ASSERT(elements[1] == 13, "failed"); 3.208 UCX_TEST_ASSERT(elements[2] == 37, "failed"); 3.209 UCX_TEST_ASSERT(elements[0] == 42, 3.210 @@ -191,24 +192,24 @@ 3.211 3.212 UCX_TEST_END 3.213 3.214 - ucx_array_destroy(&array); 3.215 + ucx_array_destroy(array); 3.216 } 3.217 3.218 UCX_TEST(test_ucx_array_prepend) { 3.219 int *elems; 3.220 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.221 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.222 3.223 - ucx_array_prepend(&array, 42); 3.224 + ucx_array_prepend(array, 42); 3.225 UCX_TEST_BEGIN 3.226 3.227 - elems = array.data; 3.228 + elems = array->data; 3.229 UCX_TEST_ASSERT(elems[0] == 42, "failed"); 3.230 3.231 - ucx_array_prepend(&array, 37); 3.232 - ucx_array_prepend(&array, 13); 3.233 + ucx_array_prepend(array, 37); 3.234 + ucx_array_prepend(array, 13); 3.235 3.236 - elems = array.data; 3.237 - UCX_TEST_ASSERT(array.size == 3, "incorrect size after prepend"); 3.238 + elems = array->data; 3.239 + UCX_TEST_ASSERT(array->size == 3, "incorrect size after prepend"); 3.240 UCX_TEST_ASSERT(elems[0] == 13, "failed"); 3.241 UCX_TEST_ASSERT(elems[1] == 37, "failed"); 3.242 UCX_TEST_ASSERT(elems[2] == 42, 3.243 @@ -216,68 +217,68 @@ 3.244 3.245 UCX_TEST_END 3.246 3.247 - ucx_array_destroy(&array); 3.248 + ucx_array_free(array); 3.249 } 3.250 3.251 UCX_TEST(test_ucx_array_set) { 3.252 int *elems; 3.253 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.254 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.255 3.256 UCX_TEST_BEGIN 3.257 3.258 - ucx_array_set(&array, 7, 42); 3.259 + ucx_array_set(array, 7, 42); 3.260 3.261 - elems = array.data; 3.262 + elems = array->data; 3.263 UCX_TEST_ASSERT(elems[7] == 42, "failed"); 3.264 - UCX_TEST_ASSERT(array.size == 8, "array not resized on set"); 3.265 - UCX_TEST_ASSERT(array.capacity == 16, "capacity changed unnecessarily"); 3.266 + UCX_TEST_ASSERT(array->size == 8, "array not resized on set"); 3.267 + UCX_TEST_ASSERT(array->capacity == 16, "capacity changed unnecessarily"); 3.268 3.269 - ucx_array_set(&array, 27, 13); 3.270 - ucx_array_set(&array, 28, 37); 3.271 + ucx_array_set(array, 27, 13); 3.272 + ucx_array_set(array, 28, 37); 3.273 3.274 - elems = array.data; 3.275 + elems = array->data; 3.276 UCX_TEST_ASSERT(elems[27] == 13, "failed"); 3.277 UCX_TEST_ASSERT(elems[28] == 37, "failed"); 3.278 - UCX_TEST_ASSERT(array.size == 29, "array not resized on set"); 3.279 - UCX_TEST_ASSERT(array.capacity == 32, "capacity not grown"); 3.280 + UCX_TEST_ASSERT(array->size == 29, "array not resized on set"); 3.281 + UCX_TEST_ASSERT(array->capacity == 32, "capacity not grown"); 3.282 3.283 UCX_TEST_END 3.284 3.285 - ucx_array_destroy(&array); 3.286 + ucx_array_free(array); 3.287 } 3.288 3.289 UCX_TEST(test_ucx_array_equals) { 3.290 - UcxArray a1 = ucx_array_new(16, sizeof(int32_t)); 3.291 - UcxArray a2 = ucx_array_new(16, sizeof(int32_t)); 3.292 - UcxArray a3 = ucx_array_new(16, sizeof(int64_t)); 3.293 - UcxArray a4 = ucx_array_new(16, sizeof(int32_t)); 3.294 + UcxArray *a1 = ucx_array_new(16, sizeof(int32_t)); 3.295 + UcxArray *a2 = ucx_array_new(16, sizeof(int32_t)); 3.296 + UcxArray *a3 = ucx_array_new(16, sizeof(int64_t)); 3.297 + UcxArray *a4 = ucx_array_new(16, sizeof(int32_t)); 3.298 3.299 int32_t *intelems; 3.300 int64_t *longintelems; 3.301 3.302 - a1.size = 5; 3.303 - intelems = a1.data; 3.304 + a1->size = 5; 3.305 + intelems = a1->data; 3.306 intelems[0] = 47; 3.307 intelems[1] = 11; 3.308 intelems[2] = 0; 3.309 intelems[3] = 8; 3.310 intelems[4] = 15; 3.311 - a2.size = 5; 3.312 - intelems = a2.data; 3.313 + a2->size = 5; 3.314 + intelems = a2->data; 3.315 intelems[0] = 47; 3.316 intelems[1] = 11; 3.317 intelems[2] = 0; 3.318 intelems[3] = 8; 3.319 intelems[4] = 15; 3.320 - a3.size = 5; 3.321 - longintelems = a3.data; 3.322 + a3->size = 5; 3.323 + longintelems = a3->data; 3.324 longintelems[0] = 47; 3.325 longintelems[1] = 11; 3.326 longintelems[2] = 0; 3.327 longintelems[3] = 8; 3.328 longintelems[4] = 15; 3.329 - a4.size = 5; 3.330 - intelems = a4.data; 3.331 + a4->size = 5; 3.332 + intelems = a4->data; 3.333 intelems[0] = 47; 3.334 intelems[1] = 11; 3.335 intelems[2] = -6; 3.336 @@ -300,54 +301,54 @@ 3.337 "compare using memcmp() failed"); 3.338 3.339 UCX_TEST_END 3.340 - ucx_array_destroy(&a1); 3.341 - ucx_array_destroy(&a2); 3.342 - ucx_array_destroy(&a3); 3.343 - ucx_array_destroy(&a4); 3.344 + ucx_array_free(a1); 3.345 + ucx_array_free(a2); 3.346 + ucx_array_free(a3); 3.347 + ucx_array_free(a4); 3.348 } 3.349 3.350 UCX_TEST(test_ucx_array_concat) { 3.351 - UcxArray a1 = ucx_array_new(16, sizeof(int)); 3.352 - UcxArray a2 = ucx_array_new(16, sizeof(int)); 3.353 + UcxArray *a1 = ucx_array_new(16, sizeof(int)); 3.354 + UcxArray *a2 = ucx_array_new(16, sizeof(int)); 3.355 int *elems; 3.356 3.357 - a1.size = 2; 3.358 - elems = a1.data; 3.359 + a1->size = 2; 3.360 + elems = a1->data; 3.361 elems[0] = 47; 3.362 elems[1] = 11; 3.363 - a2.size = 3; 3.364 - elems = a2.data; 3.365 + a2->size = 3; 3.366 + elems = a2->data; 3.367 elems[0] = 0; 3.368 elems[1] = 8; 3.369 elems[2] = 15; 3.370 3.371 UCX_TEST_BEGIN 3.372 3.373 - UCX_TEST_ASSERT(!ucx_array_concat(&a1, &a2), "failed"); 3.374 - UCX_TEST_ASSERT(a1.size == 5, "failed"); 3.375 - elems = a1.data; 3.376 + UCX_TEST_ASSERT(!ucx_array_concat(a1, a2), "failed"); 3.377 + UCX_TEST_ASSERT(a1->size == 5, "failed"); 3.378 + elems = a1->data; 3.379 UCX_TEST_ASSERT(elems[0] == 47, "failed"); 3.380 UCX_TEST_ASSERT(elems[1] == 11, "failed"); 3.381 UCX_TEST_ASSERT(elems[2] == 0, "failed"); 3.382 UCX_TEST_ASSERT(elems[3] == 8, "failed"); 3.383 UCX_TEST_ASSERT(elems[4] == 15, "failed"); 3.384 3.385 - a1.elemsize *= 2; 3.386 - UCX_TEST_ASSERT(ucx_array_concat(&a1, &a2), 3.387 + a1->elemsize *= 2; 3.388 + UCX_TEST_ASSERT(ucx_array_concat(a1, a2), 3.389 "arrays of different element size must not be concatenated"); 3.390 - UCX_TEST_ASSERT(a1.size == 5, 3.391 + UCX_TEST_ASSERT(a1->size == 5, 3.392 "arrays of different element size must not be concatenated"); 3.393 3.394 UCX_TEST_END 3.395 - ucx_array_destroy(&a1); 3.396 - ucx_array_destroy(&a2); 3.397 + ucx_array_free(a1); 3.398 + ucx_array_free(a2); 3.399 } 3.400 3.401 UCX_TEST(test_ucx_array_at) { 3.402 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.403 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.404 3.405 int x[3] = {42, 13, 5}; 3.406 - ucx_array_append_from(&array, x, 3); 3.407 + ucx_array_append_from(array, x, 3); 3.408 3.409 UCX_TEST_BEGIN 3.410 3.411 @@ -360,15 +361,15 @@ 3.412 3.413 UCX_TEST_END 3.414 3.415 - ucx_array_destroy(&array); 3.416 + ucx_array_free(array); 3.417 } 3.418 3.419 UCX_TEST(test_ucx_array_find) { 3.420 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.421 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.422 int *elems; 3.423 3.424 - array.size = 5; 3.425 - elems = array.data; 3.426 + array->size = 5; 3.427 + elems = array->data; 3.428 elems[0] = 47; 3.429 elems[1] = 11; 3.430 elems[2] = 0; 3.431 @@ -391,15 +392,15 @@ 3.432 "failed using memcmp()"); 3.433 3.434 UCX_TEST_END 3.435 - ucx_array_destroy(&array); 3.436 + ucx_array_free(array); 3.437 } 3.438 3.439 UCX_TEST(test_ucx_array_contains) { 3.440 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.441 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.442 int *elems; 3.443 3.444 - array.size = 5; 3.445 - elems = array.data; 3.446 + array->size = 5; 3.447 + elems = array->data; 3.448 elems[0] = 47; 3.449 elems[1] = 11; 3.450 elems[2] = 0; 3.451 @@ -422,15 +423,15 @@ 3.452 "false positive using memcmp()"); 3.453 3.454 UCX_TEST_END 3.455 - ucx_array_destroy(&array); 3.456 + ucx_array_free(array); 3.457 } 3.458 3.459 UCX_TEST(test_ucx_array_remove) { 3.460 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.461 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.462 int *elems; 3.463 3.464 - array.size = 5; 3.465 - elems = array.data; 3.466 + array->size = 5; 3.467 + elems = array->data; 3.468 elems[0] = 47; 3.469 elems[1] = 11; 3.470 elems[2] = 0; 3.471 @@ -439,31 +440,33 @@ 3.472 3.473 UCX_TEST_BEGIN 3.474 3.475 - ucx_array_remove(&array, 2); 3.476 - elems = array.data; 3.477 + ucx_array_remove(array, 2); 3.478 + elems = array->data; 3.479 UCX_TEST_ASSERT( 3.480 elems[0] == 47 && 3.481 elems[1] == 11 && 3.482 elems[2] == 8 && 3.483 elems[3] == 15, 3.484 "wrong contents after remove"); 3.485 - UCX_TEST_ASSERT(array.size == 4, "wrong size after remove"); 3.486 + UCX_TEST_ASSERT(array->size == 4, "wrong size after remove"); 3.487 3.488 - ucx_array_remove_fast(&array, 1); 3.489 - elems = array.data; 3.490 + ucx_array_remove_fast(array, 1); 3.491 + elems = array->data; 3.492 UCX_TEST_ASSERT( 3.493 elems[0] == 47 && 3.494 elems[1] == 15 && 3.495 elems[2] == 8, 3.496 "wrong contents after fast remove"); 3.497 - UCX_TEST_ASSERT(array.size == 3, "wrong size after fast remove"); 3.498 + UCX_TEST_ASSERT(array->size == 3, "wrong size after fast remove"); 3.499 3.500 UCX_TEST_END 3.501 - ucx_array_destroy(&array); 3.502 + ucx_array_free(array); 3.503 } 3.504 3.505 UCX_TEST(test_ucx_array_clone) { 3.506 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.507 + UcxArray array; 3.508 + UcxArray copy; 3.509 + ucx_array_init(&array, 16, sizeof(int)); 3.510 int *elems; 3.511 3.512 array.size = 5; 3.513 @@ -474,7 +477,7 @@ 3.514 elems[3] = 8; 3.515 elems[4] = 15; 3.516 3.517 - UcxArray copy = ucx_array_clone(array); 3.518 + ucx_array_clone(©, &array); 3.519 UCX_TEST_BEGIN 3.520 3.521 UCX_TEST_ASSERT(array.data != copy.data, "no true copy"); 3.522 @@ -482,7 +485,8 @@ 3.523 UCX_TEST_ASSERT(array.capacity == copy.capacity, "capacity mismatch"); 3.524 UCX_TEST_ASSERT(array.elemsize == copy.elemsize, "element size mismatch"); 3.525 UCX_TEST_ASSERT(array.allocator == copy.allocator, "allocator mismatch"); 3.526 - UCX_TEST_ASSERT(ucx_array_equals(array, copy, ucx_cmp_int, NULL), "failed"); 3.527 + UCX_TEST_ASSERT(ucx_array_equals(&array, ©, ucx_cmp_int, NULL), 3.528 + "contents do not match after clone"); 3.529 3.530 UCX_TEST_END 3.531 3.532 @@ -497,27 +501,27 @@ 3.533 UCX_TEST(test_ucx_array_sort) { 3.534 int *elems; 3.535 3.536 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.537 - array.size = 5; 3.538 - elems = array.data; 3.539 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.540 + array->size = 5; 3.541 + elems = array->data; 3.542 elems[0] = 47; 3.543 elems[1] = 11; 3.544 elems[2] = 0; 3.545 elems[3] = 8; 3.546 elems[4] = 15; 3.547 3.548 - UcxArray expected = ucx_array_new(16, sizeof(int)); 3.549 - expected.size = 5; 3.550 - elems = expected.data; 3.551 + UcxArray *expected = ucx_array_new(16, sizeof(int)); 3.552 + expected->size = 5; 3.553 + elems = expected->data; 3.554 elems[0] = 0; 3.555 elems[1] = 8; 3.556 elems[2] = 11; 3.557 elems[3] = 15; 3.558 elems[4] = 47; 3.559 3.560 - UcxArray expectedrev = ucx_array_new(16, sizeof(int)); 3.561 - expectedrev.size = 5; 3.562 - elems = expectedrev.data; 3.563 + UcxArray *expectedrev = ucx_array_new(16, sizeof(int)); 3.564 + expectedrev->size = 5; 3.565 + elems = expectedrev->data; 3.566 elems[0] = 47; 3.567 elems[1] = 15; 3.568 elems[2] = 11; 3.569 @@ -526,101 +530,102 @@ 3.570 3.571 3.572 UCX_TEST_BEGIN 3.573 - void* original_ptr = array.data; 3.574 + void* original_ptr = array->data; 3.575 ucx_array_sort(array, ucx_cmp_int, NULL); 3.576 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), "failed"); 3.577 - UCX_TEST_ASSERT(array.size == 5, "size corrupted"); 3.578 - UCX_TEST_ASSERT(array.data == original_ptr, "shall not reallocate"); 3.579 + UCX_TEST_ASSERT(array->size == 5, "size corrupted"); 3.580 + UCX_TEST_ASSERT(array->data == original_ptr, "shall not reallocate"); 3.581 3.582 ucx_array_sort(array, ucx_cmp_int_reverse, NULL); 3.583 UCX_TEST_ASSERT(ucx_array_equals(array, expectedrev, NULL, NULL), "failed"); 3.584 3.585 - ucx_array_reserve(&array, 32); 3.586 - ucx_array_reserve(&expected, 32); 3.587 - array.size = expected.size = 32; 3.588 + ucx_array_reserve(array, 32); 3.589 + ucx_array_reserve(expected, 32); 3.590 + array->size = expected->size = 32; 3.591 for (size_t i = 0 ; i < 32 ; i++) { 3.592 - ((int*)array.data)[i]= ((i%2==0)?-1:1) * ((int) i); 3.593 - ((int*)expected.data)[i] = (-30+2*i) - (i > 15 ? 1 : 0); 3.594 + ((int*)array->data)[i]= ((i%2==0)?-1:1) * ((int) i); 3.595 + ((int*)expected->data)[i] = (-30+2*i) - (i > 15 ? 1 : 0); 3.596 } 3.597 3.598 /* dummy third argument to trigger a possible fallback for qsort_s */ 3.599 - ucx_array_sort(array, ucx_cmp_int, array.data); 3.600 + ucx_array_sort(array, ucx_cmp_int, array->data); 3.601 UCX_TEST_ASSERT(ucx_array_equals(array, expected, NULL, NULL), 3.602 "failed for bigger arrays"); 3.603 UCX_TEST_END 3.604 3.605 - ucx_array_destroy(&expected); 3.606 - ucx_array_destroy(&array); 3.607 + ucx_array_free(expectedrev); 3.608 + ucx_array_free(expected); 3.609 + ucx_array_free(array); 3.610 } 3.611 3.612 UCX_TEST(test_ucx_array_autogrow) { 3.613 int *elems; 3.614 - UcxArray array = ucx_array_new(4, sizeof(int)); 3.615 - array.size = 3; 3.616 - elems = array.data; 3.617 + UcxArray *array = ucx_array_new(4, sizeof(int)); 3.618 + array->size = 3; 3.619 + elems = array->data; 3.620 elems[0] = 47; 3.621 elems[1] = 11; 3.622 int x = 5; 3.623 3.624 UCX_TEST_BEGIN 3.625 3.626 - void* oldptr = array.data; 3.627 + void* oldptr = array->data; 3.628 3.629 - ucx_array_append(&array, 5); 3.630 - UCX_TEST_ASSERT(array.capacity == 4 && array.data == oldptr, 3.631 + ucx_array_append(array, 5); 3.632 + UCX_TEST_ASSERT(array->capacity == 4 && array->data == oldptr, 3.633 "array should not grow too early"); 3.634 - ucx_array_append(&array, 5); 3.635 - elems = array.data; 3.636 - UCX_TEST_ASSERT(array.capacity == 8, "array did not grow"); 3.637 - UCX_TEST_ASSERT(array.size == 5, "incorrect size after grow"); 3.638 + ucx_array_append(array, 5); 3.639 + elems = array->data; 3.640 + UCX_TEST_ASSERT(array->capacity == 8, "array did not grow"); 3.641 + UCX_TEST_ASSERT(array->size == 5, "incorrect size after grow"); 3.642 UCX_TEST_ASSERT(elems[3] == 5 && elems[4] == 5, "corrupt data"); 3.643 3.644 UCX_TEST_END 3.645 - ucx_array_destroy(&array); 3.646 + ucx_array_free(array); 3.647 } 3.648 3.649 UCX_TEST(test_ucx_array_shrink) { 3.650 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.651 - array.size = 4; 3.652 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.653 + array->size = 4; 3.654 3.655 UCX_TEST_BEGIN 3.656 - UCX_TEST_ASSERT(!ucx_array_shrink(&array), "failed"); 3.657 - UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after shrink"); 3.658 + UCX_TEST_ASSERT(!ucx_array_shrink(array), "failed"); 3.659 + UCX_TEST_ASSERT(array->capacity == 4, "incorrect capacity after shrink"); 3.660 UCX_TEST_END 3.661 - ucx_array_destroy(&array); 3.662 + ucx_array_free(array); 3.663 } 3.664 3.665 UCX_TEST(test_ucx_array_resize) { 3.666 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.667 - array.size = 8; 3.668 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.669 + array->size = 8; 3.670 3.671 UCX_TEST_BEGIN 3.672 3.673 - UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed"); 3.674 - UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after resize"); 3.675 - UCX_TEST_ASSERT(array.size == 8, "incorrect size after resize"); 3.676 + UCX_TEST_ASSERT(!ucx_array_resize(array, 32), "failed"); 3.677 + UCX_TEST_ASSERT(array->capacity == 32, "incorrect capacity after resize"); 3.678 + UCX_TEST_ASSERT(array->size == 8, "incorrect size after resize"); 3.679 3.680 - UCX_TEST_ASSERT(!ucx_array_resize(&array, 4), "failed"); 3.681 - UCX_TEST_ASSERT(array.capacity == 4, "incorrect capacity after resize"); 3.682 - UCX_TEST_ASSERT(array.size == 4, "incorrect size after resize"); 3.683 + UCX_TEST_ASSERT(!ucx_array_resize(array, 4), "failed"); 3.684 + UCX_TEST_ASSERT(array->capacity == 4, "incorrect capacity after resize"); 3.685 + UCX_TEST_ASSERT(array->size == 4, "incorrect size after resize"); 3.686 3.687 UCX_TEST_END 3.688 - ucx_array_destroy(&array); 3.689 + ucx_array_free(array); 3.690 } 3.691 3.692 UCX_TEST(test_ucx_array_reserve) { 3.693 - UcxArray array = ucx_array_new(16, sizeof(int)); 3.694 + UcxArray *array = ucx_array_new(16, sizeof(int)); 3.695 3.696 UCX_TEST_BEGIN 3.697 3.698 - UCX_TEST_ASSERT(!ucx_array_reserve(&array, 4), "failed"); 3.699 - UCX_TEST_ASSERT(array.capacity == 16, "reserve shall not shrink"); 3.700 + UCX_TEST_ASSERT(!ucx_array_reserve(array, 4), "failed"); 3.701 + UCX_TEST_ASSERT(array->capacity == 16, "reserve shall not shrink"); 3.702 3.703 - UCX_TEST_ASSERT(!ucx_array_resize(&array, 32), "failed"); 3.704 - UCX_TEST_ASSERT(array.capacity == 32, "incorrect capacity after reserve"); 3.705 + UCX_TEST_ASSERT(!ucx_array_resize(array, 32), "failed"); 3.706 + UCX_TEST_ASSERT(array->capacity == 32, "incorrect capacity after reserve"); 3.707 3.708 UCX_TEST_END 3.709 - ucx_array_destroy(&array); 3.710 + ucx_array_free(array); 3.711 } 3.712 3.713 UCX_TEST(test_ucx_array_util_set) {
4.1 --- a/test/array_tests.h Tue Sep 24 20:16:00 2019 +0200 4.2 +++ b/test/array_tests.h Thu Oct 03 10:55:39 2019 +0200 4.3 @@ -36,7 +36,7 @@ 4.4 extern "C" { 4.5 #endif 4.6 4.7 -UCX_TEST(test_ucx_array_free); 4.8 +UCX_TEST(test_ucx_array_destroy); 4.9 UCX_TEST(test_ucx_array_new); 4.10 UCX_TEST(test_ucx_array_at); 4.11 UCX_TEST(test_ucx_array_append_from);
5.1 --- a/test/main.c Tue Sep 24 20:16:00 2019 +0200 5.2 +++ b/test/main.c Thu Oct 03 10:55:39 2019 +0200 5.3 @@ -143,7 +143,7 @@ 5.4 ucx_test_register(suite, test_ucx_logger_log); 5.5 5.6 /* UcxArray Tests */ 5.7 - ucx_test_register(suite, test_ucx_array_free); 5.8 + ucx_test_register(suite, test_ucx_array_destroy); 5.9 ucx_test_register(suite, test_ucx_array_new); 5.10 ucx_test_register(suite, test_ucx_array_at); 5.11 ucx_test_register(suite, test_ucx_array_append_from);