diff -r f1e4c6dabfb4 -r 38ee262e8b94 src/allocator.c --- a/src/allocator.c Sun Sep 26 17:58:27 2021 +0200 +++ b/src/allocator.c Sun Sep 26 18:01:51 2021 +0200 @@ -29,21 +29,23 @@ #include "cx/allocator.h" #include -#include -void *cx_malloc_stdlib(void *unused, size_t n) { +__attribute__((malloc)) +void *cx_malloc_stdlib(__attribute__((unused)) void *d, size_t n) { return malloc(n); } -void *cx_realloc_stdlib(void *unused, void *mem, size_t n) { +void *cx_realloc_stdlib(__attribute__((unused)) void *d, void *mem, size_t n) { return realloc(mem, n); } -void *cx_calloc_stdlib(void *unused, size_t nelem, size_t n) { +__attribute__((malloc)) +void *cx_calloc_stdlib(__attribute__((unused)) void *d, size_t nelem, size_t n) { return calloc(nelem, n); } -void cx_free_stdlib(void *unused, void *mem) { +__attribute__((nonnull)) +void cx_free_stdlib(__attribute__((unused)) void *d, void *mem) { free(mem); } @@ -60,6 +62,8 @@ }; CxAllocator cxDefaultAllocator = &cx_default_allocator; +/* IMPLEMENTATION OF HIGH LEVEL API */ + void *cxMalloc(CxAllocator allocator, size_t n) { return allocator->cl->malloc(allocator->data, n); } @@ -69,10 +73,6 @@ } int cxReallocate(CxAllocator allocator, void **mem, size_t n) { - if (mem == NULL) { - errno = EINVAL; - return 1; - } void* nmem = allocator->cl->realloc(allocator->data, *mem, n); if (nmem == NULL) { return 1;