Migrate feature detection macro checks from #ifdef to #if.

The #if predicate evaluates to false if the macro is undefined, or
defined to 0. #ifdef (and its synonym #if defined) evaluates to false
only if the macro is undefined.

The new setup allows differentiating between setting a macro to 0 (to
express that the capability definitely does not exist / should not be
used) and leaving a macro undefined (to express not knowing whether a
capability exists / not caring if a capability is used).

PiperOrigin-RevId: 391094241
This commit is contained in:
Victor Costan 2021-08-16 18:22:31 +00:00 committed by Victor Costan
parent a8400f1fab
commit cbb83a1d64
7 changed files with 44 additions and 43 deletions

View file

@ -2,46 +2,46 @@
#define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ #define THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_
/* Define to 1 if the compiler supports __attribute__((always_inline)). */ /* Define to 1 if the compiler supports __attribute__((always_inline)). */
#cmakedefine HAVE_ATTRIBUTE_ALWAYS_INLINE 1 #cmakedefine01 HAVE_ATTRIBUTE_ALWAYS_INLINE
/* Define to 1 if the compiler supports __builtin_ctz and friends. */ /* Define to 1 if the compiler supports __builtin_ctz and friends. */
#cmakedefine HAVE_BUILTIN_CTZ 1 #cmakedefine01 HAVE_BUILTIN_CTZ
/* Define to 1 if the compiler supports __builtin_expect. */ /* Define to 1 if the compiler supports __builtin_expect. */
#cmakedefine HAVE_BUILTIN_EXPECT 1 #cmakedefine01 HAVE_BUILTIN_EXPECT
/* Define to 1 if you have a definition for mmap() in <sys/mman.h>. */ /* Define to 1 if you have a definition for mmap() in <sys/mman.h>. */
#cmakedefine HAVE_FUNC_MMAP 1 #cmakedefine01 HAVE_FUNC_MMAP
/* Define to 1 if you have a definition for sysconf() in <unistd.h>. */ /* Define to 1 if you have a definition for sysconf() in <unistd.h>. */
#cmakedefine HAVE_FUNC_SYSCONF 1 #cmakedefine01 HAVE_FUNC_SYSCONF
/* Define to 1 if you have the `lzo2' library (-llzo2). */ /* Define to 1 if you have the `lzo2' library (-llzo2). */
#cmakedefine HAVE_LIBLZO2 1 #cmakedefine01 HAVE_LIBLZO2
/* Define to 1 if you have the `z' library (-lz). */ /* Define to 1 if you have the `z' library (-lz). */
#cmakedefine HAVE_LIBZ 1 #cmakedefine01 HAVE_LIBZ
/* Define to 1 if you have the `lz4' library (-llz4). */ /* Define to 1 if you have the `lz4' library (-llz4). */
#cmakedefine HAVE_LIBLZ4 1 #cmakedefine01 HAVE_LIBLZ4
/* Define to 1 if you have the <sys/mman.h> header file. */ /* Define to 1 if you have the <sys/mman.h> header file. */
#cmakedefine HAVE_SYS_MMAN_H 1 #cmakedefine01 HAVE_SYS_MMAN_H
/* Define to 1 if you have the <sys/resource.h> header file. */ /* Define to 1 if you have the <sys/resource.h> header file. */
#cmakedefine HAVE_SYS_RESOURCE_H 1 #cmakedefine01 HAVE_SYS_RESOURCE_H
/* Define to 1 if you have the <sys/time.h> header file. */ /* Define to 1 if you have the <sys/time.h> header file. */
#cmakedefine HAVE_SYS_TIME_H 1 #cmakedefine01 HAVE_SYS_TIME_H
/* Define to 1 if you have the <sys/uio.h> header file. */ /* Define to 1 if you have the <sys/uio.h> header file. */
#cmakedefine HAVE_SYS_UIO_H 1 #cmakedefine01 HAVE_SYS_UIO_H
/* Define to 1 if you have the <unistd.h> header file. */ /* Define to 1 if you have the <unistd.h> header file. */
#cmakedefine HAVE_UNISTD_H 1 #cmakedefine01 HAVE_UNISTD_H
/* Define to 1 if you have the <windows.h> header file. */ /* Define to 1 if you have the <windows.h> header file. */
#cmakedefine HAVE_WINDOWS_H 1 #cmakedefine01 HAVE_WINDOWS_H
/* Define to 1 if you target processors with SSSE3+ and have <tmmintrin.h>. */ /* Define to 1 if you target processors with SSSE3+ and have <tmmintrin.h>. */
#cmakedefine01 SNAPPY_HAVE_SSSE3 #cmakedefine01 SNAPPY_HAVE_SSSE3
@ -51,6 +51,6 @@
/* Define to 1 if your processor stores words with the most significant byte /* Define to 1 if your processor stores words with the most significant byte
first (like Motorola and SPARC, unlike Intel and VAX). */ first (like Motorola and SPARC, unlike Intel and VAX). */
#cmakedefine SNAPPY_IS_BIG_ENDIAN 1 #cmakedefine01 SNAPPY_IS_BIG_ENDIAN
#endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_ #endif // THIRD_PARTY_SNAPPY_OPENSOURCE_CMAKE_CONFIG_H_

