src/cx/allocator.h

changeset 503
a89857072ace
parent 500
eb9e7bd40a8e
child 508
8aea65ae1eaf
--- a/src/cx/allocator.h	Tue Feb 15 19:07:14 2022 +0100
+++ b/src/cx/allocator.h	Tue Feb 15 19:41:48 2022 +0100
@@ -46,23 +46,37 @@
     /**
      * The allocator's malloc() implementation.
      */
-    void *(*malloc)(void *data, size_t n);
+    void *(*malloc)(
+            void *data,
+            size_t n
+    );
 
     /**
      * The allocator's realloc() implementation.
      */
-    void *(*realloc)(void *data, void *mem, size_t n)
+    void *(*realloc)(
+            void *data,
+            void *mem,
+            size_t n
+    )
     __attribute__((__warn_unused_result__));
 
     /**
      * The allocator's calloc() implementation.
      */
-    void *(*calloc)(void *data, size_t nelem, size_t n);
+    void *(*calloc)(
+            void *data,
+            size_t nelem,
+            size_t n
+    );
 
     /**
      * The allocator's free() implementation.
      */
-    void (*free)(void *data, void *mem)
+    void (*free)(
+            void *data,
+            void *mem
+    )
     __attribute__((__nonnull__));
 } cx_allocator_class;
 
@@ -91,6 +105,18 @@
 extern CxAllocator *cxDefaultAllocator;
 
 /**
+ * Function pointer type for destructor functions.
+ *
+ * A destructor function deallocates possible contents and MAY free the memory
+ * pointed to by \p memory.
+ *
+ * @param memory a pointer to the object to destruct
+ * @return \p memory if it has NOT been free'd by this destructor, otherwise \c NULL
+  */
+typedef void *(*cx_destructor_func)(void *memory)
+        __attribute__((__nonnull__, __warn_unused_result__));
+
+/**
  * Allocate \p n bytes of memory.
  *
  * @param allocator the allocator

mercurial