src/allocator.c

changeset 450
7960298039cf
parent 434
38ee262e8b94
child 452
a10c3e127050
equal deleted inserted replaced
449:68ad5750ba6b 450:7960298039cf
28 28
29 #include "cx/allocator.h" 29 #include "cx/allocator.h"
30 30
31 #include <stdlib.h> 31 #include <stdlib.h>
32 32
33 __attribute__((malloc)) 33 __attribute__((__malloc__))
34 void *cx_malloc_stdlib(__attribute__((unused)) void *d, size_t n) { 34 static void *cx_malloc_stdlib(__attribute__((__unused__)) void *d, size_t n) {
35 return malloc(n); 35 return malloc(n);
36 } 36 }
37 37
38 void *cx_realloc_stdlib(__attribute__((unused)) void *d, void *mem, size_t n) { 38 __attribute__((__warn_unused_result__))
39 static void *cx_realloc_stdlib(__attribute__((__unused__)) void *d, void *mem, size_t n) {
39 return realloc(mem, n); 40 return realloc(mem, n);
40 } 41 }
41 42
42 __attribute__((malloc)) 43 __attribute__((__malloc__))
43 void *cx_calloc_stdlib(__attribute__((unused)) void *d, size_t nelem, size_t n) { 44 static void *cx_calloc_stdlib(__attribute__((__unused__)) void *d, size_t nelem, size_t n) {
44 return calloc(nelem, n); 45 return calloc(nelem, n);
45 } 46 }
46 47
47 __attribute__((nonnull)) 48 __attribute__((__nonnull__))
48 void cx_free_stdlib(__attribute__((unused)) void *d, void *mem) { 49 static void cx_free_stdlib(__attribute__((__unused__)) void *d, void *mem) {
49 free(mem); 50 free(mem);
50 } 51 }
51 52
52 cx_allocator_class cx_default_allocator_class = { 53 static cx_allocator_class cx_default_allocator_class = {
53 cx_malloc_stdlib, 54 cx_malloc_stdlib,
54 cx_realloc_stdlib, 55 cx_realloc_stdlib,
55 cx_calloc_stdlib, 56 cx_calloc_stdlib,
56 cx_free_stdlib 57 cx_free_stdlib
57 }; 58 };
71 void *cxRealloc(CxAllocator allocator, void *mem, size_t n) { 72 void *cxRealloc(CxAllocator allocator, void *mem, size_t n) {
72 return allocator->cl->realloc(allocator->data, mem, n); 73 return allocator->cl->realloc(allocator->data, mem, n);
73 } 74 }
74 75
75 int cxReallocate(CxAllocator allocator, void **mem, size_t n) { 76 int cxReallocate(CxAllocator allocator, void **mem, size_t n) {
76 void* nmem = allocator->cl->realloc(allocator->data, *mem, n); 77 void *nmem = allocator->cl->realloc(allocator->data, *mem, n);
77 if (nmem == NULL) { 78 if (nmem == NULL) {
78 return 1; 79 return 1;
79 } else { 80 } else {
80 *mem = nmem; 81 *mem = nmem;
81 return 0; 82 return 0;

mercurial