Don't explicitly check for standard functions

This commit is contained in:
Chris Robinson 2019-07-26 14:02:14 -07:00
parent b22ecc45c9
commit 7cfb353334
3 changed files with 4 additions and 6 deletions

View File

@ -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)

View File

@ -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);

View File

@ -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