]> git.apps.os.sepia.ceph.com Git - ceph.git/commitdiff
include/compat: define aligned_free() as a function not a macro 47212/head
authorKefu Chai <tchaikov@gmail.com>
Thu, 21 Jul 2022 16:09:33 +0000 (00:09 +0800)
committerKefu Chai <tchaikov@gmail.com>
Thu, 21 Jul 2022 16:28:58 +0000 (00:28 +0800)
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<T, Alignment>::deallocate(boost::alignment::aligned_allocator<T, Alignment>::pointer, boost::alignment::aligned_allocator<T, Alignment>::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 <tchaikov@gmail.com>
src/include/compat.h

index 4881e01ff98f7abd8f1586b961d29ed0db14660f..517e9d4fcd5f051a729e8287eb980148155445ec 100644 (file)
@@ -15,6 +15,7 @@
 #include "acconfig.h"
 #include <sys/types.h>
 #include <errno.h>
+#include <stdlib.h>
 #include <unistd.h>
 
 #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);
 }