improves usage of attributes

Sun, 03 Oct 2021 12:02:57 +0200

author
Mike Becker <universe@uap-core.de>
date
Sun, 03 Oct 2021 12:02:57 +0200
changeset 450
7960298039cf
parent 449
68ad5750ba6b
child 451
db06dda7ac4d

improves usage of attributes

src/allocator.c file | annotate | diff | comparison | revisions
src/cx/allocator.h file | annotate | diff | comparison | revisions
--- a/src/allocator.c	Sun Oct 03 10:43:31 2021 +0200
+++ b/src/allocator.c	Sun Oct 03 12:02:57 2021 +0200
@@ -30,26 +30,27 @@
 
 #include <stdlib.h>
 
-__attribute__((malloc))
-void *cx_malloc_stdlib(__attribute__((unused)) void *d, size_t n) {
+__attribute__((__malloc__))
+static void *cx_malloc_stdlib(__attribute__((__unused__)) void *d, size_t n) {
     return malloc(n);
 }
 
-void *cx_realloc_stdlib(__attribute__((unused)) void *d, void *mem, size_t n) {
+__attribute__((__warn_unused_result__))
+static void *cx_realloc_stdlib(__attribute__((__unused__)) void *d, void *mem, size_t n) {
     return realloc(mem, n);
 }
 
-__attribute__((malloc))
-void *cx_calloc_stdlib(__attribute__((unused)) void *d, size_t nelem, size_t n) {
+__attribute__((__malloc__))
+static void *cx_calloc_stdlib(__attribute__((__unused__)) void *d, size_t nelem, size_t n) {
     return calloc(nelem, n);
 }
 
-__attribute__((nonnull))
-void cx_free_stdlib(__attribute__((unused)) void *d, void *mem) {
+__attribute__((__nonnull__))
+static void cx_free_stdlib(__attribute__((__unused__)) void *d, void *mem) {
     free(mem);
 }
 
-cx_allocator_class cx_default_allocator_class = {
+static cx_allocator_class cx_default_allocator_class = {
         cx_malloc_stdlib,
         cx_realloc_stdlib,
         cx_calloc_stdlib,
@@ -73,7 +74,7 @@
 }
 
 int cxReallocate(CxAllocator allocator, void **mem, size_t n) {
-    void* nmem = allocator->cl->realloc(allocator->data, *mem, n);
+    void *nmem = allocator->cl->realloc(allocator->data, *mem, n);
     if (nmem == NULL) {
         return 1;
     } else {
--- a/src/cx/allocator.h	Sun Oct 03 10:43:31 2021 +0200
+++ b/src/cx/allocator.h	Sun Oct 03 12:02:57 2021 +0200
@@ -64,7 +64,8 @@
      * @param n the new size in bytes
      * @return a pointer to the re-allocated memory
      */
-    void *(*realloc)(void *data, void *mem, size_t n);
+    void *(*realloc)(void *data, void *mem, size_t n)
+    __attribute__((__warn_unused_result__));
 
     /**
      * Allocate \p nelem elements of \p n bytes each, all initialized to zero.
@@ -84,7 +85,8 @@
      * @param data the allocator's data
      * @param mem a pointer to the block to free
      */
-    void (*free)(void *data, void *mem);
+    void (*free)(void *data, void *mem)
+    __attribute__((__nonnull__));
 } cx_allocator_class;
 
 /**
@@ -118,8 +120,8 @@
  * @param n the number of bytes
  * @return a pointer to the allocated memory
  */
-__attribute__ ((malloc))
-void *cxMalloc(CxAllocator allocator, size_t n);
+void *cxMalloc(CxAllocator allocator, size_t n)
+__attribute__((__malloc__));
 
 /**
  * Re-allocate the previously allocated block in \p mem, making the new block \p n bytes long.
@@ -133,7 +135,8 @@
  * @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));
 
 /**
  * Re-allocate a previously allocated block and changes the pointer in-place, if necessary.
@@ -150,8 +153,8 @@
  * @param n the new size in bytes
  * @return zero on success, non-zero on failure
  */
-__attribute__ ((nonnull))
-int cxReallocate(CxAllocator allocator, void **mem, size_t n);
+int cxReallocate(CxAllocator allocator, void **mem, size_t n)
+__attribute__((nonnull));
 
 /**
  * Allocate \p nelem elements of \p n bytes each, all initialized to zero.
@@ -161,8 +164,8 @@
  * @param n the size of each element in bytes
  * @return a pointer to the allocated memory
  */
-__attribute__ ((malloc))
-void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n);
+void *cxCalloc(CxAllocator allocator, size_t nelem, size_t n)
+__attribute__((malloc));
 
 /**
  * Free a block allocated by this allocator.
@@ -172,8 +175,8 @@
  * @param allocator the allocator
  * @param mem a pointer to the block to free
  */
-__attribute__((nonnull))
-void cxFree(CxAllocator allocator, void *mem);
+void cxFree(CxAllocator allocator, void *mem)
+__attribute__((nonnull));
 
 #ifdef __cplusplus
 } /* extern "C" */

mercurial