do not hide pointers behind typedefs

Sun, 30 Jan 2022 14:19:00 +0100

author
Mike Becker <universe@uap-core.de>
date
Sun, 30 Jan 2022 14:19:00 +0100
changeset 500
eb9e7bd40a8e
parent 499
3dc9075df822
child 501
9a08f5e515cc

do not hide pointers behind typedefs

src/allocator.c file | annotate | diff | comparison | revisions
src/buffer.c file | annotate | diff | comparison | revisions
src/cx/allocator.h file | annotate | diff | comparison | revisions
src/cx/buffer.h file | annotate | diff | comparison | revisions
src/cx/iterator.h file | annotate | diff | comparison | revisions
src/cx/linked_list.h file | annotate | diff | comparison | revisions
src/cx/list.h file | annotate | diff | comparison | revisions
src/linked_list.c file | annotate | diff | comparison | revisions
test/test_list.c file | annotate | diff | comparison | revisions
test/util_allocator.c file | annotate | diff | comparison | revisions
test/util_allocator.h file | annotate | diff | comparison | revisions
--- a/src/allocator.c	Sat Jan 29 14:32:04 2022 +0100
+++ b/src/allocator.c	Sun Jan 30 14:19:00 2022 +0100
@@ -61,19 +61,30 @@
         &cx_default_allocator_class,
         NULL
 };
-CxAllocator cxDefaultAllocator = &cx_default_allocator;
+CxAllocator *cxDefaultAllocator = &cx_default_allocator;
 
 /* IMPLEMENTATION OF HIGH LEVEL API */
 
