From 6d0b28bb84ce39b64414742fb9b49ea3b1d6c2ec Mon Sep 17 00:00:00 2001 From: Kefu Chai Date: Fri, 22 Jul 2022 00:09:33 +0800 Subject: [PATCH] include/compat: define aligned_free() as a function not a macro so it does not get substituted by the preprocessor unconditionally. this change helps to address the compiling failure when using boost 1.79 using MinGW, like: ../build.deps/mingw/boost/include/boost/align/aligned_allocator.hpp: In member function 'void boost::alignment::aligned_allocator::deallocate(boost::alignment::aligned_allocator::pointer, boost::alignment::aligned_allocator::size_type)': ../src/include/compat.h:352:27: error: '_aligned_free' is not a member of 'boost::alignment'; did you mean 'aligned_free'? 352 | #define aligned_free(ptr) _aligned_free(ptr) | ^~~~~~~~~~~~~ Signed-off-by: Kefu Chai --- src/include/compat.h | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/src/include/compat.h b/src/include/compat.h index 4881e01ff98f7..517e9d4fcd5f0 100644 --- a/src/include/compat.h +++ b/src/include/compat.h @@ -15,6 +15,7 @@ #include "acconfig.h" #include #include +#include #include #if defined(__linux__) @@ -349,7 +350,9 @@ extern _CRTIMP errno_t __cdecl _putenv_s(const char *_Name,const char *_Value); #define compat_closesocket closesocket // Use "aligned_free" when freeing memory allocated using posix_memalign or // _aligned_malloc. Using "free" will crash. -#define aligned_free(ptr) _aligned_free(ptr) +static inline void aligned_free(void* ptr) { + _aligned_free(ptr); +} // O_CLOEXEC is not defined on Windows. Since handles aren't inherited // with subprocesses unless explicitly requested, we'll define this @@ -363,7 +366,9 @@ extern _CRTIMP errno_t __cdecl _putenv_s(const char *_Name,const char *_Value); #define SOCKOPT_VAL_TYPE void* -#define aligned_free(ptr) free(ptr) +static inline void aligned_free(void* ptr) { + free(ptr); +} static inline int compat_closesocket(int fildes) { return close(fildes); } -- 2.39.5