src/cx/allocator.h

changeset 891
49d8cff6f0ee
parent 890
54565fd74e74
--- a/src/cx/allocator.h	Sat Sep 28 15:47:28 2024 +0200
+++ b/src/cx/allocator.h	Sat Sep 28 15:55:14 2024 +0200
@@ -54,12 +54,12 @@
     /**
      * The allocator's realloc() implementation.
      */
+    __attribute__((__warn_unused_result__))
     void *(*realloc)(
             void *data,
             void *mem,
             size_t n
-    )
-    __attribute__((__warn_unused_result__));
+    );
 
     /**
      * The allocator's calloc() implementation.
@@ -73,11 +73,11 @@
     /**
      * The allocator's free() implementation.
      */
+    __attribute__((__nonnull__))
     void (*free)(
             void *data,
             void *mem
-    )
-    __attribute__((__nonnull__));
+    );
 } cx_allocator_class;
 
 /**
@@ -114,7 +114,8 @@
  *
  * @param memory a pointer to the object to destruct
   */
-typedef void (*cx_destructor_func)(void *memory) __attribute__((__nonnull__));
+__attribute__((__nonnull__))
+typedef void (*cx_destructor_func)(void *memory);
 
 /**
  * Function pointer type for destructor functions.
@@ -127,10 +128,11 @@
  * @param data an optional pointer to custom data
  * @param memory a pointer to the object to destruct
   */
+__attribute__((__nonnull__(2)))
 typedef void (*cx_destructor_func2)(
         void *data,
         void *memory
-) __attribute__((__nonnull__(2)));
+);
 
 /**
  * Re-allocate a previously allocated block and changes the pointer in-place, if necessary.
@@ -142,11 +144,11 @@
  * @param n the new size in bytes
  * @return zero on success, non-zero on failure
  */
+__attribute__((__nonnull__))
 int cx_reallocate(
         void **mem,
         size_t n
-)
-__attribute__((__nonnull__));
+);
 
 /**
  * Allocate \p n bytes of memory.
@@ -155,12 +157,12 @@
  * @param n the number of bytes
  * @return a pointer to the allocated memory
  */
+__attribute__((__malloc__))
+__attribute__((__alloc_size__(2)))
 void *cxMalloc(
         const CxAllocator *allocator,
         size_t n
-)
-__attribute__((__malloc__))
-__attribute__((__alloc_size__(2)));
+);
 
 /**
  * Re-allocate the previously allocated block in \p mem, making the new block \p n bytes long.
@@ -174,13 +176,13 @@
  * @param n the new size in bytes
  * @return a pointer to the re-allocated memory
  */
+__attribute__((__warn_unused_result__))
+__attribute__((__alloc_size__(3)))
 void *cxRealloc(
         const CxAllocator *allocator,
         void *mem,
         size_t n
-)
-__attribute__((__warn_unused_result__))
-__attribute__((__alloc_size__(3)));
+);
 
 /**
  * Re-allocate a previously allocated block and changes the pointer in-place, if necessary.
@@ -196,12 +198,12 @@
  * @param n the new size in bytes
  * @return zero on success, non-zero on failure
  */
+__attribute__((__nonnull__))
 int cxReallocate(
         const CxAllocator *allocator,
         void **mem,
         size_t n
-)
-__attribute__((__nonnull__));
+);
 
 /**
  * Allocate \p nelem elements of \p n bytes each, all initialized to zero.
@@ -211,13 +213,13 @@
  * @param n the size of each element in bytes
  * @return a pointer to the allocated memory
  */
+__attribute__((__malloc__))
+__attribute__((__alloc_size__(2, 3)))
 void *cxCalloc(
         const CxAllocator *allocator,
         size_t nelem,
         size_t n
-)
-__attribute__((__malloc__))
-__attribute__((__alloc_size__(2, 3)));
+);
 
 /**
  * Free a block allocated by this allocator.
@@ -227,11 +229,11 @@
  * @param allocator the allocator
  * @param mem a pointer to the block to free
  */
+__attribute__((__nonnull__))
 void cxFree(
         const CxAllocator *allocator,
         void *mem
-)
-__attribute__((__nonnull__));
+);
 
 #ifdef __cplusplus
 } // extern "C"

mercurial