src/cx/array_list.h

changeset 986
38fa7e41194c
parent 985
68754c7de906
--- a/src/cx/array_list.h	Thu Nov 07 22:46:58 2024 +0100
+++ b/src/cx/array_list.h	Mon Nov 11 21:42:14 2024 +0100
@@ -153,42 +153,28 @@
 );
 
 /**
- * Return codes for array functions.
- */
-enum cx_array_result {
-    CX_ARRAY_SUCCESS,
-    CX_ARRAY_REALLOC_NOT_SUPPORTED,
-    CX_ARRAY_REALLOC_FAILED,
-};
-
-/**
  * Copies elements from one array to another.
  *
  * The elements are copied to the \p target array at the specified \p index,
  * overwriting possible elements. The \p index does not need to be in range of
  * the current array \p size. If the new index plus the number of elements added
- * would extend the array's size, and \p capacity is not \c NULL, the remaining
- * capacity is used.
+ * would extend the array's size, the remaining \p capacity is used.
  *
- * If the capacity is insufficient to hold the new data, a reallocation
- * attempt is made, unless the \p reallocator is set to \c NULL, in which case
- * this function ultimately returns a failure.
+ * If the \p capacity is also insufficient to hold the new data, a reallocation
+ * attempt is made with the specified \p reallocator.
  *
  * @param target a pointer to the target array
  * @param size a pointer to the size of the target array
- * @param capacity a pointer to the target array's capacity -
- * \c NULL if only the size shall be used to bound the array (reallocations
- * will NOT be supported in that case)
+ * @param capacity a pointer to the capacity of the target array
  * @param index the index where the copied elements shall be placed
  * @param src the source array
  * @param elem_size the size of one element
  * @param elem_count the number of elements to copy
- * @param reallocator the array reallocator to use, or \c NULL
- * if reallocation shall not happen
- * @return zero on success, non-zero error code on failure
+ * @param reallocator the array reallocator to use
+ * @return zero on success, non-zero on failure
  */
-cx_attr_nonnull_arg(1, 2, 5)
-enum cx_array_result cx_array_copy(
+cx_attr_nonnull
+int cx_array_copy(
         void **target,
         size_t *size,
         size_t *capacity,
@@ -200,12 +186,14 @@
 );
 
 /**
- * Convenience macro that uses cx_array_copy() with a default layout and the default reallocator.
+ * Convenience macro that uses cx_array_copy() with a default layout and
+ * the default reallocator.
  *
  * @param array the name of the array (NOT a pointer to the array)
  * @param index the index where the copied elements shall be placed
  * @param src the source array
  * @param count the number of elements to copy
+ * @return zero on success, non-zero on failure
  * @see CX_ARRAY_DECLARE()
  */
 #define cx_array_simple_copy(array, index, src, count) \
@@ -215,21 +203,20 @@
 /**
  * Adds an element to an array with the possibility of allocating more space.
  *
- * The element \p elem is added to the end of the \p target array which containing
- * \p size elements, already. The \p capacity must not be \c NULL and point a
- * variable holding the current maximum number of elements the array can hold.
+ * The element \p elem is added to the end of the \p target array which contains
+ * \p size elements, already. The \p capacity must point to a variable denoting
+ * the current maximum number of elements the array can hold.
  *
- * If the capacity is insufficient to hold the new element, and the optional
- * \p reallocator is not \c NULL, an attempt increase the \p capacity is made
- * and the new capacity is written back.
+ * If the capacity is insufficient to hold the new element, an attempt to
+ * increase the \p capacity is made and the new capacity is written back.
  *
  * @param target a pointer to the target array
  * @param size a pointer to the size of the target array
- * @param capacity a pointer to the target array's capacity - must not be \c NULL
+ * @param capacity a pointer to the capacity of the target array
  * @param elem_size the size of one element
  * @param elem a pointer to the element to add
- * @param reallocator the array reallocator to use, or \c NULL if reallocation shall not happen
- * @return zero on success, non-zero error code on failure
+ * @param reallocator the array reallocator to use
+ * @return zero on success, non-zero on failure
  */
 #define cx_array_add(target, size, capacity, elem_size, elem, reallocator) \
     cx_array_copy((void**)(target), size, capacity, *(size), elem, elem_size, 1, reallocator)
@@ -240,6 +227,7 @@
  *
  * @param array the name of the array (NOT a pointer to the array)
  * @param elem the element to add (NOT a pointer, address is automatically taken)
+ * @return zero on success, non-zero on failure
  * @see CX_ARRAY_DECLARE()
  */
 #define cx_array_simple_add(array, elem) \
@@ -257,16 +245,16 @@
  *
  * @param target a pointer to the target array
  * @param size a pointer to the size of the target array
- * @param capacity a pointer to the target array's capacity
+ * @param capacity a pointer to the capacity of the target array
  * @param cmp_func the compare function for the elements
  * @param src the source array
  * @param elem_size the size of one element
  * @param elem_count the number of elements to insert
  * @param reallocator the array reallocator to use
- * @return zero on success, non-zero error code on failure
+ * @return zero on success, non-zero on failure
  */
 cx_attr_nonnull
-enum cx_array_result cx_array_insert_sorted(
+int cx_array_insert_sorted(
         void **target,
         size_t *size,
         size_t *capacity,
@@ -288,11 +276,11 @@
  *
  * @param target a pointer to the target array
  * @param size a pointer to the size of the target array
- * @param capacity a pointer to the target array's capacity
+ * @param capacity a pointer to the capacity of the target array
  * @param elem_size the size of one element
  * @param elem a pointer to the element to add
  * @param reallocator the array reallocator to use
- * @return zero on success, non-zero error code on failure
+ * @return zero on success, non-zero on failure
  */
 #define cx_array_add_sorted(target, size, capacity, elem_size, elem, cmp_func, reallocator) \
     cx_array_insert_sorted((void**)(target), size, capacity, cmp_func, elem, elem_size, 1, reallocator)
@@ -304,6 +292,7 @@
  * @param array the name of the array (NOT a pointer to the array)
  * @param elem the element to add (NOT a pointer, address is automatically taken)
  * @param cmp_func the compare function for the elements
+ * @return zero on success, non-zero on failure
  * @see CX_ARRAY_DECLARE()
  */
 #define cx_array_simple_add_sorted(array, elem, cmp_func) \
@@ -318,6 +307,7 @@
  * @param src pointer to the source array
  * @param n number of elements in the source array
  * @param cmp_func the compare function for the elements
+ * @return zero on success, non-zero on failure
  * @see CX_ARRAY_DECLARE()
  */
 #define cx_array_simple_insert_sorted(array, src, n, cmp_func) \

mercurial