src/allocator.c

changeset 434
38ee262e8b94
parent 414
81a4c3a63e65
child 450
7960298039cf
     1.1 --- a/src/allocator.c	Sun Sep 26 17:58:27 2021 +0200
     1.2 +++ b/src/allocator.c	Sun Sep 26 18:01:51 2021 +0200
     1.3 @@ -29,21 +29,23 @@
     1.4  #include "cx/allocator.h"
     1.5  
     1.6  #include <stdlib.h>
     1.7 -#include <errno.h>
     1.8  
     1.9 -void *cx_malloc_stdlib(void *unused, size_t n) {
    1.10 +__attribute__((malloc))
    1.11 +void *cx_malloc_stdlib(__attribute__((unused)) void *d, size_t n) {
    1.12      return malloc(n);
    1.13  }
    1.14  
    1.15 -void *cx_realloc_stdlib(void *unused, void *mem, size_t n) {
    1.16 +void *cx_realloc_stdlib(__attribute__((unused)) void *d, void *mem, size_t n) {
    1.17      return realloc(mem, n);
    1.18  }
    1.19  
    1.20 -void *cx_calloc_stdlib(void *unused, size_t nelem, size_t n) {
    1.21 +__attribute__((malloc))
    1.22 +void *cx_calloc_stdlib(__attribute__((unused)) void *d, size_t nelem, size_t n) {
    1.23      return calloc(nelem, n);
    1.24  }
    1.25  
    1.26 -void cx_free_stdlib(void *unused, void *mem) {
    1.27 +__attribute__((nonnull))
    1.28 +void cx_free_stdlib(__attribute__((unused)) void *d, void *mem) {
    1.29      free(mem);
    1.30  }
    1.31  
    1.32 @@ -60,6 +62,8 @@
    1.33  };
    1.34  CxAllocator cxDefaultAllocator = &cx_default_allocator;
    1.35  
    1.36 +/* IMPLEMENTATION OF HIGH LEVEL API */
    1.37 +
    1.38  void *cxMalloc(CxAllocator allocator, size_t n) {
    1.39      return allocator->cl->malloc(allocator->data, n);
    1.40  }
    1.41 @@ -69,10 +73,6 @@
    1.42  }
    1.43  
    1.44  int cxReallocate(CxAllocator allocator, void **mem, size_t n) {
    1.45 -    if (mem == NULL) {
    1.46 -        errno = EINVAL;
    1.47 -        return 1;
    1.48 -    }
    1.49      void* nmem = allocator->cl->realloc(allocator->data, *mem, n);
    1.50      if (nmem == NULL) {
    1.51          return 1;

mercurial