move the alignment macro to compiler.h
because mem.h is dropped in the Linux kernel. Changed macro definition order (gcc/clang/msvc before c11) due to a limitation in the kernel source builder. Changed the backup to sizeof(), reverting to previous behavior when no support of alignof() is detected.dev
parent
ffbdc8ac57
commit
80a13fd645
|
@ -282,6 +282,39 @@
|
|||
# endif
|
||||
#endif
|
||||
|
||||
/*-**************************************************************
|
||||
* Alignment check
|
||||
*****************************************************************/
|
||||
|
||||
/* this test was initially positioned in mem.h,
|
||||
* but this file is removed (or replaced) for linux kernel
|
||||
* so it's now hosted in compiler.h,
|
||||
* which remains valid for both user & kernel spaces.
|
||||
*/
|
||||
|
||||
#ifndef MEM_ALIGN_COND
|
||||
# if defined(__GNUC__) || defined(_MSC_VER)
|
||||
/* covers gcc, clang & MSVC */
|
||||
/* note : this section must come first, before C11,
|
||||
* due to a limitation in the kernel source generator */
|
||||
# define MEM_ALIGN_COND(T) __alignof(T)
|
||||
|
||||
# elif defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
||||
/* C11 support */
|
||||
# include <stdalign.h>
|
||||
# define MEM_ALIGN_COND(T) alignof(T)
|
||||
|
||||
# else
|
||||
/* No known support for alignof() - imperfect backup */
|
||||
# define MEM_ALIGN_COND(T) sizeof(T)
|
||||
|
||||
# endif
|
||||
#endif /* MEM_ALIGN_COND */
|
||||
|
||||
/*-**************************************************************
|
||||
* Sanitizer
|
||||
*****************************************************************/
|
||||
|
||||
#if ZSTD_MEMORY_SANITIZER
|
||||
/* Not all platforms that support msan provide sanitizers/msan_interface.h.
|
||||
* We therefore declare the functions we need ourselves, rather than trying to
|
||||
|
|
|
@ -80,26 +80,6 @@ extern "C" {
|
|||
#endif
|
||||
|
||||
|
||||
/*-**************************************************************
|
||||
* Alignment check
|
||||
*****************************************************************/
|
||||
|
||||
/* C11 support */
|
||||
#if defined(__STDC_VERSION__) && (__STDC_VERSION__ >= 201112L)
|
||||
|
||||
#include <stdalign.h>
|
||||
# define MEM_ALIGN_COND(T) alignof(T)
|
||||
|
||||
#elif defined(__GNUC__) || defined(_MSC_VER)
|
||||
|
||||
# define MEM_ALIGN_COND(T) __alignof(T)
|
||||
|
||||
#else
|
||||
|
||||
# define MEM_ALIGN_COND(T) 1 /* most likely incorrect, just to pass tests */
|
||||
|
||||
#endif
|
||||
|
||||
/*-**************************************************************
|
||||
* Memory I/O API
|
||||
*****************************************************************/
|
||||
|
|
Loading…
Reference in New Issue