-void *cxMalloc(CxAllocator allocator, size_t n) {
+void *cxMalloc(
+        CxAllocator *allocator,
+        size_t n
+) {
     return allocator->cl->malloc(allocator->data, n);
 }
 
-void *cxRealloc(CxAllocator allocator, void *mem, size_t n) {
+void *cxRealloc(
+        CxAllocator *allocator,
+        void *mem,
+        size_t n
+) {
     return allocator->cl->realloc(allocator->data, mem, n);
 }
 
-int cxReallocate(CxAllocator allocator, void **mem, size_t n) {
+int cxReallocate(
+        CxAllocator *allocator,
+        void **mem,
+        size_t n
+) {
     void *nmem = allocator->cl->realloc(allocator->data, *mem, n);
     if (nmem == NULL) {
         return 1;
@@ -83,10 +94,17 @@
     }
 }
 
-void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n) {
+void *cxCalloc(
+        CxAllocator *allocator,
+        size_t nelem,
+        size_t n
+) {
     return allocator->cl->calloc(allocator->data, nelem, n);
 }
 
-void cxFree(CxAllocator allocator, void *mem) {
+void cxFree(
+        CxAllocator *allocator,
+        void *mem
+) {
     allocator->cl->free(allocator->data, mem);
 }
--- a/src/buffer.c	Sat Jan 29 14:32:04 2022 +0100
+++ b/src/buffer.c	Sun Jan 30 14:19:00 2022 +0100
@@ -32,12 +32,12 @@
 #include <stdlib.h>
 #include <string.h>
 
-CxBuffer cxBufferCreate(
+CxBuffer *cxBufferCreate(
         void *space,
         size_t capacity,
         int flags
 ) {
-    CxBuffer buffer = (CxBuffer) malloc(sizeof(cx_buffer_s));
+    CxBuffer *buffer = (CxBuffer *) malloc(sizeof(cx_buffer_s));
     if (buffer) {
         buffer->flags = flags;
         if (!space) {
@@ -60,15 +60,15 @@
     return buffer;
 }
 
-void cxBufferDestroy(CxBuffer buffer) {
+void cxBufferDestroy(CxBuffer *buffer) {
     if ((buffer->flags & CX_BUFFER_FREE_CONTENTS) == CX_BUFFER_FREE_CONTENTS) {
         free(buffer->bytes);
     }
     free(buffer);
 }
 
-CxBuffer cxBufferExtract(
-        CxBuffer src,
+CxBuffer *cxBufferExtract(
+        CxBuffer *src,
         size_t start,
         size_t length,
         int flags
@@ -78,7 +78,7 @@
         return NULL;
     }
 
-    CxBuffer dst = (CxBuffer) malloc(sizeof(cx_buffer_s));
+    CxBuffer *dst = (CxBuffer *) malloc(sizeof(cx_buffer_s));
     if (dst) {
         dst->bytes = malloc(length);
         if (!dst->bytes) {
@@ -95,7 +95,7 @@
 }
 
 int cxBufferSeek(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         off_t offset,
         int whence
 ) {
@@ -130,12 +130,12 @@
 
 }
 
-int cxBufferEof(CxBuffer buffer) {
+int cxBufferEof(CxBuffer *buffer) {
     return buffer->pos >= buffer->size;
 }
 
 int cxBufferMinimumCapacity(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         size_t additional_bytes
 ) {
     size_t newcap = buffer->capacity + additional_bytes;
@@ -161,7 +161,7 @@
         void const *ptr,
         size_t size,
         size_t nitems,
-        CxBuffer buffer
+        CxBuffer *buffer
 ) {
     size_t len;
     if (cx_szmul(size, nitems, &len)) {
@@ -202,7 +202,7 @@
         void *ptr,
         size_t size,
         size_t nitems,
-        CxBuffer buffer
+        CxBuffer *buffer
 ) {
     size_t len;
     if (cx_szmul(size, nitems, &len)) {
@@ -224,7 +224,7 @@
 }
 
 int cxBufferPut(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         int c
 ) {
     if (buffer->pos >= buffer->capacity) {
@@ -246,7 +246,7 @@
     return c;
 }
 
-int cxBufferGet(CxBuffer buffer) {
+int cxBufferGet(CxBuffer *buffer) {
     if (cxBufferEof(buffer)) {
         return EOF;
     } else {
@@ -257,14 +257,14 @@
 }
 
 size_t cxBufferPutString(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         const char *str
 ) {
     return cxBufferWrite(str, 1, strlen(str), buffer);
 }
 
 int cxBufferShiftLeft(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         size_t shift
 ) {
     if (shift >= buffer->size) {
@@ -283,7 +283,7 @@
 }
 
 int cxBufferShiftRight(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         size_t shift
 ) {
     size_t req_capacity = buffer->size + shift;
@@ -315,7 +315,7 @@
 }
 
 int cxBufferShift(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         off_t shift
 ) {
     if (shift < 0) {
--- a/src/cx/allocator.h	Sat Jan 29 14:32:04 2022 +0100
+++ b/src/cx/allocator.h	Sun Jan 30 14:19:00 2022 +0100
@@ -83,12 +83,12 @@
 /**
  * High-Level type alias for the allocator type.
  */
-typedef struct cx_allocator_s *CxAllocator;
+typedef struct cx_allocator_s CxAllocator;
 
 /**
  * A default allocator using standard library malloc() etc.
  */
-extern CxAllocator cxDefaultAllocator;
+extern CxAllocator *cxDefaultAllocator;
 
 /**
  * Allocate \p n bytes of memory.
@@ -97,7 +97,10 @@
  * @param n the number of bytes
  * @return a pointer to the allocated memory
  */
-void *cxMalloc(CxAllocator allocator, size_t n)
+void *cxMalloc(
+        CxAllocator *allocator,
+        size_t n
+)
 __attribute__((__malloc__))
 __attribute__((__alloc_size__(2)));
 
@@ -113,7 +116,11 @@
  * @param n the new size in bytes
  * @return a pointer to the re-allocated memory
  */
-void *cxRealloc(CxAllocator allocator, void *mem, size_t n)
+void *cxRealloc(
+        CxAllocator *allocator,
+        void *mem,
+        size_t n
+)
 __attribute__((__warn_unused_result__))
 __attribute__((__alloc_size__(3)));
 
@@ -132,7 +139,11 @@
  * @param n the new size in bytes
  * @return zero on success, non-zero on failure
  */
-int cxReallocate(CxAllocator allocator, void **mem, size_t n)
+int cxReallocate(
+        CxAllocator *allocator,
+        void **mem,
+        size_t n
+)
 __attribute__((__nonnull__));
 
 /**
@@ -143,7 +154,11 @@
  * @param n the size of each element in bytes
  * @return a pointer to the allocated memory
  */
-void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n)
+void *cxCalloc(
+        CxAllocator *allocator,
+        size_t nelem,
+        size_t n
+)
 __attribute__((__malloc__))
 __attribute__((__alloc_size__(2, 3)));
 
@@ -155,7 +170,10 @@
  * @param allocator the allocator
  * @param mem a pointer to the block to free
  */
-void cxFree(CxAllocator allocator, void *mem)
+void cxFree(
+        CxAllocator *allocator,
+        void *mem
+)
 __attribute__((__nonnull__));
 
 #ifdef __cplusplus
--- a/src/cx/buffer.h	Sat Jan 29 14:32:04 2022 +0100
+++ b/src/cx/buffer.h	Sun Jan 30 14:19:00 2022 +0100
@@ -100,7 +100,7 @@
 /**
  * UCX buffer.
  */
-typedef cx_buffer_s *CxBuffer;
+typedef cx_buffer_s CxBuffer;
 
 /**
  * Creates a new buffer.
@@ -115,7 +115,7 @@
  * @param flags buffer features (see cx_buffer_s.flags)
  * @return the new buffer
  */
-CxBuffer cxBufferCreate(
+CxBuffer *cxBufferCreate(
         void *space,
         size_t capacity,
         int flags
@@ -129,7 +129,7 @@
  *
  * @param buffer the buffer to destroy
  */
-void cxBufferDestroy(CxBuffer buffer);
+void cxBufferDestroy(CxBuffer *buffer);
 
 /**
  * Creates a new buffer and fills it with content copied from another buffer.
@@ -142,8 +142,8 @@
  * @param flags features for the new buffer (#CX_BUFFER_FREE_CONTENTS will always be enabled)
  * @return a new buffer containing the extraction
  */
-CxBuffer cxBufferExtract(
-        CxBuffer src,
+CxBuffer *cxBufferExtract(
+        CxBuffer *src,
         size_t start,
         size_t length,
         int flags
@@ -193,7 +193,7 @@
  * @return 0 on success, non-zero if a required auto-extension fails
  */
 int cxBufferShift(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         off_t shift
 );
 
@@ -207,7 +207,7 @@
  * @see cxBufferShift()
  */
 int cxBufferShiftRight(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         size_t shift
 );
 
@@ -224,7 +224,7 @@
  * @see cxBufferShift()
  */
 int cxBufferShiftLeft(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         size_t shift
 );
 
@@ -249,7 +249,7 @@
  *
  */
 int cxBufferSeek(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         off_t offset,
         int whence
 );
@@ -271,7 +271,7 @@
  * @return non-zero, if the current buffer position has exceeded the last
  * available byte of the buffer.
  */
-int cxBufferEof(CxBuffer buffer);
+int cxBufferEof(CxBuffer *buffer);
 
 
 /**
@@ -284,7 +284,7 @@
  * @return 0 on success or a non-zero value on failure
  */
 int cxBufferMinimumCapacity(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         size_t capacity
 );
 
@@ -305,7 +305,7 @@
         void const *ptr,
         size_t size,
         size_t nitems,
-        CxBuffer buffer
+        CxBuffer *buffer
 );
 
 /**
@@ -325,7 +325,7 @@
         void *ptr,
         size_t size,
         size_t nitems,
-        CxBuffer buffer
+        CxBuffer *buffer
 );
 
 /**
@@ -344,7 +344,7 @@
  * reached and automatic extension is not enabled or not possible
  */
 int cxBufferPut(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         int c
 );
 
@@ -356,7 +356,7 @@
  * @param buffer the buffer to read from
  * @return the character or \c EOF, if the end of the buffer is reached
  */
-int cxBufferGet(CxBuffer buffer);
+int cxBufferGet(CxBuffer *buffer);
 
 /**
  * Writes a string to a buffer.
@@ -366,7 +366,7 @@
  * @return the number of bytes written
  */
 size_t cxBufferPutString(
-        CxBuffer buffer,
+        CxBuffer *buffer,
         const char *str
 );
 
--- a/src/cx/iterator.h	Sat Jan 29 14:32:04 2022 +0100
+++ b/src/cx/iterator.h	Sun Jan 30 14:19:00 2022 +0100
@@ -40,36 +40,23 @@
 #include "common.h"
 
 /**
- * Iterator value type.
- * An iterator points to a certain element in an (possibly unbounded) chain of elements.
- * Iterators that are based on collections (which have a defined "first" element), are supposed
- * to be "position-aware", which means that they keep track of the current index within the collection.
- *
- * @note Objects that are pointed to by an iterator are mutable through that iterator. However, if the
- * iterator is based on a collection and the underlying collection is mutated (elements added or removed),
- * the iterator becomes invalid (regardless of what cxIteratorValid() returns) and MUST be re-obtained
- * from the collection.
- */
-typedef struct cx_iterator_s CxIterator;
-
-/**
  * Internal iterator struct - use CxIterator.
  */
 struct cx_iterator_s {
     /**
      * True iff the iterator points to valid data.
      */
-    bool (*valid)(CxIterator const *) __attribute__ ((__nonnull__));
+    bool (*valid)(struct cx_iterator_s const *) __attribute__ ((__nonnull__));
 
     /**
      * Returns a pointer to the current element.
      */
-    void *(*current)(CxIterator const *) __attribute__ ((__nonnull__));
+    void *(*current)(struct cx_iterator_s const *) __attribute__ ((__nonnull__));
 
     /**
      * Advances the iterator.
      */
-    void (*next)(CxIterator *) __attribute__ ((__nonnull__));
+    void (*next)(struct cx_iterator_s *) __attribute__ ((__nonnull__));
 
     /**
      * Handle for the current element, if required.
@@ -96,6 +83,19 @@
 };
 
 /**
+ * Iterator value type.
+ * An iterator points to a certain element in an (possibly unbounded) chain of elements.
+ * Iterators that are based on collections (which have a defined "first" element), are supposed
+ * to be "position-aware", which means that they keep track of the current index within the collection.
+ *
+ * @note Objects that are pointed to by an iterator are mutable through that iterator. However, if the
+ * iterator is based on a collection and the underlying collection is mutated (elements added or removed),
+ * the iterator becomes invalid (regardless of what cxIteratorValid() returns) and MUST be re-obtained
+ * from the collection.
+ */
+typedef struct cx_iterator_s CxIterator;
+
+/**
  * Checks if the iterator points to valid data.
  *
  * This is especially false for past-the-end iterators.
--- a/src/cx/linked_list.h	Sat Jan 29 14:32:04 2022 +0100
+++ b/src/cx/linked_list.h	Sun Jan 30 14:19:00 2022 +0100
@@ -55,8 +55,8 @@
  * @param item_size the size of each element in bytes
  * @return the created list
  */
-CxList cxLinkedListCreate(
-        CxAllocator allocator,
+CxList *cxLinkedListCreate(
+        CxAllocator *allocator,
         CxListComparator comparator,
         size_t item_size
 ) __attribute__((__nonnull__));
@@ -70,8 +70,8 @@
  * @param comparator the comparator for the elements
  * @return the created list
  */
-CxList cxPointerLinkedListCreate(
-        CxAllocator allocator,
+CxList *cxPointerLinkedListCreate(
+        CxAllocator *allocator,
         CxListComparator comparator
 ) __attribute__((__nonnull__));
 
@@ -85,8 +85,8 @@
  * @param array the array data
  * @return the created list
  */
-CxList cxLinkedListFromArray(
-        CxAllocator allocator,
+CxList *cxLinkedListFromArray(
+        CxAllocator *allocator,
         CxListComparator comparator,
         size_t item_size,
         size_t num_items,
@@ -100,7 +100,7 @@
  *
  * @param list the list
  */
-void cxLinkedListDestroy(CxList list) __attribute__((__nonnull__));
+void cxLinkedListDestroy(CxList *list) __attribute__((__nonnull__));
 
 /**
  * Finds the node at a certain index.
--- a/src/cx/list.h	Sat Jan 29 14:32:04 2022 +0100
+++ b/src/cx/list.h	Sun Jan 30 14:19:00 2022 +0100
@@ -54,90 +54,9 @@
 );
 
 /**
- * Internal type for the list structure - use CxList instead.
- */
-typedef struct cx_list_s cx_list_s;
-
-/**
- * The class definition for arbitrary lists.
+ * List class type.
  */
-typedef struct {
-    /**
-     * Member function for adding an element.
-     */
-    int (*add)(
-            cx_list_s *list,
-            void const *elem
-    );
-
-    /**
-     * Member function for inserting an element.
-     */
-    int (*insert)(
-            cx_list_s *list,
-            size_t index,
-            void const *elem
-    );
-
-    /**
-     * Member function for inserting an element relative to an iterator position.
-     */
-    int (*insert_iter)(
-            CxIterator *iter,
-            void const *elem,
-            int prepend
-    );
-
-    /**
-     * Member function for removing an element.
-     */
-    int (*remove)(
-            cx_list_s *list,
-            size_t index
-    );
-
-    /**
-     * Member function for element lookup.
-     */
-    void *(*at)(
-            cx_list_s const *list,
-            size_t index
-    );
-
-    /**
-     * Member function for finding an element.
-     */
-    size_t (*find)(
-            cx_list_s const *list,
-            void const *elem
-    );
-
-    /**
-     * Member function for sorting the list in place.
-     */
-    void (*sort)(cx_list_s *list);
-
-    /**
-     * Member function for comparing this list to another list of the same type.
-     */
-    int (*compare)(
-            cx_list_s const *list,
-            cx_list_s const *other
-    );
-
-    /**
-     * Member function for reversing the order of the items.
-     */
-    void (*reverse)(cx_list_s *list);
-
-    /**
-     * Returns an iterator pointing to the specified index.
-     */
-    CxIterator (*iterator)(
-            cx_list_s *list,
-            size_t index
-    );
-} cx_list_class;
+typedef struct cx_list_class_s cx_list_class;
 
 /**
  * Structure for holding the base data of a list.
@@ -150,7 +69,7 @@
     /**
      * The allocator to use.
      */
-    CxAllocator allocator;
+    CxAllocator *allocator;
     /**
      * The comparator function for the elements.
      */
@@ -170,9 +89,90 @@
 };
 
 /**
+ * The class definition for arbitrary lists.
+ */
+struct cx_list_class_s {
+    /**
+     * Member function for adding an element.
+     */
+    int (*add)(
+            struct cx_list_s *list,
+            void const *elem
+    );
+
+    /**
+     * Member function for inserting an element.
+     */
+    int (*insert)(
+            struct cx_list_s *list,
+            size_t index,
+            void const *elem
+    );
+
+    /**
+     * Member function for inserting an element relative to an iterator position.
+     */
+    int (*insert_iter)(
+            struct cx_iterator_s *iter,
+            void const *elem,
+            int prepend
+    );
+
+    /**
+     * Member function for removing an element.
+     */
+    int (*remove)(
+            struct cx_list_s *list,
+            size_t index
+    );
+
+    /**
+     * Member function for element lookup.
+     */
+    void *(*at)(
+            struct cx_list_s const *list,
+            size_t index
+    );
+
+    /**
+     * Member function for finding an element.
+     */
+    size_t (*find)(
+            struct cx_list_s const *list,
+            void const *elem
+    );
+
+    /**
+     * Member function for sorting the list in place.
+     */
+    void (*sort)(struct cx_list_s *list);
+
+    /**
+     * Member function for comparing this list to another list of the same type.
+     */
+    int (*compare)(
+            struct cx_list_s const *list,
+            struct cx_list_s const *other
+    );
+
+    /**
+     * Member function for reversing the order of the items.
+     */
+    void (*reverse)(struct cx_list_s *list);
+
+    /**
+     * Returns an iterator pointing to the specified index.
+     */
+    struct cx_iterator_s (*iterator)(
+            struct cx_list_s *list,
+            size_t index
+    );
+};
+
+/**
  * Common type for all list implementations.
  */
-typedef cx_list_s *CxList;
+typedef struct cx_list_s CxList;
 
 /**
  * Adds an item to the end of the list.
@@ -182,7 +182,7 @@
  * @return zero on success, non-zero on memory allocation failure
  */
 static inline int cxListAdd(
-        CxList list,
+        CxList *list,
         void const *elem
 ) {
     return list->cl->add(list, elem);
@@ -202,7 +202,7 @@
  * @see cxListInsertBefore()
  */
 static inline int cxListInsert(
-        CxList list,
+        CxList *list,
         size_t index,
         void const *elem
 ) {
@@ -228,7 +228,7 @@
         CxIterator *iter,
         void const *elem
 ) {
-    return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0);
+    return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 0);
 }
 
 /**
@@ -250,7 +250,7 @@
         CxIterator *iter,
         void const *elem
 ) {
-    return ((cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1);
+    return ((struct cx_list_s *) iter->src_handle)->cl->insert_iter(iter, elem, 1);
 }
 
 /**
@@ -260,7 +260,7 @@
  * @return zero on success, non-zero if the index is out of bounds
  */
 static inline int cxListRemove(
-        CxList list,
+        CxList *list,
         size_t index
 ) {
     return list->cl->remove(list, index);
@@ -274,7 +274,7 @@
  * @return a pointer to the element or \c NULL if the index is out of bounds
  */
 static inline void *cxListAt(
-        CxList list,
+        CxList *list,
         size_t index
 ) {
     return list->cl->at(list, index);
@@ -292,7 +292,7 @@
  * @return a new iterator
  */
 static inline CxIterator cxListIterator(
-        CxList list,
+        CxList *list,
         size_t index
 ) {
     return list->cl->iterator(list, index);
@@ -308,7 +308,7 @@
  * @param list the list
  * @return a new iterator
  */
-static inline CxIterator cxListBegin(CxList list) {
+static inline CxIterator cxListBegin(CxList *list) {
     return list->cl->iterator(list, 0);
 }
 
@@ -322,7 +322,7 @@
  * @return the index of the element or \c (size+1) if the element is not found
  */
 static inline size_t cxListFind(
-        CxList list,
+        CxList *list,
         void const *elem
 ) {
     return list->cl->find(list, elem);
@@ -335,7 +335,7 @@
  *
  * @param list the list
  */
-static inline void cxListSort(CxList list) {
+static inline void cxListSort(CxList *list) {
     list->cl->sort(list);
 }
 
@@ -344,7 +344,7 @@
  *
  * @param list the list
  */
-static inline void cxListReverse(CxList list) {
+static inline void cxListReverse(CxList *list) {
     list->cl->reverse(list);
 }
 
@@ -358,8 +358,8 @@
  * @return zero, if both lists are equal element wise, negative if the first list is smaller, zero if the first list is larger
  */
 static inline int cxListCompare(
-        CxList list,
-        CxList other
+        CxList *list,
+        CxList *other
 ) {
     return list->cl->compare(list, other);
 }
--- a/src/linked_list.c	Sat Jan 29 14:32:04 2022 +0100
+++ b/src/linked_list.c	Sun Jan 30 14:19:00 2022 +0100
@@ -463,7 +463,7 @@
 #define CX_LL_LOC_DATA offsetof(cx_linked_list_node, payload)
 
 typedef struct {
-    cx_list_s base;
+    struct cx_list_s base;
     cx_linked_list_node *begin;
     cx_linked_list_node *end;
 } cx_linked_list;
@@ -482,7 +482,7 @@
 }
 
 static int cx_ll_insert_at(
-        cx_list_s *list,
+        struct cx_list_s *list,
         cx_linked_list_node *node,
         void const *elem
 ) {
@@ -512,7 +512,7 @@
 }
 
 static int cx_ll_insert(
-        cx_list_s *list,
+        struct cx_list_s *list,
         size_t index,
         void const *elem
 ) {
@@ -527,14 +527,14 @@
 }
 
 static int cx_ll_add(
-        cx_list_s *list,
+        struct cx_list_s *list,
         void const *elem
 ) {
     return cx_ll_insert(list, list->size, elem);
 }
 
 static int cx_pll_insert(
-        cx_list_s *list,
+        struct cx_list_s *list,
         size_t index,
         void const *elem
 ) {
@@ -542,14 +542,14 @@
 }
 
 static int cx_pll_add(
-        cx_list_s *list,
+        struct cx_list_s *list,
         void const *elem
 ) {
     return cx_ll_insert(list, list->size, &elem);
 }
 
 static int cx_ll_remove(
-        cx_list_s *list,
+        struct cx_list_s *list,
         size_t index
 ) {
     cx_linked_list *ll = (cx_linked_list *) list;
@@ -572,7 +572,7 @@
 }
 
 static void *cx_ll_at(
-        cx_list_s const *list,
+        struct cx_list_s const *list,
         size_t index
 ) {
     cx_linked_list *ll = (cx_linked_list *) list;
@@ -581,7 +581,7 @@
 }
 
 static void *cx_pll_at(
-        cx_list_s const *list,
+        struct cx_list_s const *list,
         size_t index
 ) {
     cx_linked_list *ll = (cx_linked_list *) list;
@@ -590,7 +590,7 @@
 }
 
 static size_t cx_ll_find(
-        cx_list_s const *list,
+        struct cx_list_s const *list,
         void const *elem
 ) {
     return cx_linked_list_find(((cx_linked_list *) list)->begin,
@@ -599,7 +599,7 @@
 }
 
 static size_t cx_pll_find(
-        cx_list_s const *list,
+        struct cx_list_s const *list,
         void const *elem
 ) {
     return cx_linked_list_find(((cx_linked_list *) list)->begin,
@@ -607,28 +607,28 @@
                                true, list->cmpfunc, elem);
 }
 
-static void cx_ll_sort(cx_list_s *list) {
+static void cx_ll_sort(struct cx_list_s *list) {
     cx_linked_list *ll = (cx_linked_list *) list;
     cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end,
                         CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
                         false, list->cmpfunc);
 }
 
-static void cx_pll_sort(cx_list_s *list) {
+static void cx_pll_sort(struct cx_list_s *list) {
     cx_linked_list *ll = (cx_linked_list *) list;
     cx_linked_list_sort((void **) &ll->begin, (void **) &ll->end,
                         CX_LL_LOC_PREV, CX_LL_LOC_NEXT, CX_LL_LOC_DATA,
                         true, list->cmpfunc);
 }
 
-static void cx_ll_reverse(cx_list_s *list) {
+static void cx_ll_reverse(struct cx_list_s *list) {
     cx_linked_list *ll = (cx_linked_list *) list;
     cx_linked_list_reverse((void **) &ll->begin, (void **) ll->end, CX_LL_LOC_PREV, CX_LL_LOC_NEXT);
 }
 
 static int cx_ll_compare(
-        cx_list_s const *list,
-        cx_list_s const *other
+        struct cx_list_s const *list,
+        struct cx_list_s const *other
 ) {
     cx_linked_list *left = (cx_linked_list *) list;
     cx_linked_list *right = (cx_linked_list *) other;
@@ -638,8 +638,8 @@
 }
 
 static int cx_pll_compare(
-        cx_list_s const *list,
-        cx_list_s const *other
+        struct cx_list_s const *list,
+        struct cx_list_s const *other
 ) {
     cx_linked_list *left = (cx_linked_list *) list;
     cx_linked_list *right = (cx_linked_list *) other;
@@ -680,7 +680,7 @@
 }
 
 static CxIterator cx_ll_iterator(
-        cx_list_s *list,
+        struct cx_list_s *list,
         size_t index
 ) {
     CxIterator iter;
@@ -695,7 +695,7 @@
 }
 
 static CxIterator cx_pll_iterator(
-        cx_list_s *list,
+        struct cx_list_s *list,
         size_t index
 ) {
     CxIterator iter = cx_ll_iterator(list, index);
@@ -708,7 +708,7 @@
         void const *elem,
         int prepend
 ) {
-    cx_list_s *list = iter->src_handle;
+    struct cx_list_s *list = iter->src_handle;
     cx_linked_list_node *node = iter->elem_handle;
     if (node != NULL) {
         assert(prepend >= 0 && prepend <= 1);
@@ -757,8 +757,8 @@
         cx_pll_iterator,
 };
 
-CxList cxLinkedListCreate(
-        CxAllocator allocator,
+CxList *cxLinkedListCreate(
+        CxAllocator *allocator,
         CxListComparator comparator,
         size_t item_size
 ) {
@@ -776,11 +776,11 @@
     list->begin = NULL;
     list->end = NULL;
 
-    return (CxList) list;
+    return (CxList *) list;
 }
 
-CxList cxPointerLinkedListCreate(
-        CxAllocator allocator,
+CxList *cxPointerLinkedListCreate(
+        CxAllocator *allocator,
         CxListComparator comparator
 ) {
     cx_linked_list *list = cxMalloc(allocator, sizeof(cx_linked_list));
@@ -797,17 +797,17 @@
     list->begin = NULL;
     list->end = NULL;
 
-    return (CxList) list;
+    return (CxList *) list;
 }
 
-CxList cxLinkedListFromArray(
-        CxAllocator allocator,
+CxList *cxLinkedListFromArray(
+        CxAllocator *allocator,
         CxListComparator comparator,
         size_t item_size,
         size_t num_items,
         void const *array
 ) {
-    CxList list = cxLinkedListCreate(allocator, comparator, item_size);
+    CxList *list = cxLinkedListCreate(allocator, comparator, item_size);
     if (list == NULL) return NULL;
     for (size_t i = 0; i < num_items; i++) {
         if (0 != cxListAdd(list, ((const unsigned char *) array) + i * item_size)) {
@@ -818,7 +818,7 @@
     return list;
 }
 
-void cxLinkedListDestroy(CxList list) {
+void cxLinkedListDestroy(CxList *list) {
     cx_linked_list *ll = (cx_linked_list *) list;
 
     cx_linked_list_node *node = ll->begin;
--- a/test/test_list.c	Sat Jan 29 14:32:04 2022 +0100
+++ b/test/test_list.c	Sun Jan 30 14:19:00 2022 +0100
@@ -560,7 +560,7 @@
 void test_hl_linked_list_create(void) {
     cxTestingAllocatorReset();
 
-    CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
+    CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
 
     CU_ASSERT_EQUAL(list->size, 0)
     CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
@@ -575,7 +575,7 @@
 void test_hl_ptr_linked_list_create(void) {
     cxTestingAllocatorReset();
 
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
+    CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
 
     CU_ASSERT_EQUAL(list->size, 0)
     CU_ASSERT_EQUAL(list->capacity, (size_t) -1)
@@ -592,10 +592,10 @@
 
     int data[] = {2, 4, 5, 7, 10, 15};
 
-    CxList expected = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
+    CxList *expected = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
     for (int i = 0; i < 5; i++) cxListAdd(expected, &data[i]);
 
-    CxList list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 5, data);
+    CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 5, data);
 
     CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
 
@@ -608,7 +608,7 @@
     cxTestingAllocatorReset();
 
     int data;
-    CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
+    CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
 
     data = 5;
     CU_ASSERT_EQUAL(cxListAdd(list, &data), 0)
@@ -621,7 +621,7 @@
     CU_ASSERT_TRUE(list->capacity >= list->size)
 
     int exp[] = {5, 47, 13};
-    CxList expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 3, exp);
+    CxList *expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 3, exp);
     CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
 
     cxLinkedListDestroy(list);
@@ -632,7 +632,7 @@
 void test_hl_ptr_linked_list_add(void) {
     cxTestingAllocatorReset();
 
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
+    CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
 
     int a = 5, b = 47, c = 13;
 
@@ -663,7 +663,7 @@
     cxTestingAllocatorReset();
 
     int data;
-    CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
+    CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
 
     data = 5;
     CU_ASSERT_NOT_EQUAL(cxListInsert(list, 1, &data), 0)
@@ -683,7 +683,7 @@
     CU_ASSERT_TRUE(list->capacity >= list->size)
 
     int exp[] = {47, 13, 5, 42};
-    CxList expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 4, exp);
+    CxList *expected = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 4, exp);
     CU_ASSERT_TRUE(0 == cxListCompare(list, expected))
 
     cxLinkedListDestroy(list);
@@ -694,7 +694,7 @@
 void test_hl_ptr_linked_list_insert(void) {
     cxTestingAllocatorReset();
 
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
+    CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
 
     int a = 5, b = 47, c = 13, d = 42;
 
@@ -724,8 +724,8 @@
     cxTestingAllocatorReset();
 
     int data[] = {5, 47, 42, 13};
-    CxList list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
-                                        sizeof(int), 4, data);
+    CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
+                                         sizeof(int), 4, data);
 
     CU_ASSERT_EQUAL(list->size, 4)
     CU_ASSERT_TRUE(list->capacity >= list->size)
@@ -764,7 +764,7 @@
     cxTestingAllocatorReset();
 
     int a = 5, b = 47, c = 42, d = 13;
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
+    CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
 
     cxListAdd(list, &a);
     cxListAdd(list, &b);
@@ -808,8 +808,8 @@
     cxTestingAllocatorReset();
 
     int data[] = {5, 47, 13};
-    CxList list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
-                                        sizeof(int), 3, data);
+    CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
+                                         sizeof(int), 3, data);
 
     CU_ASSERT_EQUAL(*(int *) cxListAt(list, 0), 5)
     CU_ASSERT_EQUAL(*(int *) cxListAt(list, 1), 47)
@@ -823,7 +823,7 @@
 void test_hl_ptr_linked_list_at(void) {
     cxTestingAllocatorReset();
 
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
+    CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
 
     int a = 5, b = 47, c = 13;
     cxListAdd(list, &a);
@@ -843,8 +843,8 @@
     cxTestingAllocatorReset();
 
     int data[] = {5, 47, 13};
-    CxList list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
-                                        sizeof(int), 3, data);
+    CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int,
+                                         sizeof(int), 3, data);
     CU_ASSERT_EQUAL(list->size, 3)
     CU_ASSERT_TRUE(list->capacity >= list->size)
 
@@ -869,7 +869,7 @@
     cxTestingAllocatorReset();
 
     int a = 5, b = 47, c = 13, criteria;
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
+    CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
 
     cxListAdd(list, &a);
     cxListAdd(list, &b);
@@ -915,8 +915,8 @@
 
     cxTestingAllocatorReset();
 
-    CxList list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, scrambled);
-    CxList exp = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, expected);
+    CxList *list = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, scrambled);
+    CxList *exp = cxLinkedListFromArray(cxTestingAllocator, cmp_int, sizeof(int), 100, expected);
 
     cxListSort(list);
     CU_ASSERT_TRUE(0 == cxListCompare(list, exp))
@@ -946,7 +946,7 @@
 
     cxTestingAllocatorReset();
 
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
+    CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
 
     for (int i = 0; i < 100; i++) {
         cxListAdd(list, &scrambled[i]);
@@ -962,7 +962,7 @@
     CU_ASSERT_TRUE(cxTestingAllocatorVerify())
 }
 
-void test_hl_linked_list_iterator_impl(CxList list) {
+void test_hl_linked_list_iterator_impl(CxList *list) {
     int i = 0;
     CxIterator iter = cxListBegin(list);
     cx_foreach(int*, x, iter) {
@@ -984,7 +984,7 @@
 
 void test_hl_linked_list_iterator(void) {
     cxTestingAllocatorReset();
-    CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
+    CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
     for (int i = 0; i < 10; i++) {
         cxListAdd(list, &i);
     }
@@ -993,7 +993,7 @@
 
 void test_hl_ptr_linked_list_iterator(void) {
     cxTestingAllocatorReset();
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
+    CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
     int data[10] = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
     for (int i = 0; i < 10; i++) {
         cxListAdd(list, &data[i]);
@@ -1003,7 +1003,7 @@
 
 void test_hl_linked_list_insert_via_iterator(void) {
     cxTestingAllocatorReset();
-    CxList list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
+    CxList *list = cxLinkedListCreate(cxTestingAllocator, cmp_int, sizeof(int));
     for (int i = 0; i < 5; i++) {
         cxListAdd(list, &i);
     }
@@ -1037,8 +1037,8 @@
     CU_ASSERT_FALSE(cxIteratorValid(&iter))
 
     int expdata[] = {30, 0, 1, 20, 2, 10, 3, 4, 40, 50};
-    CxList expected = cxLinkedListFromArray(cxTestingAllocator,
-                                            cmp_int, sizeof(int), 10, expdata);
+    CxList *expected = cxLinkedListFromArray(cxTestingAllocator,
+                                             cmp_int, sizeof(int), 10, expdata);
 
     CU_ASSERT_EQUAL(0, cxListCompare(list, expected))
     cxLinkedListDestroy(list);
@@ -1049,7 +1049,7 @@
 void test_hl_ptr_linked_list_insert_via_iterator(void) {
     int testdata[] = {0, 1, 2, 3, 4, 10, 20, 30, 40, 50};
     cxTestingAllocatorReset();
-    CxList list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
+    CxList *list = cxPointerLinkedListCreate(cxTestingAllocator, cmp_int);
     int i;
     for (i = 0; i < 5; i++) {
         cxListAdd(list, &testdata[i]);
--- a/test/util_allocator.c	Sat Jan 29 14:32:04 2022 +0100
+++ b/test/util_allocator.c	Sun Jan 30 14:19:00 2022 +0100
@@ -113,7 +113,7 @@
         &cx_testing_allocator_class,
         &cx_testing_allocator_data
 };
-CxAllocator cxTestingAllocator = &cx_testing_allocator;
+CxAllocator *cxTestingAllocator = &cx_testing_allocator;
 
 void cxTestingAllocatorReset(void) {
     memset(&cx_testing_allocator_data, 0, sizeof(cx_testing_allocator_s));
--- a/test/util_allocator.h	Sat Jan 29 14:32:04 2022 +0100
+++ b/test/util_allocator.h	Sun Jan 30 14:19:00 2022 +0100
@@ -68,7 +68,7 @@
     void *tracked[CX_TESTING_ALLOCATOR_MAX_LIVE];
 } cx_testing_allocator_s;
 
-extern CxAllocator cxTestingAllocator;
+extern CxAllocator *cxTestingAllocator;
 
 /**
  * Resets the testing allocator information.

mercurial