45 return realloc(mem, n); |
45 return realloc(mem, n); |
46 } |
46 } |
47 |
47 |
48 static void *cx_calloc_stdlib( |
48 static void *cx_calloc_stdlib( |
49 cx_attr_unused void *d, |
49 cx_attr_unused void *d, |
50 size_t nelem, |
50 size_t nmemb, |
51 size_t n |
51 size_t size |
52 ) { |
52 ) { |
53 return calloc(nelem, n); |
53 return calloc(nmemb, size); |
54 } |
54 } |
55 |
55 |
56 static void cx_free_stdlib( |
56 static void cx_free_stdlib( |
57 cx_attr_unused void *d, |
57 cx_attr_unused void *d, |
58 void *mem |
58 void *mem |
69 |
69 |
70 struct cx_allocator_s cx_default_allocator = { |
70 struct cx_allocator_s cx_default_allocator = { |
71 &cx_default_allocator_class, |
71 &cx_default_allocator_class, |
72 NULL |
72 NULL |
73 }; |
73 }; |
74 CxAllocator *cxDefaultAllocator = &cx_default_allocator; |
74 const CxAllocator * const cxDefaultAllocator = &cx_default_allocator; |
75 |
75 |
76 #undef cx_reallocate |
76 int cx_reallocate_( |
77 int cx_reallocate( |
|
78 void **mem, |
77 void **mem, |
79 size_t n |
78 size_t n |
80 ) { |
79 ) { |
81 void *nmem = realloc(*mem, n); |
80 void *nmem = realloc(*mem, n); |
82 if (nmem == NULL) { |
81 if (nmem == NULL) { |
138 } else { |
136 } else { |
139 return allocator->cl->realloc(allocator->data, mem, n); |
137 return allocator->cl->realloc(allocator->data, mem, n); |
140 } |
138 } |
141 } |
139 } |
142 |
140 |
143 #undef cxReallocate |
141 int cxReallocate_( |
144 int cxReallocate( |
|
145 const CxAllocator *allocator, |
142 const CxAllocator *allocator, |
146 void **mem, |
143 void **mem, |
147 size_t n |
144 size_t n |
148 ) { |
145 ) { |
149 void *nmem = allocator->cl->realloc(allocator->data, *mem, n); |
146 void *nmem = allocator->cl->realloc(allocator->data, *mem, n); |