Avoid #including system headers from inside a namespace.
port.h #includes various headers in order to define byteswap functions, but it currently does so from inside the google::protobuf namespace. This can cause bizarre symbol conflicts and other build errors as these headers' contents are then included inside this namespace. Instead, #include the relevant headers above the namespace declarations.
This commit is contained in:
parent
c7a1f8ec3b
commit
2e789bc246
@ -79,6 +79,15 @@
|
|||||||
#define LIBPROTOC_EXPORT
|
#define LIBPROTOC_EXPORT
|
||||||
#endif
|
#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
|
// from google3/base/port.h
|
||||||
namespace google {
|
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
|
// The following guarantees declaration of the byte swap functions, and
|
||||||
// defines __BYTE_ORDER for MSVC
|
// defines __BYTE_ORDER for MSVC
|
||||||
#ifdef _MSC_VER
|
#ifdef _MSC_VER
|
||||||
#include <stdlib.h> // NOLINT(build/include)
|
|
||||||
#define __BYTE_ORDER __LITTLE_ENDIAN
|
#define __BYTE_ORDER __LITTLE_ENDIAN
|
||||||
#define bswap_16(x) _byteswap_ushort(x)
|
#define bswap_16(x) _byteswap_ushort(x)
|
||||||
#define bswap_32(x) _byteswap_ulong(x)
|
#define bswap_32(x) _byteswap_ulong(x)
|
||||||
@ -283,15 +291,11 @@ inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) {
|
|||||||
|
|
||||||
#elif defined(__APPLE__)
|
#elif defined(__APPLE__)
|
||||||
// Mac OS X / Darwin features
|
// Mac OS X / Darwin features
|
||||||
#include <libkern/OSByteOrder.h>
|
|
||||||
#define bswap_16(x) OSSwapInt16(x)
|
#define bswap_16(x) OSSwapInt16(x)
|
||||||
#define bswap_32(x) OSSwapInt32(x)
|
#define bswap_32(x) OSSwapInt32(x)
|
||||||
#define bswap_64(x) OSSwapInt64(x)
|
#define bswap_64(x) OSSwapInt64(x)
|
||||||
|
|
||||||
#elif defined(__GLIBC__) || defined(__CYGWIN__)
|
#elif !defined(__GLIBC__) && !defined(__CYGWIN__)
|
||||||
#include <byteswap.h> // IWYU pragma: export
|
|
||||||
|
|
||||||
#else
|
|
||||||
|
|
||||||
static inline uint16 bswap_16(uint16 x) {
|
static inline uint16 bswap_16(uint16 x) {
|
||||||
return static_cast<uint16>(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8));
|
return static_cast<uint16>(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8));
|
||||||
|
Loading…
Reference in New Issue
Block a user