--- a/src/cx/list.h Sun Dec 28 15:45:39 2025 +0100 +++ b/src/cx/list.h Sun Dec 28 17:31:20 2025 +0100 @@ -39,10 +39,6 @@ #include "common.h" #include "collection.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * List class type. */ @@ -206,8 +202,8 @@ * @param n the number of elements to insert * @return the number of elements actually inserted */ -cx_attr_nonnull_arg(1) -CX_EXPORT size_t cx_list_default_insert_array(struct cx_list_s *list, +CX_EXTERN CX_NONNULL_ARG(1) +size_t cx_list_default_insert_array(struct cx_list_s *list, size_t index, const void *data, size_t n); /** @@ -226,8 +222,8 @@ * @param n the number of elements to insert * @return the number of elements actually inserted */ -cx_attr_nonnull -CX_EXPORT size_t cx_list_default_insert_sorted(struct cx_list_s *list, +CX_EXTERN CX_NONNULL +size_t cx_list_default_insert_sorted(struct cx_list_s *list, const void *sorted_data, size_t n); /** @@ -246,8 +242,8 @@ * @param n the number of elements to insert * @return the number of elements from the @p sorted_data that are definitely present in the list after this call */ -cx_attr_nonnull -CX_EXPORT size_t cx_list_default_insert_unique(struct cx_list_s *list, +CX_EXTERN CX_NONNULL +size_t cx_list_default_insert_unique(struct cx_list_s *list, const void *sorted_data, size_t n); /** @@ -261,8 +257,8 @@ * * @param list the list that shall be sorted */ -cx_attr_nonnull -CX_EXPORT void cx_list_default_sort(struct cx_list_s *list); +CX_EXTERN CX_NONNULL +void cx_list_default_sort(struct cx_list_s *list); /** * Default unoptimized swap implementation. @@ -277,8 +273,8 @@ * @retval non-zero when indices are out of bounds or memory * allocation for the temporary buffer fails */ -cx_attr_nonnull -CX_EXPORT int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j); +CX_EXTERN CX_NONNULL +int cx_list_default_swap(struct cx_list_s *list, size_t i, size_t j); /** * Initializes a list struct. @@ -319,8 +315,8 @@ * @param allocator the allocator for the elements * @param elem_size the size of one element */ -cx_attr_nonnull_arg(1, 2, 3) -CX_EXPORT void cx_list_init(struct cx_list_s *list, +CX_EXTERN CX_NONNULL_ARG(1, 2, 3) +void cx_list_init(struct cx_list_s *list, struct cx_list_class_s *cl, const struct cx_allocator_s *allocator, size_t elem_size); @@ -332,8 +328,8 @@ * @param list the list which is comparing the elements * @return the comparison result */ -cx_attr_nonnull -CX_EXPORT int cx_list_compare_wrapper( +CX_EXTERN CX_NONNULL +int cx_list_compare_wrapper( const void *left, const void *right, void *list); /** @@ -342,8 +338,8 @@ * @param list the list * @return the number of currently stored elements */ -cx_attr_nonnull -CX_EXPORT size_t cxListSize(const CxList *list); +CX_EXTERN CX_NONNULL +size_t cxListSize(const CxList *list); /** * Adds an item to the end of the list. @@ -355,8 +351,8 @@ * @see cxListAddArray() * @see cxListEmplace() */ -cx_attr_nonnull -CX_EXPORT int cxListAdd(CxList *list, const void *elem); +CX_EXTERN CX_NONNULL +int cxListAdd(CxList *list, const void *elem); /** * Adds multiple items to the end of the list. @@ -375,8 +371,8 @@ * @return the number of added elements * @see cxListEmplaceArray() */ -cx_attr_nonnull -CX_EXPORT size_t cxListAddArray(CxList *list, const void *array, size_t n); +CX_EXTERN CX_NONNULL +size_t cxListAddArray(CxList *list, const void *array, size_t n); /** * Inserts an item at the specified index. @@ -392,8 +388,8 @@ * @see cxListInsertBefore() * @see cxListEmplaceAt() */ -cx_attr_nonnull -CX_EXPORT int cxListInsert(CxList *list, size_t index, const void *elem); +CX_EXTERN CX_NONNULL +int cxListInsert(CxList *list, size_t index, const void *elem); /** * Allocates memory for an element at the specified index and returns a pointer to that memory. @@ -407,8 +403,8 @@ * @see cxListEmplaceArrayAt() * @see cxListInsert() */ -cx_attr_nonnull -CX_EXPORT void *cxListEmplaceAt(CxList *list, size_t index); +CX_EXTERN CX_NONNULL CX_NODISCARD +void *cxListEmplaceAt(CxList *list, size_t index); /** * Allocates memory for an element at the end of the list and returns a pointer to that memory. @@ -420,8 +416,8 @@ * @see cxListEmplaceAt() * @see cxListAdd() */ -cx_attr_nonnull -CX_EXPORT void *cxListEmplace(CxList *list); +CX_EXTERN CX_NONNULL CX_NODISCARD +void *cxListEmplace(CxList *list); /** * Allocates memory for multiple elements and returns an iterator. @@ -440,8 +436,8 @@ * @see cxListEmplaceAt() * @see cxListInsertArray() */ -cx_attr_nonnull -CX_EXPORT CxIterator cxListEmplaceArrayAt(CxList *list, size_t index, size_t n); +CX_EXTERN CX_NONNULL CX_NODISCARD +CxIterator cxListEmplaceArrayAt(CxList *list, size_t index, size_t n); /** * Allocates memory for multiple elements and returns an iterator. @@ -459,8 +455,8 @@ * @see cxListEmplace() * @see cxListAddArray() */ -cx_attr_nonnull -CX_EXPORT CxIterator cxListEmplaceArray(CxList *list, size_t n); +CX_EXTERN CX_NONNULL CX_NODISCARD +CxIterator cxListEmplaceArray(CxList *list, size_t n); /** * Inserts an item into a sorted list. @@ -472,8 +468,8 @@ * @retval zero success * @retval non-zero memory allocation failure */ -cx_attr_nonnull -CX_EXPORT int cxListInsertSorted(CxList *list, const void *elem); +CX_EXTERN CX_NONNULL +int cxListInsertSorted(CxList *list, const void *elem); /** * Inserts an item into a list if it does not exist. @@ -488,8 +484,8 @@ * @retval zero success (also when the element was already in the list) * @retval non-zero memory allocation failure */ -cx_attr_nonnull -CX_EXPORT int cxListInsertUnique(CxList *list, const void *elem); +CX_EXTERN CX_NONNULL +int cxListInsertUnique(CxList *list, const void *elem); /** * Inserts multiple items to the list at the specified index. @@ -511,8 +507,8 @@ * @return the number of added elements * @see cxListEmplaceArrayAt() */ -cx_attr_nonnull -CX_EXPORT size_t cxListInsertArray(CxList *list, size_t index, const void *array, size_t n); +CX_EXTERN CX_NONNULL +size_t cxListInsertArray(CxList *list, size_t index, const void *array, size_t n); /** * Inserts a sorted array into a sorted list. @@ -533,8 +529,8 @@ * @param n the number of elements to add * @return the number of added elements */ -cx_attr_nonnull -CX_EXPORT size_t cxListInsertSortedArray(CxList *list, const void *array, size_t n); +CX_EXTERN CX_NONNULL +size_t cxListInsertSortedArray(CxList *list, const void *array, size_t n); /** * Inserts an array into a list, skipping duplicates. @@ -568,8 +564,8 @@ * * @return the number of elements from the @p sorted_data that are definitely present in the list after this call */ -cx_attr_nonnull -CX_EXPORT size_t cxListInsertUniqueArray(CxList *list, const void *array, size_t n); +CX_EXTERN CX_NONNULL +size_t cxListInsertUniqueArray(CxList *list, const void *array, size_t n); /** * Inserts an element after the current location of the specified iterator. @@ -587,8 +583,8 @@ * @see cxListInsert() * @see cxListInsertBefore() */ -cx_attr_nonnull -CX_EXPORT int cxListInsertAfter(CxIterator *iter, const void *elem); +CX_EXTERN CX_NONNULL +int cxListInsertAfter(CxIterator *iter, const void *elem); /** * Inserts an element before the current location of the specified iterator. @@ -606,8 +602,8 @@ * @see cxListInsert() * @see cxListInsertAfter() */ -cx_attr_nonnull -CX_EXPORT int cxListInsertBefore(CxIterator *iter, const void *elem); +CX_EXTERN CX_NONNULL +int cxListInsertBefore(CxIterator *iter, const void *elem); /** * Removes the element at the specified index. @@ -620,8 +616,8 @@ * @retval zero success * @retval non-zero index out of bounds */ -cx_attr_nonnull -CX_EXPORT int cxListRemove(CxList *list, size_t index); +CX_EXTERN CX_NONNULL +int cxListRemove(CxList *list, size_t index); /** * Removes and returns the element at the specified index. @@ -636,8 +632,8 @@ * @retval zero success * @retval non-zero index out of bounds */ -cx_attr_nonnull cx_attr_access_w(3) -CX_EXPORT int cxListRemoveAndGet(CxList *list, size_t index, void *targetbuf); +CX_EXTERN CX_NONNULL CX_ACCESS_W(3) +int cxListRemoveAndGet(CxList *list, size_t index, void *targetbuf); /** * Removes and returns the first element of the list. @@ -653,8 +649,8 @@ * @see cxListPopFront() * @see cxListRemoveAndGetLast() */ -cx_attr_nonnull cx_attr_access_w(2) -CX_EXPORT int cxListRemoveAndGetFirst(CxList *list, void *targetbuf); +CX_EXTERN CX_NONNULL CX_ACCESS_W(2) +int cxListRemoveAndGetFirst(CxList *list, void *targetbuf); /** * Removes and returns the first element of the list. @@ -687,8 +683,8 @@ * @retval zero success * @retval non-zero the list is empty */ -cx_attr_nonnull cx_attr_access_w(2) -CX_EXPORT int cxListRemoveAndGetLast(CxList *list, void *targetbuf); +CX_EXTERN CX_NONNULL CX_ACCESS_W(2) +int cxListRemoveAndGetLast(CxList *list, void *targetbuf); /** * Removes and returns the last element of the list. @@ -723,8 +719,8 @@ * @param num the number of elements to remove * @return the actual number of removed elements */ -cx_attr_nonnull -CX_EXPORT size_t cxListRemoveArray(CxList *list, size_t index, size_t num); +CX_EXTERN CX_NONNULL +size_t cxListRemoveArray(CxList *list, size_t index, size_t num); /** * Removes and returns multiple elements starting at the specified index. @@ -739,8 +735,8 @@ * @param targetbuf a buffer where to copy the elements * @return the actual number of removed elements */ -cx_attr_nonnull cx_attr_access_w(4) -CX_EXPORT size_t cxListRemoveArrayAndGet(CxList *list, size_t index, size_t num, void *targetbuf); +CX_EXTERN CX_NONNULL CX_ACCESS_W(4) +size_t cxListRemoveArrayAndGet(CxList *list, size_t index, size_t num, void *targetbuf); /** * Removes all elements from this list. @@ -750,8 +746,8 @@ * * @param list the list */ -cx_attr_nonnull -CX_EXPORT void cxListClear(CxList *list); +CX_EXTERN CX_NONNULL +void cxListClear(CxList *list); /** * Swaps two items in the list. @@ -766,8 +762,8 @@ * @retval non-zero one of the indices is out of bounds, * or the swap needed extra memory, but allocation failed */ -cx_attr_nonnull -CX_EXPORT int cxListSwap(CxList *list, size_t i, size_t j); +CX_EXTERN CX_NONNULL +int cxListSwap(CxList *list, size_t i, size_t j); /** * Returns a pointer to the element at the specified index. @@ -778,8 +774,8 @@ * @param index the index of the element * @return a pointer to the element or @c NULL if the index is out of bounds */ -cx_attr_nonnull -CX_EXPORT void *cxListAt(const CxList *list, size_t index); +CX_EXTERN CX_NONNULL +void *cxListAt(const CxList *list, size_t index); /** * Returns a pointer to the first element. @@ -789,8 +785,8 @@ * @param list the list * @return a pointer to the first element or @c NULL if the list is empty */ -cx_attr_nonnull -CX_EXPORT void *cxListFirst(const CxList *list); +CX_EXTERN CX_NONNULL +void *cxListFirst(const CxList *list); /** * Returns a pointer to the last element. @@ -800,8 +796,8 @@ * @param list the list * @return a pointer to the last element or @c NULL if the list is empty */ -cx_attr_nonnull -CX_EXPORT void *cxListLast(const CxList *list); +CX_EXTERN CX_NONNULL +void *cxListLast(const CxList *list); /** * Sets the element at the specified index in the list. @@ -815,8 +811,8 @@ * @retval zero on success * @retval non-zero when index is out of bounds */ -cx_attr_nonnull -CX_EXPORT int cxListSet(CxList *list, size_t index, const void *elem); +CX_EXTERN CX_NONNULL +int cxListSet(CxList *list, size_t index, const void *elem); /** * Returns an iterator pointing to the item at the specified index. @@ -829,8 +825,8 @@ * @param index the index where the iterator shall point at * @return a new iterator */ -cx_attr_nodiscard -CX_EXPORT CxIterator cxListIteratorAt(const CxList *list, size_t index); +CX_EXTERN CX_NODISCARD +CxIterator cxListIteratorAt(const CxList *list, size_t index); /** * Returns a backwards iterator pointing to the item at the specified index. @@ -843,8 +839,8 @@ * @param index the index where the iterator shall point at * @return a new iterator */ -cx_attr_nodiscard -CX_EXPORT CxIterator cxListBackwardsIteratorAt(const CxList *list, size_t index); +CX_EXTERN CX_NODISCARD +CxIterator cxListBackwardsIteratorAt(const CxList *list, size_t index); /** * Returns an iterator pointing to the first item of the list. @@ -856,8 +852,8 @@ * @param list the list * @return a new iterator */ -cx_attr_nodiscard -CX_EXPORT CxIterator cxListIterator(const CxList *list); +CX_EXTERN CX_NODISCARD +CxIterator cxListIterator(const CxList *list); /** * Returns a backwards iterator pointing to the last item of the list. @@ -869,8 +865,8 @@ * @param list the list * @return a new iterator */ -cx_attr_nodiscard -CX_EXPORT CxIterator cxListBackwardsIterator(const CxList *list); +CX_EXTERN CX_NODISCARD +CxIterator cxListBackwardsIterator(const CxList *list); /** * Returns the index of the first element that equals @p elem. @@ -883,8 +879,8 @@ * @see cxListIndexValid() * @see cxListContains() */ -cx_attr_nonnull cx_attr_nodiscard -CX_EXPORT size_t cxListFind(const CxList *list, const void *elem); +CX_EXTERN CX_NONNULL CX_NODISCARD +size_t cxListFind(const CxList *list, const void *elem); /** * Checks if the list contains the specified element. @@ -897,8 +893,8 @@ * @retval false if the element is not contained * @see cxListFind() */ -cx_attr_nonnull cx_attr_nodiscard -CX_EXPORT bool cxListContains(const CxList* list, const void* elem); +CX_EXTERN CX_NONNULL CX_NODISCARD +bool cxListContains(const CxList* list, const void* elem); /** * Checks if the specified index is within bounds. @@ -908,8 +904,8 @@ * @retval true if the index is within bounds * @retval false if the index is out of bounds */ -cx_attr_nonnull cx_attr_nodiscard -CX_EXPORT bool cxListIndexValid(const CxList *list, size_t index); +CX_EXTERN CX_NONNULL CX_NODISCARD +bool cxListIndexValid(const CxList *list, size_t index); /** * Removes and returns the index of the first element that equals @p elem. @@ -922,8 +918,8 @@ * when the element is not found or could not be removed * @see cxListIndexValid() */ -cx_attr_nonnull -CX_EXPORT size_t cxListFindRemove(CxList *list, const void *elem); +CX_EXTERN CX_NONNULL +size_t cxListFindRemove(CxList *list, const void *elem); /** * Sorts the list. @@ -932,16 +928,16 @@ * * @param list the list */ -cx_attr_nonnull -CX_EXPORT void cxListSort(CxList *list); +CX_EXTERN CX_NONNULL +void cxListSort(CxList *list); /** * Reverses the order of the items. * * @param list the list */ -cx_attr_nonnull -CX_EXPORT void cxListReverse(CxList *list); +CX_EXTERN CX_NONNULL +void cxListReverse(CxList *list); /** * Compares a list to another list of the same type. @@ -957,8 +953,8 @@ * @retval positive the first list is larger * or the first non-equal element in the first list is larger */ -cx_attr_nonnull cx_attr_nodiscard -CX_EXPORT int cxListCompare(const CxList *list, const CxList *other); +CX_EXTERN CX_NONNULL CX_NODISCARD +int cxListCompare(const CxList *list, const CxList *other); /** * Deallocates the memory of the specified list structure. @@ -967,7 +963,8 @@ * * @param list the list that shall be freed */ -CX_EXPORT void cxListFree(CxList *list); +CX_EXTERN +void cxListFree(CxList *list); /** @@ -989,8 +986,8 @@ * @retval non-zero when an allocation error occurred * @see cxListCloneShallow() */ -cx_attr_nonnull_arg(1, 2, 3) -CX_EXPORT int cxListClone(CxList *dst, const CxList *src, +CX_EXTERN CX_NONNULL_ARG(1, 2, 3) +int cxListClone(CxList *dst, const CxList *src, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); /** @@ -1012,8 +1009,8 @@ * @retval non-zero when an allocation error occurred * @see cxListDifferenceShallow() */ -cx_attr_nonnull_arg(1, 2, 3, 4) -CX_EXPORT int cxListDifference(CxList *dst, +CX_EXTERN CX_NONNULL_ARG(1, 2, 3, 4) +int cxListDifference(CxList *dst, const CxList *minuend, const CxList *subtrahend, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); @@ -1036,8 +1033,8 @@ * @retval non-zero when an allocation error occurred * @see cxListIntersectionShallow() */ -cx_attr_nonnull_arg(1, 2, 3, 4) -CX_EXPORT int cxListIntersection(CxList *dst, const CxList *src, const CxList *other, +CX_EXTERN CX_NONNULL_ARG(1, 2, 3, 4) +int cxListIntersection(CxList *dst, const CxList *src, const CxList *other, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); /** @@ -1061,8 +1058,8 @@ * @retval non-zero when an allocation error occurred * @see cxListUnionShallow() */ -cx_attr_nonnull_arg(1, 2, 3, 4) -CX_EXPORT int cxListUnion(CxList *dst, const CxList *src, const CxList *other, +CX_EXTERN CX_NONNULL_ARG(1, 2, 3, 4) +int cxListUnion(CxList *dst, const CxList *src, const CxList *other, cx_clone_func clone_func, const CxAllocator *clone_allocator, void *data); /** @@ -1084,8 +1081,8 @@ * @retval non-zero when an allocation error occurred * @see cxListClone() */ -cx_attr_nonnull -CX_EXPORT int cxListCloneShallow(CxList *dst, const CxList *src); +CX_EXTERN CX_NONNULL +int cxListCloneShallow(CxList *dst, const CxList *src); /** * Clones elements from a list only if they are not present in another list. @@ -1106,8 +1103,8 @@ * @retval non-zero when an allocation error occurred * @see cxListDifference() */ -cx_attr_nonnull -CX_EXPORT int cxListDifferenceShallow(CxList *dst, +CX_EXTERN CX_NONNULL +int cxListDifferenceShallow(CxList *dst, const CxList *minuend, const CxList *subtrahend); /** @@ -1129,8 +1126,8 @@ * @retval non-zero when an allocation error occurred * @see cxListIntersection() */ -cx_attr_nonnull -CX_EXPORT int cxListIntersectionShallow(CxList *dst, const CxList *src, const CxList *other); +CX_EXTERN CX_NONNULL +int cxListIntersectionShallow(CxList *dst, const CxList *src, const CxList *other); /** * Performs a deep clone of one list into another, skipping duplicates. @@ -1153,8 +1150,8 @@ * @retval non-zero when an allocation error occurred * @see cxListUnion() */ -cx_attr_nonnull -CX_EXPORT int cxListUnionShallow(CxList *dst, const CxList *src, const CxList *other); +CX_EXTERN CX_NONNULL +int cxListUnionShallow(CxList *dst, const CxList *src, const CxList *other); /** * Asks the list to reserve enough memory for a given total number of elements. @@ -1173,8 +1170,8 @@ * @retval non-zero when an allocation error occurred * @see cxListShrink() */ -cx_attr_nonnull -CX_EXPORT int cxListReserve(CxList *list, size_t capacity); +CX_EXTERN CX_NONNULL +int cxListReserve(CxList *list, size_t capacity); /** * Advises the list to free any overallocated memory. @@ -1187,11 +1184,7 @@ * @param list the list * @return usually zero */ -cx_attr_nonnull -CX_EXPORT int cxListShrink(CxList *list); - -#ifdef __cplusplus -} // extern "C" -#endif +CX_EXTERN CX_NONNULL +int cxListShrink(CxList *list); #endif // UCX_LIST_H