ucx/cx/array_list.h

branch
dav-2
changeset 894
e86049631677
parent 891
4d58cbcc9efa
--- a/ucx/cx/array_list.h	Tue Dec 30 21:39:38 2025 +0100
+++ b/ucx/cx/array_list.h	Wed Dec 31 16:41:16 2025 +0100
@@ -39,10 +39,6 @@
 
 #include "list.h"
 
-#ifdef __cplusplus
-extern "C" {
-#endif
-
 /**
  * The maximum item size in an array list that fits into
  * a stack buffer when swapped.
@@ -88,8 +84,8 @@
  * @retval zero allocation was successful
  * @retval non-zero allocation failed
  */
-cx_attr_nonnull
-CX_EXPORT int cx_array_init_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
+CX_EXTERN CX_NONNULL
+int cx_array_init_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
 
 /**
  * Initializes an array by allocating memory.
@@ -131,8 +127,8 @@
  * @param capacity the capacity of the fixed size array
  * @param size the number of initialized elements in the fixed size array
  */
-cx_attr_nonnull
-CX_EXPORT void cx_array_init_fixed_(CxArray *array, const void *data, size_t capacity, size_t size);
+CX_EXTERN CX_NONNULL
+void cx_array_init_fixed_(CxArray *array, const void *data, size_t capacity, size_t size);
 
 /**
  * Initializes an array with fixed size memory.
@@ -173,8 +169,8 @@
  * @retval zero allocation was successful
  * @retval non-zero allocation failed
  */
-cx_attr_nonnull
-CX_EXPORT int cx_array_reserve_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
+CX_EXTERN CX_NONNULL
+int cx_array_reserve_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
 
 /**
  * Changes the capacity of an array.
@@ -215,8 +211,8 @@
  * @retval zero allocation was successful
  * @retval non-zero allocation failed
  */
-cx_attr_nonnull
-CX_EXPORT int cx_array_copy_to_new_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
+CX_EXTERN CX_NONNULL
+int cx_array_copy_to_new_(const CxAllocator *allocator, CxArray *array, size_t elem_size, size_t capacity);
 
 /**
  * Copies the array to a new memory region.
@@ -269,8 +265,8 @@
  * @retval zero success
  * @retval non-zero a re-allocation was necessary but failed
  */
-cx_attr_nonnull_arg(1, 2)
-CX_EXPORT int cx_array_insert_(const CxAllocator *allocator, CxArray *array,
+CX_EXTERN CX_NONNULL_ARG(1, 2)
+int cx_array_insert_(const CxAllocator *allocator, CxArray *array,
         size_t elem_size, size_t index, const void *other, size_t n);
 
 /**
@@ -404,8 +400,8 @@
  * @retval zero success
  * @retval non-zero a re-allocation was necessary but failed
  */
-cx_attr_nonnull
-CX_EXPORT int cx_array_insert_sorted_(const CxAllocator *allocator, CxArray *array,
+CX_EXTERN CX_NONNULL
+int cx_array_insert_sorted_(const CxAllocator *allocator, CxArray *array,
         size_t elem_size, const void *sorted_data, size_t n,
         cx_compare_func cmp_func, bool allow_duplicates);
 
@@ -561,8 +557,8 @@
  * @retval zero success
  * @retval non-zero a re-allocation was necessary but failed
  */
-cx_attr_nonnull_arg(1, 2, 4, 6)
-CX_EXPORT int cx_array_insert_sorted_c_(const CxAllocator *allocator, CxArray *array,
+CX_EXTERN CX_NONNULL_ARG(1, 2, 4, 6)
+int cx_array_insert_sorted_c_(const CxAllocator *allocator, CxArray *array,
         size_t elem_size, const void *sorted_data, size_t n,
         cx_compare_func2 cmp_func, void *context, bool allow_duplicates);
 
@@ -581,7 +577,7 @@
  * @retval zero success
  * @retval non-zero a re-allocation was necessary but failed
  */
-#define cx_array_insert_sorted_ca(allocator, array, element, cmp_func) \
+#define cx_array_insert_sorted_ca(allocator, array, element, cmp_func, context) \
         cx_array_insert_sorted_c_(allocator, (CxArray*)&(array), sizeof((array).data[0]), (void*)&(element), 1, cmp_func, context, true)
 
 /**
@@ -721,7 +717,8 @@
  * @param fn the compare function
  * @param context the context for the compare function
  */
-CX_EXPORT void cx_array_qsort_c(void *array, size_t nmemb, size_t size,
+CX_EXTERN CX_NONNULL
+void cx_array_qsort_c(void *array, size_t nmemb, size_t size,
         cx_compare_func2 fn, void *context);
 
 /**
@@ -733,7 +730,8 @@
  * @param elem_size the size of one element
  * @param fn the compare function
  */
-CX_EXPORT void cx_array_sort_(CxArray *array, size_t elem_size,
+CX_EXTERN CX_NONNULL
+void cx_array_sort_(CxArray *array, size_t elem_size,
         cx_compare_func fn);
 
 /**
@@ -746,7 +744,8 @@
  * @param fn the compare function
  * @param context the context for the compare function
  */
-CX_EXPORT void cx_array_sort_c_(CxArray *array, size_t elem_size,
+CX_EXTERN CX_NONNULL
+void cx_array_sort_c_(CxArray *array, size_t elem_size,
         cx_compare_func2 fn, void *context);
 
 /**
@@ -754,7 +753,6 @@
  *
  * @param array the name of the array
  * @param fn (@c cx_compare_func) the compare function
- * @param context (@c void*) the context for the compare function
  */
 #define cx_array_sort(array, fn) \
         cx_array_sort_((CxArray*)&(array), sizeof((array).data[0]), fn)
@@ -778,8 +776,8 @@
  * @param elem_size the size of one element
  * @return an iterator over the elements
  */
-cx_attr_nodiscard cx_attr_nonnull
-CX_EXPORT CxIterator cx_array_iterator_(CxArray *array, size_t elem_size);
+CX_EXTERN CX_NODISCARD CX_NONNULL
+CxIterator cx_array_iterator_(CxArray *array, size_t elem_size);
 
 /**
  * Creates an iterator over the elements of an array.
@@ -804,8 +802,8 @@
  * @param array the name of the array
  * @return an iterator over the elements
  */
-cx_attr_nodiscard cx_attr_nonnull
-CX_EXPORT CxIterator cx_array_iterator_ptr_(CxArray *array);
+CX_EXTERN CX_NODISCARD CX_NONNULL
+CxIterator cx_array_iterator_ptr_(CxArray *array);
 
 /**
  * Creates an iterator over the elements of an array containing pointers.
@@ -835,8 +833,8 @@
  * @param n the number of elements to remove
  * @param fast indicates whether tail elements should be copied into the gap
  */
-cx_attr_nonnull
-CX_EXPORT void cx_array_remove_(CxArray *array, size_t elem_size, size_t index, size_t n, bool fast);
+CX_EXTERN CX_NONNULL
+void cx_array_remove_(CxArray *array, size_t elem_size, size_t index, size_t n, bool fast);
 
 /**
  * Removes one element from the array.
@@ -912,8 +910,8 @@
  * @param allocator (@c CxAllocator*) the allocator which was used to allocate the array
  * @param array a pointer to the array structure
  */
-cx_attr_nonnull
-CX_EXPORT void cx_array_free_(const CxAllocator *allocator, CxArray *array);
+CX_EXTERN CX_NONNULL
+void cx_array_free_(const CxAllocator *allocator, CxArray *array);
 
 /**
  * Deallocates an array.
@@ -962,8 +960,8 @@
  * @see cx_array_binary_search_sup()
  * @see cx_array_binary_search()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cx_array_binary_search_inf(const void *arr, size_t size,
+CX_EXTERN CX_NONNULL
+size_t cx_array_binary_search_inf(const void *arr, size_t size,
         size_t elem_size, const void *elem, cx_compare_func cmp_func);
 
 /**
@@ -985,8 +983,8 @@
  * @see cx_array_binary_search_inf()
  * @see cx_array_binary_search_sup()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cx_array_binary_search(const void *arr, size_t size,
+CX_EXTERN CX_NONNULL
+size_t cx_array_binary_search(const void *arr, size_t size,
         size_t elem_size, const void *elem, cx_compare_func cmp_func);
 
 /**
@@ -1014,8 +1012,8 @@
  * @see cx_array_binary_search_inf()
  * @see cx_array_binary_search()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cx_array_binary_search_sup(const void *arr, size_t size,
+CX_EXTERN CX_NONNULL
+size_t cx_array_binary_search_sup(const void *arr, size_t size,
         size_t elem_size, const void *elem, cx_compare_func cmp_func);
 
 
@@ -1045,8 +1043,8 @@
  * @see cx_array_binary_search_sup()
  * @see cx_array_binary_search()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cx_array_binary_search_inf_c(const void *arr, size_t size,
+CX_EXTERN CX_NONNULL
+size_t cx_array_binary_search_inf_c(const void *arr, size_t size,
         size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context);
 
 /**
@@ -1069,8 +1067,8 @@
  * @see cx_array_binary_search_inf()
  * @see cx_array_binary_search_sup()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cx_array_binary_search_c(const void *arr, size_t size,
+CX_EXTERN CX_NONNULL
+size_t cx_array_binary_search_c(const void *arr, size_t size,
         size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context);
 
 /**
@@ -1099,8 +1097,8 @@
  * @see cx_array_binary_search_inf()
  * @see cx_array_binary_search()
  */
-cx_attr_nonnull
-CX_EXPORT size_t cx_array_binary_search_sup_c(const void *arr, size_t size,
+CX_EXTERN CX_NONNULL
+size_t cx_array_binary_search_sup_c(const void *arr, size_t size,
         size_t elem_size, const void *elem, cx_compare_func2 cmp_func, void *context);
 
 /**
@@ -1111,8 +1109,8 @@
  * @param idx1 index of the first element
  * @param idx2 index of the second element
  */
-cx_attr_nonnull
-CX_EXPORT void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2);
+CX_EXTERN CX_NONNULL
+void cx_array_swap(void *arr, size_t elem_size, size_t idx1, size_t idx2);
 
 /**
  * Allocates an array list for storing elements with @p elem_size bytes each.
@@ -1127,14 +1125,8 @@
  * @param initial_capacity the initial number of elements the array can store
  * @return the created list
  */
-cx_attr_nodiscard
-cx_attr_malloc
-cx_attr_dealloc(cxListFree, 1)
-CX_EXPORT CxList *cxArrayListCreate(const CxAllocator *allocator,
+CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxListFree, 1)
+CxList *cxArrayListCreate(const CxAllocator *allocator,
         size_t elem_size, size_t initial_capacity);
 
-#ifdef __cplusplus
-} // extern "C"
-#endif
-
 #endif // UCX_ARRAY_LIST_H

mercurial