|
|
|
@ -62,7 +62,7 @@ Error, UINTPTR_MAX is undefined |
|
|
|
|
/* If we always read/write as a consistent type to each address, this shouldn't |
|
|
|
|
* violate aliasing. |
|
|
|
|
*/ |
|
|
|
|
#define UPB_PTR_AT(msg, ofs, type) ((type*)((char*)(msg) + (ofs))) |
|
|
|
|
#define UPB_PTR_AT(msg, ofs, type) ((type *)((char *)(msg) + (ofs))) |
|
|
|
|
|
|
|
|
|
// A flexible array member may have lower alignment requirements than the struct |
|
|
|
|
// overall - in that case, it can overlap with the trailing padding of the rest |
|
|
|
@ -83,7 +83,7 @@ Error, UINTPTR_MAX is undefined |
|
|
|
|
// UPB_INLINE: inline if possible, emit standalone code if required. |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
#define UPB_INLINE inline |
|
|
|
|
#elif defined (__GNUC__) || defined(__clang__) |
|
|
|
|
#elif defined(__GNUC__) || defined(__clang__) |
|
|
|
|
#define UPB_INLINE static __inline__ |
|
|
|
|
#else |
|
|
|
|
#define UPB_INLINE static |
|
|
|
@ -117,7 +117,13 @@ Error, UINTPTR_MAX is undefined |
|
|
|
|
#ifdef __clang__ |
|
|
|
|
#define UPB_ALIGN_OF(type) _Alignof(type) |
|
|
|
|
#else |
|
|
|
|
#define UPB_ALIGN_OF(type) offsetof (struct { char c; type member; }, member) |
|
|
|
|
#define UPB_ALIGN_OF(type) \ |
|
|
|
|
offsetof( \ |
|
|
|
|
struct { \ |
|
|
|
|
char c; \ |
|
|
|
|
type member; \ |
|
|
|
|
}, \ |
|
|
|
|
member) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef _MSC_VER |
|
|
|
@ -128,7 +134,7 @@ Error, UINTPTR_MAX is undefined |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
// Hints to the compiler about likely/unlikely branches. |
|
|
|
|
#if defined (__GNUC__) || defined(__clang__) |
|
|
|
|
#if defined(__GNUC__) || defined(__clang__) |
|
|
|
|
#define UPB_LIKELY(x) __builtin_expect((bool)(x), 1) |
|
|
|
|
#define UPB_UNLIKELY(x) __builtin_expect((bool)(x), 0) |
|
|
|
|
#else |
|
|
|
@ -152,13 +158,14 @@ Error, UINTPTR_MAX is undefined |
|
|
|
|
#define UPB_FORCEINLINE __inline__ __attribute__((always_inline)) static |
|
|
|
|
#define UPB_NOINLINE __attribute__((noinline)) |
|
|
|
|
#define UPB_NORETURN __attribute__((__noreturn__)) |
|
|
|
|
#define UPB_PRINTF(str, first_vararg) __attribute__((format (printf, str, first_vararg))) |
|
|
|
|
#define UPB_PRINTF(str, first_vararg) \ |
|
|
|
|
__attribute__((format(printf, str, first_vararg))) |
|
|
|
|
#elif defined(_MSC_VER) |
|
|
|
|
#define UPB_NOINLINE |
|
|
|
|
#define UPB_FORCEINLINE static |
|
|
|
|
#define UPB_NORETURN __declspec(noreturn) |
|
|
|
|
#define UPB_PRINTF(str, first_vararg) |
|
|
|
|
#else /* !defined(__GNUC__) */ |
|
|
|
|
#else /* !defined(__GNUC__) */ |
|
|
|
|
#define UPB_FORCEINLINE static |
|
|
|
|
#define UPB_NOINLINE |
|
|
|
|
#define UPB_NORETURN |
|
|
|
@ -173,11 +180,15 @@ Error, UINTPTR_MAX is undefined |
|
|
|
|
// UPB_ASSUME(): in release mode, we tell the compiler to assume this is true. |
|
|
|
|
#ifdef NDEBUG |
|
|
|
|
#ifdef __GNUC__ |
|
|
|
|
#define UPB_ASSUME(expr) if (!(expr)) __builtin_unreachable() |
|
|
|
|
#define UPB_ASSUME(expr) \ |
|
|
|
|
if (!(expr)) __builtin_unreachable() |
|
|
|
|
#elif defined _MSC_VER |
|
|
|
|
#define UPB_ASSUME(expr) if (!(expr)) __assume(0) |
|
|
|
|
#define UPB_ASSUME(expr) \ |
|
|
|
|
if (!(expr)) __assume(0) |
|
|
|
|
#else |
|
|
|
|
#define UPB_ASSUME(expr) do {} while (false && (expr)) |
|
|
|
|
#define UPB_ASSUME(expr) \ |
|
|
|
|
do { \ |
|
|
|
|
} while (false && (expr)) |
|
|
|
|
#endif |
|
|
|
|
#else |
|
|
|
|
#define UPB_ASSUME(expr) assert(expr) |
|
|
|
@ -186,13 +197,19 @@ Error, UINTPTR_MAX is undefined |
|
|
|
|
/* 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)) |
|
|
|
|
#define UPB_ASSERT(expr) \ |
|
|
|
|
do { \ |
|
|
|
|
} while (false && (expr)) |
|
|
|
|
#else |
|
|
|
|
#define UPB_ASSERT(expr) assert(expr) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(__GNUC__) || defined(__clang__) |
|
|
|
|
#define UPB_UNREACHABLE() do { assert(0); __builtin_unreachable(); } while(0) |
|
|
|
|
#define UPB_UNREACHABLE() \ |
|
|
|
|
do { \ |
|
|
|
|
assert(0); \ |
|
|
|
|
__builtin_unreachable(); \ |
|
|
|
|
} while (0) |
|
|
|
|
#elif defined(_MSC_VER) |
|
|
|
|
#define UPB_UNREACHABLE() \ |
|
|
|
|
do { \ |
|
|
|
@ -200,7 +217,16 @@ Error, UINTPTR_MAX is undefined |
|
|
|
|
__assume(0); \ |
|
|
|
|
} while (0) |
|
|
|
|
#else |
|
|
|
|
#define UPB_UNREACHABLE() do { assert(0); } while(0) |
|
|
|
|
#define UPB_UNREACHABLE() \ |
|
|
|
|
do { \ |
|
|
|
|
assert(0); \ |
|
|
|
|
} while (0) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#ifdef __ANDROID__ |
|
|
|
|
#define UPB_DEFAULT_MAX_BLOCK_SIZE 8192; |
|
|
|
|
#else |
|
|
|
|
#define UPB_DEFAULT_MAX_BLOCK_SIZE 32768; |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
/* UPB_SETJMP() / UPB_LONGJMP() */ |
|
|
|
@ -348,10 +374,10 @@ Error, UINTPTR_MAX is undefined |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
extern "C" { |
|
|
|
|
#endif |
|
|
|
|
void __asan_poison_memory_region(void const volatile *addr, size_t size); |
|
|
|
|
void __asan_unpoison_memory_region(void const volatile *addr, size_t size); |
|
|
|
|
void __asan_poison_memory_region(void const volatile *addr, size_t size); |
|
|
|
|
void __asan_unpoison_memory_region(void const volatile *addr, size_t size); |
|
|
|
|
#ifdef __cplusplus |
|
|
|
|
} /* extern "C" */ |
|
|
|
|
} /* extern "C" */ |
|
|
|
|
#endif |
|
|
|
|
#define UPB_POISON_MEMORY_REGION(addr, size) \ |
|
|
|
|
__asan_poison_memory_region((addr), (size)) |
|
|
|
@ -360,10 +386,8 @@ void __asan_unpoison_memory_region(void const volatile *addr, size_t size); |
|
|
|
|
#else |
|
|
|
|
#define UPB_ASAN 0 |
|
|
|
|
#define UPB_ASAN_GUARD_SIZE 0 |
|
|
|
|
#define UPB_POISON_MEMORY_REGION(addr, size) \ |
|
|
|
|
((void)(addr), (void)(size)) |
|
|
|
|
#define UPB_UNPOISON_MEMORY_REGION(addr, size) \ |
|
|
|
|
((void)(addr), (void)(size)) |
|
|
|
|
#define UPB_POISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) |
|
|
|
|
#define UPB_UNPOISON_MEMORY_REGION(addr, size) ((void)(addr), (void)(size)) |
|
|
|
|
#endif |
|
|
|
|
|
|
|
|
|
#if defined(__SANITIZE_THREAD__) || UPB_CLANG_TSAN |
|
|
|
|