Sat, 19 Oct 2024 14:24:26 +0200
add convenience macro for cx_reallocate to hide the (void**) cast
src/allocator.c | file | annotate | diff | comparison | revisions | |
src/cx/allocator.h | file | annotate | diff | comparison | revisions |
--- a/src/allocator.c Sat Oct 19 13:49:44 2024 +0200 +++ b/src/allocator.c Sat Oct 19 14:24:26 2024 +0200 @@ -75,7 +75,7 @@ }; CxAllocator *cxDefaultAllocator = &cx_default_allocator; - +#undef cx_reallocate int cx_reallocate( void **mem, size_t n
--- a/src/cx/allocator.h Sat Oct 19 13:49:44 2024 +0200 +++ b/src/cx/allocator.h Sat Oct 19 14:24:26 2024 +0200 @@ -151,6 +151,18 @@ ); /** + * Re-allocate a previously allocated block and changes the pointer in-place, if necessary. + * + * \par Error handling + * \c errno will be set by realloc() on failure. + * + * @param mem pointer to the pointer to allocated block + * @param n the new size in bytes + * @return zero on success, non-zero on failure + */ +#define cx_reallocate(mem, n) cx_reallocate((void**)(mem), n) + +/** * Allocate \p n bytes of memory. * * @param allocator the allocator