Skip to content

Commit

Permalink
Don't include sys/param.h for _BYTE_ORDER
Browse files Browse the repository at this point in the history
It includes a bunch of other files including a lot of macros which can
reduce the namespace available for actual protobuf.

For example, create a protobuf with a member called SIGSEGV. Since
macros cannot be namespaced in C++ this results in code which cannot be
compiled.

Fix this by just directly including endian.h
  • Loading branch information
giannitedesco committed Dec 2, 2020
1 parent 9ee163a commit 339f622
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 4 deletions.
6 changes: 5 additions & 1 deletion src/google/protobuf/io/coded_stream.h
Expand Up @@ -131,7 +131,11 @@
#pragma runtime_checks("c", off)
#endif
#else
#include <sys/param.h> // __BYTE_ORDER
#ifdef __APPLE__
#include <machine/endian.h> // __BYTE_ORDER
#else
#include <endian.h> // __BYTE_ORDER
#endif
#if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \
(defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN)) && \
!defined(PROTOBUF_DISABLE_LITTLE_ENDIAN_OPT_FOR_TEST)
Expand Down
7 changes: 4 additions & 3 deletions src/google/protobuf/stubs/port.h
Expand Up @@ -57,9 +57,10 @@
#pragma runtime_checks("c", off)
#endif
#else
#include <sys/param.h> // __BYTE_ORDER
#if defined(__OpenBSD__)
#include <endian.h>
#ifdef __APPLE__
#include <machine/endian.h> // __BYTE_ORDER
#else
#include <endian.h> // __BYTE_ORDER
#endif
#if ((defined(__LITTLE_ENDIAN__) && !defined(__BIG_ENDIAN__)) || \
(defined(__BYTE_ORDER) && __BYTE_ORDER == __LITTLE_ENDIAN) || \
Expand Down

0 comments on commit 339f622

Please sign in to comment.