View file

@ -153,8 +153,9 @@ char* CompressFragment(const char* input,
// loading from s2 + n. // loading from s2 + n.
// //
// Separate implementation for 64-bit, little-endian cpus. // Separate implementation for 64-bit, little-endian cpus.
#if !defined(SNAPPY_IS_BIG_ENDIAN) && \ #if !SNAPPY_IS_BIG_ENDIAN && \
(defined(__x86_64__) || defined(_M_X64) || defined(ARCH_PPC) || defined(ARCH_ARM)) (defined(__x86_64__) || defined(_M_X64) || defined(ARCH_PPC) || \
defined(ARCH_ARM))
static inline std::pair<size_t, bool> FindMatchLength(const char* s1, static inline std::pair<size_t, bool> FindMatchLength(const char* s1,
const char* s2, const char* s2,
const char* s2_limit, const char* s2_limit,

View file

@ -31,7 +31,7 @@
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_ #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_STUBS_INTERNAL_H_
#ifdef HAVE_CONFIG_H #if HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
@ -43,11 +43,11 @@
#include <limits> #include <limits>
#include <string> #include <string>
#ifdef HAVE_SYS_MMAN_H #if HAVE_SYS_MMAN_H
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
#ifdef HAVE_UNISTD_H #if HAVE_UNISTD_H
#include <unistd.h> #include <unistd.h>
#endif #endif
@ -90,20 +90,20 @@
#define ARRAYSIZE(a) int{sizeof(a) / sizeof(*(a))} #define ARRAYSIZE(a) int{sizeof(a) / sizeof(*(a))}
// Static prediction hints. // Static prediction hints.
#ifdef HAVE_BUILTIN_EXPECT #if HAVE_BUILTIN_EXPECT
#define SNAPPY_PREDICT_FALSE(x) (__builtin_expect(x, 0)) #define SNAPPY_PREDICT_FALSE(x) (__builtin_expect(x, 0))
#define SNAPPY_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1)) #define SNAPPY_PREDICT_TRUE(x) (__builtin_expect(!!(x), 1))
#else #else
#define SNAPPY_PREDICT_FALSE(x) x #define SNAPPY_PREDICT_FALSE(x) x
#define SNAPPY_PREDICT_TRUE(x) x #define SNAPPY_PREDICT_TRUE(x) x
#endif #endif // HAVE_BUILTIN_EXPECT
// Inlining hints. // Inlining hints.
#ifdef HAVE_ATTRIBUTE_ALWAYS_INLINE #if HAVE_ATTRIBUTE_ALWAYS_INLINE
#define SNAPPY_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline)) #define SNAPPY_ATTRIBUTE_ALWAYS_INLINE __attribute__((always_inline))
#else #else
#define SNAPPY_ATTRIBUTE_ALWAYS_INLINE #define SNAPPY_ATTRIBUTE_ALWAYS_INLINE
#endif #endif // HAVE_ATTRIBUTE_ALWAYS_INLINE
// Stubbed version of ABSL_FLAG. // Stubbed version of ABSL_FLAG.
// //
@ -235,11 +235,11 @@ class LittleEndian {
} }
static inline constexpr bool IsLittleEndian() { static inline constexpr bool IsLittleEndian() {
#if defined(SNAPPY_IS_BIG_ENDIAN) #if SNAPPY_IS_BIG_ENDIAN
return false; return false;
#else #else
return true; return true;
#endif // defined(SNAPPY_IS_BIG_ENDIAN) #endif // SNAPPY_IS_BIG_ENDIAN
} }
}; };
@ -265,7 +265,7 @@ class Bits {
void operator=(const Bits&); void operator=(const Bits&);
}; };
#if defined(HAVE_BUILTIN_CTZ) #if HAVE_BUILTIN_CTZ
inline int Bits::Log2FloorNonZero(uint32_t n) { inline int Bits::Log2FloorNonZero(uint32_t n) {
assert(n != 0); assert(n != 0);
@ -354,7 +354,7 @@ inline int Bits::FindLSBSetNonZero(uint32_t n) {
#endif // End portable versions. #endif // End portable versions.
#if defined(HAVE_BUILTIN_CTZ) #if HAVE_BUILTIN_CTZ
inline int Bits::FindLSBSetNonZero64(uint64_t n) { inline int Bits::FindLSBSetNonZero64(uint64_t n) {
assert(n != 0); assert(n != 0);
@ -388,7 +388,7 @@ inline int Bits::FindLSBSetNonZero64(uint64_t n) {
} }
} }
#endif // End portable version. #endif // HAVE_BUILTIN_CTZ
// Variable-length integer encoding. // Variable-length integer encoding.
class Varint { class Varint {

View file

@ -151,7 +151,7 @@ LogMessageCrash::~LogMessageCrash() {
#pragma warning(pop) #pragma warning(pop)
#endif #endif
#ifdef HAVE_LIBZ #if HAVE_LIBZ
ZLib::ZLib() ZLib::ZLib()
: comp_init_(false), : comp_init_(false),

View file

@ -31,25 +31,25 @@
#ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_ #ifndef THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_
#define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_ #define THIRD_PARTY_SNAPPY_OPENSOURCE_SNAPPY_TEST_H_
#ifdef HAVE_CONFIG_H #if HAVE_CONFIG_H
#include "config.h" #include "config.h"
#endif #endif
#include "snappy-stubs-internal.h" #include "snappy-stubs-internal.h"
#ifdef HAVE_SYS_MMAN_H #if HAVE_SYS_MMAN_H
#include <sys/mman.h> #include <sys/mman.h>
#endif #endif
#ifdef HAVE_SYS_RESOURCE_H #if HAVE_SYS_RESOURCE_H
#include <sys/resource.h> #include <sys/resource.h>
#endif #endif
#ifdef HAVE_SYS_TIME_H #if HAVE_SYS_TIME_H
#include <sys/time.h> #include <sys/time.h>
#endif #endif
#ifdef HAVE_WINDOWS_H #if HAVE_WINDOWS_H
// Needed to be able to use std::max without workarounds in the source code. // Needed to be able to use std::max without workarounds in the source code.
// https://support.microsoft.com/en-us/help/143208/prb-using-stl-in-windows-program-can-cause-min-max-conflicts // https://support.microsoft.com/en-us/help/143208/prb-using-stl-in-windows-program-can-cause-min-max-conflicts
#define NOMINMAX #define NOMINMAX
@ -58,15 +58,15 @@
#define InitGoogle(argv0, argc, argv, remove_flags) ((void)(0)) #define InitGoogle(argv0, argc, argv, remove_flags) ((void)(0))
#ifdef HAVE_LIBZ #if HAVE_LIBZ
#include "zlib.h" #include "zlib.h"
#endif #endif
#ifdef HAVE_LIBLZO2 #if HAVE_LIBLZO2
#include "lzo/lzo1x.h" #include "lzo/lzo1x.h"
#endif #endif
#ifdef HAVE_LIBLZ4 #if HAVE_LIBLZ4
#include "lz4.h" #include "lz4.h"
#endif #endif
@ -216,7 +216,7 @@ class LogMessageVoidify {
#define CHECK_GT(a, b) CRASH_UNLESS((a) > (b)) #define CHECK_GT(a, b) CRASH_UNLESS((a) > (b))
#define CHECK_OK(cond) (cond).ok() #define CHECK_OK(cond) (cond).ok()
#ifdef HAVE_LIBZ #if HAVE_LIBZ
// Object-oriented wrapper around zlib. // Object-oriented wrapper around zlib.
class ZLib { class ZLib {

View file

@ -66,7 +66,7 @@ namespace snappy {
namespace { namespace {
#if defined(HAVE_FUNC_MMAP) && defined(HAVE_FUNC_SYSCONF) #if HAVE_FUNC_MMAP && HAVE_FUNC_SYSCONF
// To test against code that reads beyond its input, this class copies a // To test against code that reads beyond its input, this class copies a
// string to a newly allocated group of pages, the last of which // string to a newly allocated group of pages, the last of which
@ -112,7 +112,7 @@ class DataEndingAtUnreadablePage {
size_t size_; size_t size_;
}; };
#else // defined(HAVE_FUNC_MMAP) && defined(HAVE_FUNC_SYSCONF) #else // HAVE_FUNC_MMAP && HAVE_FUNC_SYSCONF
// Fallback for systems without mmap. // Fallback for systems without mmap.
using DataEndingAtUnreadablePage = std::string; using DataEndingAtUnreadablePage = std::string;

View file

@ -50,7 +50,7 @@ namespace snappy {
namespace { namespace {
#if defined(HAVE_FUNC_MMAP) && defined(HAVE_FUNC_SYSCONF) #if HAVE_FUNC_MMAP && HAVE_FUNC_SYSCONF
// To test against code that reads beyond its input, this class copies a // To test against code that reads beyond its input, this class copies a
// string to a newly allocated group of pages, the last of which // string to a newly allocated group of pages, the last of which
@ -96,7 +96,7 @@ class DataEndingAtUnreadablePage {
size_t size_; size_t size_;
}; };
#else // defined(HAVE_FUNC_MMAP) && defined(HAVE_FUNC_SYSCONF) #else // HAVE_FUNC_MMAP) && HAVE_FUNC_SYSCONF
// Fallback for systems without mmap. // Fallback for systems without mmap.
using DataEndingAtUnreadablePage = std::string; using DataEndingAtUnreadablePage = std::string;