Moved some logic from 'configure' to 'mhd_align.h'

This should improve readability and maintainability of the code.
This commit is contained in:
Evgeny Grin (Karlson2k)
2021-09-13 21:00:54 +03:00
parent a066a34138
commit b6dbca7699
2 changed files with 21 additions and 16 deletions
-7
View File
@@ -308,13 +308,6 @@ AC_CACHE_CHECK([[for C11 'alignof()' support]], [[mhd_cv_c_alignof]],
#include <stdalign.h>
#endif
]], [[
#if (defined (__GNUC__) && __GNUC__ < 4 && __GNUC_MINOR__ < 9 && ! defined(__clang__)) || \
(defined (__clang__) && __clang_major__ < 8)
/* GCC before 4.9 and clang before 8.0 have incorrect implementation of 'alignof()'
which returns preferred alignment instead of minimal required alignment */
#error Compiler has incorrect implementation of alignof()
choke me now
#endif
int var1[(alignof(int) >= 2) ? 1 : -1];
int var2[alignof(unsigned int) - 1];
int var3[(alignof(char) > 0) ? 1 : -1];
+21 -9
View File
@@ -33,24 +33,36 @@
#endif
#ifdef HAVE_C_ALIGNOF
#ifdef HAVE_STDALIGN_H
#include <stdalign.h>
#endif
#endif /* HAVE_STDALIGN_H */
#define _MHD_ALIGNOF(type) alignof(type)
#endif /* HAVE_C_ALIGNOF */
#ifndef _MHD_ALIGNOF
#if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER >= 1900
/* MSVC has the same problem as older GCC versions:
'__alignof()' may return "preferred" alignment instead of "required",
but it is related to floating point variables only. */
#if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER >= 1700
#define _MHD_ALIGNOF(type) __alignof(type)
#endif /* _MSC_VER >= 1900 */
#endif /* !_MHD_ALIGNOF */
#ifdef _MHD_ALIGNOF
#if (defined (__GNUC__) && __GNUC__ < 4 && __GNUC_MINOR__ < 9 && \
! defined(__clang__)) || \
(defined (__clang__) && __clang_major__ < 8) || \
(defined (__clang__) && __clang_major__ < 11 && \
defined(__apple_build_version__))
/* GCC before 4.9 and clang before 8.0 have incorrect implementation of 'alignof()'
which returns preferred alignment instead of minimal required alignment */
#define _MHD_ALIGNOF_UNRELIABLE 1
#endif
#if defined(_MSC_VER) && ! defined(__clang__) && _MSC_VER < 1900
/* MSVC has the same problem as old GCC versions:
'__alignof()' may return "preferred" alignment instead of "required". */
#define _MHD_ALIGNOF_UNRELIABLE 1
#endif /* _MSC_VER < 1900 */
#endif /* _MHD_ALIGNOF */
#ifdef offsetof
#define _MHD_OFFSETOF(strct, membr) offsetof(strct, membr)
@@ -61,7 +73,7 @@
/* Provide a limited set of alignment macros */
/* The set could be extended as needed */
#ifdef _MHD_ALIGNOF
#if defined(_MHD_ALIGNOF) && ! defined(_MHD_ALIGNOF_UNRELIABLE)
#define _MHD_UINT32_ALIGN _MHD_ALIGNOF(uint32_t)
#define _MHD_UINT64_ALIGN _MHD_ALIGNOF(uint64_t)
#else /* ! _MHD_ALIGNOF */