Closed marekmosna closed 2 years ago
In essense, I would change your PR from this:
#ifndef CVECTOR_CUSTOM_MALLOC
#include <stdlib.h> /* for malloc/realloc/free */
/* cvector heap implemented using C library malloc() */
/* in case C library malloc() needs extra protection,
* allow these defines to be overridden.
*/
#ifndef cvector_clib_free
#define cvector_clib_free free
#endif
#ifndef cvector_clib_malloc
#define cvector_clib_malloc malloc
#endif
#ifndef cvector_clib_calloc
#define cvector_clib_calloc calloc
#endif
#ifndef cvector_clib_realloc
#define cvector_clib_realloc realloc
#endif
#else
#ifndef cvector_clib_free
#error "custom cvector_clib_free aquired but not defined"
#endif
#ifndef cvector_clib_malloc
#error "custom cvector_clib_malloc aquired but not defined"
#endif
#ifndef cvector_clib_calloc
#error "custom cvector_clib_calloc aquired but not defined"
#endif
#ifndef cvector_clib_realloc
#error "custom cvector_clib_realloc aquired but not defined"
#endif
#endif /* #ifndef CVECTOR_CUSTOM_MALLOC */
to just this:
#include <stdlib.h> /* for malloc/realloc/free */
/* cvector heap implemented using C library malloc() */
/* in case C library malloc() needs extra protection,
* allow these defines to be overridden.
*/
#ifndef cvector_clib_free
#define cvector_clib_free free
#endif
#ifndef cvector_clib_malloc
#define cvector_clib_malloc malloc
#endif
#ifndef cvector_clib_calloc
#define cvector_clib_calloc calloc
#endif
#ifndef cvector_clib_realloc
#define cvector_clib_realloc realloc
#endif
I actually think the best solution is simpler. Remove the
CVECTOR_CUSTOM_MALLOC
macro and just make it so users can override themalloc
family. If they don't, they'll just get the default.