--- a/src/cx/linked_list.h Sun Dec 28 15:45:39 2025 +0100 +++ b/src/cx/linked_list.h Sun Dec 28 17:31:20 2025 +0100 @@ -39,10 +39,6 @@ #include "common.h" #include "list.h" -#ifdef __cplusplus -extern "C" { -#endif - /** * Metadata for a linked list. */ @@ -94,8 +90,8 @@ * @param elem_size the size of each element in bytes * @return the created list */ -cx_attr_nodiscard cx_attr_malloc cx_attr_dealloc(cxListFree, 1) -CX_EXPORT CxList *cxLinkedListCreate(const CxAllocator *allocator, +CX_EXTERN CX_NODISCARD CX_MALLOC CX_DEALLOC(cxListFree, 1) +CxList *cxLinkedListCreate(const CxAllocator *allocator, size_t elem_size); /** @@ -112,8 +108,8 @@ * @param list the list (must be a linked list) * @param len the length of the extra data */ -cx_attr_nonnull -CX_EXPORT void cx_linked_list_extra_data(cx_linked_list *list, size_t len); +CX_EXTERN CX_NONNULL +void cx_linked_list_extra_data(cx_linked_list *list, size_t len); /** * Finds the node at a certain index. @@ -132,8 +128,8 @@ * @param index the search index * @return the node found at the specified index */ -cx_attr_nonnull cx_attr_nodiscard -CX_EXPORT void *cx_linked_list_at(const void *start,size_t start_index, +CX_EXTERN CX_NONNULL CX_NODISCARD +void *cx_linked_list_at(const void *start,size_t start_index, ptrdiff_t loc_advance, size_t index); /** @@ -148,8 +144,8 @@ * @param cmp_func a compare function to compare @p elem against the node data * @return a pointer to the found node or @c NULL if no matching node was found */ -cx_attr_nonnull_arg(1, 4, 6) -CX_EXPORT void *cx_linked_list_find(const void *start, ptrdiff_t loc_advance, +CX_EXTERN CX_NONNULL_ARG(1, 4, 6) +void *cx_linked_list_find(const void *start, ptrdiff_t loc_advance, ptrdiff_t loc_data, const void *elem, size_t *found_index, cx_compare_func cmp_func); @@ -166,8 +162,8 @@ * @param context additional context for the compare function * @return a pointer to the found node or @c NULL if no matching node was found */ -cx_attr_nonnull_arg(1, 4, 6) -CX_EXPORT void *cx_linked_list_find_c(const void *start, ptrdiff_t loc_advance, +CX_EXTERN CX_NONNULL_ARG(1, 4, 6) +void *cx_linked_list_find_c(const void *start, ptrdiff_t loc_advance, ptrdiff_t loc_data, const void *elem, size_t *found_index, cx_compare_func2 cmp_func, void *context); @@ -182,8 +178,8 @@ * @param loc_prev the location of the @c prev pointer * @return a pointer to the first node */ -cx_attr_nonnull cx_attr_returns_nonnull -CX_EXPORT void *cx_linked_list_first(const void *node, ptrdiff_t loc_prev); +CX_EXTERN CX_NONNULL CX_RETURNS_NONNULL +void *cx_linked_list_first(const void *node, ptrdiff_t loc_prev); /** * Finds the last node in a linked list. @@ -196,8 +192,8 @@ * @param loc_next the location of the @c next pointer * @return a pointer to the last node */ -cx_attr_nonnull cx_attr_returns_nonnull -CX_EXPORT void *cx_linked_list_last(const void *node, ptrdiff_t loc_next); +CX_EXTERN CX_NONNULL CX_RETURNS_NONNULL +void *cx_linked_list_last(const void *node, ptrdiff_t loc_next); /** * Finds the predecessor of a node in case it is not linked. @@ -209,8 +205,8 @@ * @param node the successor of the node to find * @return the node or @c NULL if @p node has no predecessor */ -cx_attr_nonnull -CX_EXPORT void *cx_linked_list_prev(const void *begin, ptrdiff_t loc_next, const void *node); +CX_EXTERN CX_NONNULL +void *cx_linked_list_prev(const void *begin, ptrdiff_t loc_next, const void *node); /** * Adds a new node to a linked list. @@ -224,8 +220,8 @@ * @param loc_next the location of a @c next pointer within your node struct (required) * @param new_node a pointer to the node that shall be appended */ -cx_attr_nonnull_arg(5) -CX_EXPORT void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); +CX_EXTERN CX_NONNULL_ARG(5) +void cx_linked_list_add(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); /** * Prepends a new node to a linked list. @@ -239,8 +235,8 @@ * @param loc_next the location of a @c next pointer within your node struct (required) * @param new_node a pointer to the node that shall be prepended */ -cx_attr_nonnull_arg(5) -CX_EXPORT void cx_linked_list_prepend(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); +CX_EXTERN CX_NONNULL_ARG(5) +void cx_linked_list_prepend(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node); /** * Links two nodes. @@ -250,8 +246,8 @@ * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) * @param loc_next the location of a @c next pointer within your node struct (required) */ -cx_attr_nonnull -CX_EXPORT void cx_linked_list_link(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next); +CX_EXTERN CX_NONNULL +void cx_linked_list_link(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next); /** * Unlinks two nodes. @@ -263,8 +259,8 @@ * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) * @param loc_next the location of a @c next pointer within your node struct (required) */ -cx_attr_nonnull -CX_EXPORT void cx_linked_list_unlink(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next); +CX_EXTERN CX_NONNULL +void cx_linked_list_unlink(void *left, void *right, ptrdiff_t loc_prev, ptrdiff_t loc_next); /** * Inserts a new node after a given node of a linked list. @@ -280,8 +276,8 @@ * @param node the node after which to insert (@c NULL if you want to prepend the node to the list) * @param new_node a pointer to the node that shall be inserted */ -cx_attr_nonnull_arg(6) -CX_EXPORT void cx_linked_list_insert(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(6) +void cx_linked_list_insert(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *new_node); /** @@ -304,8 +300,8 @@ * @param insert_begin a pointer to the first node of the chain that shall be inserted * @param insert_end a pointer to the last node of the chain (or NULL if the last node shall be determined) */ -cx_attr_nonnull_arg(6) -CX_EXPORT void cx_linked_list_insert_chain(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(6) +void cx_linked_list_insert_chain(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, void *insert_begin, void *insert_end); /** @@ -322,8 +318,8 @@ * @param new_node a pointer to the node that shall be inserted * @param cmp_func a compare function that will receive the node pointers */ -cx_attr_nonnull_arg(1, 5, 6) -CX_EXPORT void cx_linked_list_insert_sorted(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 5, 6) +void cx_linked_list_insert_sorted(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func cmp_func); /** @@ -345,8 +341,8 @@ * @param insert_begin a pointer to the first node of the chain that shall be inserted * @param cmp_func a compare function that will receive the node pointers */ -cx_attr_nonnull_arg(1, 5, 6) -CX_EXPORT void cx_linked_list_insert_sorted_chain(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 5, 6) +void cx_linked_list_insert_sorted_chain(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func); /** @@ -365,8 +361,8 @@ * @retval zero when the node was inserted * @retval non-zero when a node with the same value already exists */ -cx_attr_nonnull_arg(1, 5, 6) -CX_EXPORT int cx_linked_list_insert_unique(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 5, 6) +int cx_linked_list_insert_unique(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func cmp_func); /** @@ -387,8 +383,8 @@ * @param cmp_func a compare function that will receive the node pointers * @return a pointer to a new chain with all duplicates that were not inserted (or @c NULL when there were no duplicates) */ -cx_attr_nonnull_arg(1, 5, 6) cx_attr_nodiscard -CX_EXPORT void *cx_linked_list_insert_unique_chain(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 5, 6) CX_NODISCARD +void *cx_linked_list_insert_unique_chain(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func cmp_func); /** @@ -406,8 +402,8 @@ * @param cmp_func a compare function that will receive the node pointers * @param context context for the compare function */ -cx_attr_nonnull_arg(1, 5, 6) -CX_EXPORT void cx_linked_list_insert_sorted_c(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 5, 6) +void cx_linked_list_insert_sorted_c(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func2 cmp_func, void *context); /** @@ -430,8 +426,8 @@ * @param cmp_func a compare function that will receive the node pointers * @param context context for the compare function */ -cx_attr_nonnull_arg(1, 5, 6) -CX_EXPORT void cx_linked_list_insert_sorted_chain_c(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 5, 6) +void cx_linked_list_insert_sorted_chain_c(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func2 cmp_func, void *context); /** @@ -450,8 +446,8 @@ * @retval zero when the node was inserted * @retval non-zero when a node with the same value already exists */ -cx_attr_nonnull_arg(1, 5, 6) -CX_EXPORT int cx_linked_list_insert_unique_c(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 5, 6) +int cx_linked_list_insert_unique_c(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *new_node, cx_compare_func2 cmp_func, void *context); /** @@ -473,8 +469,8 @@ * @param context context for the compare function * @return a pointer to a new chain with all duplicates that were not inserted (or @c NULL when there were no duplicates) */ -cx_attr_nonnull_arg(1, 5, 6) cx_attr_nodiscard -CX_EXPORT void *cx_linked_list_insert_unique_chain_c(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 5, 6) CX_NODISCARD +void *cx_linked_list_insert_unique_chain_c(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *insert_begin, cx_compare_func2 cmp_func, void *context); /** @@ -498,8 +494,8 @@ * @param num the number of nodes to remove * @return the actual number of nodes that were removed (can be less when the list did not have enough nodes) */ -cx_attr_nonnull_arg(5) -CX_EXPORT size_t cx_linked_list_remove_chain(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(5) +size_t cx_linked_list_remove_chain(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node, size_t num); /** @@ -521,8 +517,8 @@ * @param loc_next the location of a @c next pointer within your node struct (required) * @param node the node to remove */ -cx_attr_nonnull_arg(5) -CX_EXPORT void cx_linked_list_remove(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(5) +void cx_linked_list_remove(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, void *node); /** @@ -532,8 +528,8 @@ * @param loc_next the location of the @c next pointer within the node struct * @return the size of the list or zero if @p node is @c NULL */ -cx_attr_nodiscard -CX_EXPORT size_t cx_linked_list_size(const void *node, ptrdiff_t loc_next); +CX_EXTERN CX_NODISCARD +size_t cx_linked_list_size(const void *node, ptrdiff_t loc_next); /** * Sorts a linked list based on a comparison function. @@ -547,8 +543,8 @@ * @param loc_data the location of the @c data pointer within your node struct * @param cmp_func the compare function defining the sort order */ -cx_attr_nonnull_arg(1, 6) -CX_EXPORT void cx_linked_list_sort(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 6) +void cx_linked_list_sort(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, cx_compare_func cmp_func); /** @@ -564,11 +560,10 @@ * @param cmp_func the compare function defining the sort order * @param context additional context for the compare function */ -cx_attr_nonnull_arg(1, 6) -CX_EXPORT void cx_linked_list_sort_c(void **begin, void **end, +CX_EXTERN CX_NONNULL_ARG(1, 6) +void cx_linked_list_sort_c(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next, ptrdiff_t loc_data, cx_compare_func2 cmp_func, void *context); - /** * Compares two lists element wise. * @@ -582,8 +577,8 @@ * @return the first non-zero result of invoking @p cmp_func or: negative if the left list is smaller than the * right list, positive if the left list is larger than the right list, zero if both lists are equal. */ -cx_attr_nonnull_arg(5) -CX_EXPORT int cx_linked_list_compare(const void *begin_left, const void *begin_right, +CX_EXTERN CX_NONNULL_ARG(5) +int cx_linked_list_compare(const void *begin_left, const void *begin_right, ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func cmp_func); /** @@ -599,8 +594,8 @@ * @return the first non-zero result of invoking @p cmp_func or: negative if the left list is smaller than the * right list, positive if the left list is larger than the right list, zero if both lists are equal. */ -cx_attr_nonnull_arg(5) -CX_EXPORT int cx_linked_list_compare_c(const void *begin_left, const void *begin_right, +CX_EXTERN CX_NONNULL_ARG(5) +int cx_linked_list_compare_c(const void *begin_left, const void *begin_right, ptrdiff_t loc_advance, ptrdiff_t loc_data, cx_compare_func2 cmp_func, void *context); /** @@ -611,11 +606,7 @@ * @param loc_prev the location of a @c prev pointer within your node struct (negative if your struct does not have one) * @param loc_next the location of a @c next pointer within your node struct (required) */ -cx_attr_nonnull_arg(1) -CX_EXPORT void cx_linked_list_reverse(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next); - -#ifdef __cplusplus -} // extern "C" -#endif +CX_EXTERN CX_NONNULL_ARG(1) +void cx_linked_list_reverse(void **begin, void **end, ptrdiff_t loc_prev, ptrdiff_t loc_next); #endif // UCX_LINKED_LIST_H