From b12701c381cfe624267091bf04a86645330c6228 Mon Sep 17 00:00:00 2001 From: Patrick Pelissier Date: Sun, 21 May 2017 21:16:08 +0200 Subject: [PATCH] Separate ALLOC & REALLOC macros so that we can overload one, without the other. --- m-core.h | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/m-core.h b/m-core.h index 57170487..c03e024d 100644 --- a/m-core.h +++ b/m-core.h @@ -1007,13 +1007,21 @@ m_core_hash (const void *str, size_t length) # include # define M_MEMORY_ALLOC(type) ((type*)std::malloc (sizeof (type))) # define M_MEMORY_DEL(ptr) std::free(ptr) +#else +# include +# define M_MEMORY_ALLOC(type) malloc (sizeof (type)) +# define M_MEMORY_DEL(ptr) free(ptr) +#endif +#endif + +#ifndef M_MEMORY_REALLOC +#ifdef __cplusplus +# include # define M_MEMORY_REALLOC(type, ptr, n) \ ((type*) (M_UNLIKELY ((n) > SIZE_MAX / sizeof(type)) ? NULL : std::realloc ((ptr), (n)*sizeof (type)))) # define M_MEMORY_FREE(ptr) std::free(ptr) #else # include -# define M_MEMORY_ALLOC(type) malloc (sizeof (type)) -# define M_MEMORY_DEL(ptr) free(ptr) # define M_MEMORY_REALLOC(type, ptr, n) (M_UNLIKELY ((n) > SIZE_MAX / sizeof(type)) ? NULL : realloc ((ptr), (n)*sizeof (type))) # define M_MEMORY_FREE(ptr) free(ptr) #endif