diff options
author | Feng Xiao <xiaofeng@google.com> | 2015-08-27 15:51:06 -0700 |
---|---|---|
committer | Feng Xiao <xiaofeng@google.com> | 2015-08-27 15:51:06 -0700 |
commit | 59b360f65124716900da74d5e801059907a0f806 (patch) | |
tree | 322783ad5a7c5dcffdb1c911d102d21d3c0c0649 /src/google | |
parent | c7a1f8ec3b7ab4f6763e4d5c2663ad39e13a6aa0 (diff) | |
parent | 2e789bc246144a1b8a3fba5e4de3105089498674 (diff) | |
download | protobuf-59b360f65124716900da74d5e801059907a0f806.tar.gz protobuf-59b360f65124716900da74d5e801059907a0f806.tar.bz2 protobuf-59b360f65124716900da74d5e801059907a0f806.zip |
Merge pull request #767 from pkasting/port
Avoid #including system headers from inside a namespace.
Diffstat (limited to 'src/google')
-rw-r--r-- | src/google/protobuf/stubs/port.h | 16 |
1 files changed, 10 insertions, 6 deletions
diff --git a/src/google/protobuf/stubs/port.h b/src/google/protobuf/stubs/port.h index a3c53dd9..6b94bc3a 100644 --- a/src/google/protobuf/stubs/port.h +++ b/src/google/protobuf/stubs/port.h @@ -79,6 +79,15 @@ #define LIBPROTOC_EXPORT #endif +// These #includes are for the byte swap functions declared later on. +#ifdef _MSC_VER +#include <stdlib.h> // NOLINT(build/include) +#elif defined(__APPLE__) +#include <libkern/OSByteOrder.h> +#elif defined(__GLIBC__) || defined(__CYGWIN__) +#include <byteswap.h> // IWYU pragma: export +#endif + // =================================================================== // from google3/base/port.h namespace google { @@ -275,7 +284,6 @@ inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) { // The following guarantees declaration of the byte swap functions, and // defines __BYTE_ORDER for MSVC #ifdef _MSC_VER -#include <stdlib.h> // NOLINT(build/include) #define __BYTE_ORDER __LITTLE_ENDIAN #define bswap_16(x) _byteswap_ushort(x) #define bswap_32(x) _byteswap_ulong(x) @@ -283,15 +291,11 @@ inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) { #elif defined(__APPLE__) // Mac OS X / Darwin features -#include <libkern/OSByteOrder.h> #define bswap_16(x) OSSwapInt16(x) #define bswap_32(x) OSSwapInt32(x) #define bswap_64(x) OSSwapInt64(x) -#elif defined(__GLIBC__) || defined(__CYGWIN__) -#include <byteswap.h> // IWYU pragma: export - -#else +#elif !defined(__GLIBC__) && !defined(__CYGWIN__) static inline uint16 bswap_16(uint16 x) { return static_cast<uint16>(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8)); |