summaryrefslogtreecommitdiff
path: root/upb/upb.h
diff options
context:
space:
mode:
authorJoshua Haberman <jhaberman@gmail.com>2019-03-27 15:32:05 -0700
committerGitHub <noreply@github.com>2019-03-27 15:32:05 -0700
commitcf35baa1ad70f0dca734f93bcc2b54d8d059bcdd (patch)
tree3c9881fcceaba1dbb5f04fe01ddc5f2dc5c647d1 /upb/upb.h
parent928ef7f2c02f18d9945dd750884dffbdebef1b98 (diff)
Moved macros from upb.h to port_def.inc to avoid leaking them to users. (#160)
* Use port_def.inc to prevent macros from leaking to users. * Added helpful comments to port_def.inc/port_undef.inc.
Diffstat (limited to 'upb/upb.h')
-rw-r--r--upb/upb.h82
1 files changed, 3 insertions, 79 deletions
diff --git a/upb/upb.h b/upb/upb.h
index 49bb757..7b5d1c1 100644
--- a/upb/upb.h
+++ b/upb/upb.h
@@ -24,85 +24,7 @@ template <int N> class InlinedArena;
}
#endif
-/* UPB_INLINE: inline if possible, emit standalone code if required. */
-#ifdef __cplusplus
-#define UPB_INLINE inline
-#elif defined (__GNUC__)
-#define UPB_INLINE static __inline__
-#else
-#define UPB_INLINE static
-#endif
-
-/* Hints to the compiler about likely/unlikely branches. */
-#define UPB_LIKELY(x) __builtin_expect((x),1)
-
-/* Define UPB_BIG_ENDIAN manually if you're on big endian and your compiler
- * doesn't provide these preprocessor symbols. */
-#if defined(__BYTE_ORDER__) && (__BYTE_ORDER__ == __ORDER_BIG_ENDIAN__)
-#define UPB_BIG_ENDIAN
-#endif
-
-/* Macros for function attributes on compilers that support them. */
-#ifdef __GNUC__
-#define UPB_FORCEINLINE __inline__ __attribute__((always_inline))
-#define UPB_NOINLINE __attribute__((noinline))
-#define UPB_NORETURN __attribute__((__noreturn__))
-#else /* !defined(__GNUC__) */
-#define UPB_FORCEINLINE
-#define UPB_NOINLINE
-#define UPB_NORETURN
-#endif
-
-#if __STDC_VERSION__ >= 199901L || __cplusplus >= 201103L
-/* C99/C++11 versions. */
-#include <stdio.h>
-#define _upb_snprintf snprintf
-#define _upb_vsnprintf vsnprintf
-#define _upb_va_copy(a, b) va_copy(a, b)
-#elif defined __GNUC__
-/* A few hacky workarounds for functions not in C89.
- * For internal use only!
- * TODO(haberman): fix these by including our own implementations, or finding
- * another workaround.
- */
-#define _upb_snprintf __builtin_snprintf
-#define _upb_vsnprintf __builtin_vsnprintf
-#define _upb_va_copy(a, b) __va_copy(a, b)
-#else
-#error Need implementations of [v]snprintf and va_copy
-#endif
-
-#ifdef __cplusplus
-#if __cplusplus >= 201103L || defined(__GXX_EXPERIMENTAL_CXX0X__) || \
- (defined(_MSC_VER) && _MSC_VER >= 1900)
-// C++11 is present
-#else
-#error upb requires C++11 for C++ support
-#endif
-#endif
-
-#define UPB_MAX(x, y) ((x) > (y) ? (x) : (y))
-#define UPB_MIN(x, y) ((x) < (y) ? (x) : (y))
-
-#define UPB_UNUSED(var) (void)var
-
-/* UPB_ASSERT(): in release mode, we use the expression without letting it be
- * evaluated. This prevents "unused variable" warnings. */
-#ifdef NDEBUG
-#define UPB_ASSERT(expr) do {} while (false && (expr))
-#else
-#define UPB_ASSERT(expr) assert(expr)
-#endif
-
-/* UPB_ASSERT_DEBUGVAR(): assert that uses functions or variables that only
- * exist in debug mode. This turns into regular assert. */
-#define UPB_ASSERT_DEBUGVAR(expr) assert(expr)
-
-#ifdef __GNUC__
-#define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0)
-#else
-#define UPB_UNREACHABLE() do { assert(0); } while(0)
-#endif
+#include "upb/port_def.inc"
/* upb_status *****************************************************************/
@@ -429,4 +351,6 @@ typedef enum {
extern const uint8_t upb_desctype_to_fieldtype[];
+#include "upb/port_undef.inc"
+
#endif /* UPB_H_ */
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback