src/cx/linked_list.h

changeset 985
68754c7de906
parent 926
8fdd8d78c14b
--- a/src/cx/linked_list.h	Thu Nov 07 20:22:56 2024 +0100
+++ b/src/cx/linked_list.h	Thu Nov 07 22:46:58 2024 +0100
@@ -64,6 +64,9 @@
  * @param elem_size the size of each element in bytes
  * @return the created list
  */
+cx_attr_nodiscard
+cx_attr_malloc
+cx_attr_dealloc(cxListDestroy, 1)
 CxList *cxLinkedListCreate(
         const CxAllocator *allocator,
         cx_compare_func comparator,
@@ -104,7 +107,8 @@
  * @param index the search index
  * @return the node found at the specified index
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
+cx_attr_nodiscard
 void *cx_linked_list_at(
         const void *start,
         size_t start_index,
@@ -122,7 +126,7 @@
  * @param elem a pointer to the element to find
  * @return the index of the element or a negative value if it could not be found
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 ssize_t cx_linked_list_find(
         const void *start,
         ptrdiff_t loc_advance,
@@ -143,7 +147,7 @@
  * @param elem a pointer to the element to find
  * @return the index of the element or a negative value if it could not be found
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 ssize_t cx_linked_list_find_node(
         void **result,
         const void *start,
@@ -164,7 +168,8 @@
  * @param loc_prev the location of the \c prev pointer
  * @return a pointer to the first node
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
+cx_attr_returns_nonnull
 void *cx_linked_list_first(
         const void *node,
         ptrdiff_t loc_prev
@@ -181,7 +186,8 @@
  * @param loc_next the location of the \c next pointer
  * @return a pointer to the last node
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
+cx_attr_returns_nonnull
 void *cx_linked_list_last(
         const void *node,
         ptrdiff_t loc_next
@@ -197,7 +203,7 @@
  * @param node the successor of the node to find
  * @return the node or \c NULL if \p node has no predecessor
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 void *cx_linked_list_prev(
         const void *begin,
         ptrdiff_t loc_next,
@@ -216,7 +222,7 @@
  * @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
  */
-__attribute__((__nonnull__(5)))
+cx_attr_nonnull_arg(5)
 void cx_linked_list_add(
         void **begin,
         void **end,
@@ -237,7 +243,7 @@
  * @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
  */
-__attribute__((__nonnull__(5)))
+cx_attr_nonnull_arg(5)
 void cx_linked_list_prepend(
         void **begin,
         void **end,
@@ -254,7 +260,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)
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 void cx_linked_list_link(
         void *left,
         void *right,
@@ -272,7 +278,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)
  */
-__attribute__((__nonnull__))
+cx_attr_nonnull
 void cx_linked_list_unlink(
         void *left,
         void *right,
@@ -294,7 +300,7 @@
  * @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
  */
-__attribute__((__nonnull__(6)))
+cx_attr_nonnull_arg(6)
 void cx_linked_list_insert(
         void **begin,
         void **end,
@@ -324,7 +330,7 @@
  * @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)
  */
-__attribute__((__nonnull__(6)))
+cx_attr_nonnull_arg(6)
 void cx_linked_list_insert_chain(
         void **begin,
         void **end,
@@ -349,7 +355,7 @@
  * @param new_node a pointer to the node that shall be inserted
  * @param cmp_func a compare function that will receive the node pointers
  */
-__attribute__((__nonnull__(1, 5, 6)))
+cx_attr_nonnull_arg(1, 5, 6)
 void cx_linked_list_insert_sorted(
         void **begin,
         void **end,
@@ -378,7 +384,7 @@
  * @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
  */
-__attribute__((__nonnull__(1, 5, 6)))
+cx_attr_nonnull_arg(1, 5, 6)
 void cx_linked_list_insert_sorted_chain(
         void **begin,
         void **end,
@@ -409,7 +415,7 @@
  * @param num the number of nodes to remove
  * @return the actual number of nodes that were removed (may be less when the list did not have enough nodes)
  */
-__attribute__((__nonnull__(5)))
+cx_attr_nonnull_arg(5)
 size_t cx_linked_list_remove_chain(
         void **begin,
         void **end,
@@ -438,7 +444,7 @@
  * @param loc_next the location of a \c next pointer within your node struct (required)
  * @param node the node to remove
  */
-__attribute__((__nonnull__(5)))
+cx_attr_nonnull_arg(5)
 static inline void cx_linked_list_remove(
         void **begin,
         void **end,
@@ -482,7 +488,7 @@
  * @param loc_data the location of the \c data pointer within your node struct
  * @param cmp_func the compare function defining the sort order
  */
-__attribute__((__nonnull__(1, 6)))
+cx_attr_nonnull_arg(1, 6)
 void cx_linked_list_sort(
         void **begin,
         void **end,
@@ -506,7 +512,7 @@
  * @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.
  */
-__attribute__((__nonnull__(5)))
+cx_attr_nonnull_arg(5)
 int cx_linked_list_compare(
         const void *begin_left,
         const void *begin_right,
@@ -523,7 +529,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)
  */
-__attribute__((__nonnull__(1)))
+cx_attr_nonnull_arg(1)
 void cx_linked_list_reverse(
         void **begin,
         void **end,

mercurial