aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChris Robinson <[email protected]>2019-07-26 14:02:14 -0700
committerChris Robinson <[email protected]>2019-07-26 14:02:14 -0700
commit7cfb353334c725b3f57a4a2951b4ff9e352fc956 (patch)
treef5108e9a62528e556463d83008eaf0cbedf8489a
parentb22ecc45c9183572370895790cf955c490196b1f (diff)
Don't explicitly check for standard functions
-rw-r--r--CMakeLists.txt1
-rw-r--r--common/almalloc.cpp6
-rw-r--r--config.h.in3
3 files changed, 4 insertions, 6 deletions
diff --git a/CMakeLists.txt b/CMakeLists.txt
index cf10bc20..60528515 100644
--- a/CMakeLists.txt
+++ b/CMakeLists.txt
@@ -486,7 +486,6 @@ IF(HAVE_INTRIN_H)
ENDIF()
CHECK_SYMBOL_EXISTS(sysconf unistd.h HAVE_SYSCONF)
-CHECK_SYMBOL_EXISTS(aligned_alloc stdlib.h HAVE_ALIGNED_ALLOC)
CHECK_SYMBOL_EXISTS(posix_memalign stdlib.h HAVE_POSIX_MEMALIGN)
CHECK_SYMBOL_EXISTS(_aligned_malloc malloc.h HAVE__ALIGNED_MALLOC)
CHECK_SYMBOL_EXISTS(proc_pidpath libproc.h HAVE_PROC_PIDPATH)
diff --git a/common/almalloc.cpp b/common/almalloc.cpp
index f94ae8bc..2902a087 100644
--- a/common/almalloc.cpp
+++ b/common/almalloc.cpp
@@ -17,12 +17,14 @@
#endif
+#define ALIGNED_ALLOC_AVAILABLE (__STDC_VERSION__ >= 201112L || __cplusplus >= 201703L)
+
void *al_malloc(size_t alignment, size_t size)
{
assert((alignment & (alignment-1)) == 0);
alignment = std::max(alignment, alignof(std::max_align_t));
-#if defined(HAVE_ALIGNED_ALLOC)
+#if ALIGNED_ALLOC_AVAILABLE
size = (size+(alignment-1))&~(alignment-1);
return aligned_alloc(alignment, size);
#elif defined(HAVE_POSIX_MEMALIGN)
@@ -53,7 +55,7 @@ void *al_calloc(size_t alignment, size_t size)
void al_free(void *ptr) noexcept
{
-#if defined(HAVE_ALIGNED_ALLOC) || defined(HAVE_POSIX_MEMALIGN)
+#if ALIGNED_ALLOC_AVAILABLE || defined(HAVE_POSIX_MEMALIGN)
free(ptr);
#elif defined(HAVE__ALIGNED_MALLOC)
_aligned_free(ptr);
diff --git a/config.h.in b/config.h.in
index a98faff8..5dd4311a 100644
--- a/config.h.in
+++ b/config.h.in
@@ -11,9 +11,6 @@
/* Define if we have the sysconf function */
#cmakedefine HAVE_SYSCONF
-/* Define if we have the C11 aligned_alloc function */
-#cmakedefine HAVE_ALIGNED_ALLOC
-
/* Define if we have the posix_memalign function */
#cmakedefine HAVE_POSIX_MEMALIGN