Skip to content

Commit

Permalink
Merge pull request #4172 from OskarKinomoto/master
Browse files Browse the repository at this point in the history
Add guards against bswap_XX redefnitions
  • Loading branch information
Adam Cozzette committed Jun 25, 2018
2 parents 35567c1 + 609f43c commit d9ccd0c
Showing 1 changed file with 8 additions and 0 deletions.
8 changes: 8 additions & 0 deletions src/google/protobuf/stubs/port.h
Expand Up @@ -382,17 +382,24 @@ inline void GOOGLE_UNALIGNED_STORE64(void *p, uint64 v) {

#elif !defined(__GLIBC__) && !defined(__BIONIC__) && !defined(__CYGWIN__)

#ifndef bswap_16
static inline uint16 bswap_16(uint16 x) {
return static_cast<uint16>(((x & 0xFF) << 8) | ((x & 0xFF00) >> 8));
}
#define bswap_16(x) bswap_16(x)
#endif

#ifndef bswap_32
static inline uint32 bswap_32(uint32 x) {
return (((x & 0xFF) << 24) |
((x & 0xFF00) << 8) |
((x & 0xFF0000) >> 8) |
((x & 0xFF000000) >> 24));
}
#define bswap_32(x) bswap_32(x)
#endif

#ifndef bswap_64
static inline uint64 bswap_64(uint64 x) {
return (((x & GOOGLE_ULONGLONG(0xFF)) << 56) |
((x & GOOGLE_ULONGLONG(0xFF00)) << 40) |
Expand All @@ -404,6 +411,7 @@ static inline uint64 bswap_64(uint64 x) {
((x & GOOGLE_ULONGLONG(0xFF00000000000000)) >> 56));
}
#define bswap_64(x) bswap_64(x)
#endif

#endif

Expand Down

0 comments on commit d9ccd0c

Please sign in to comment.