diff options
Diffstat (limited to 'upb')
-rw-r--r-- | upb/refcounted.c | 12 | ||||
-rw-r--r-- | upb/table.int.h | 8 | ||||
-rw-r--r-- | upb/upb.h | 6 |
3 files changed, 24 insertions, 2 deletions
diff --git a/upb/refcounted.c b/upb/refcounted.c index 40e6e89..fa775ab 100644 --- a/upb/refcounted.c +++ b/upb/refcounted.c @@ -726,6 +726,18 @@ static void freeobj(upb_refcounted *o) { bool upb_refcounted_init(upb_refcounted *r, const struct upb_refcounted_vtbl *vtbl, const void *owner) { +#ifndef NDEBUG + // Endianness check. This is unrelated to upb_refcounted, it's just a + // convenient place to put the check that we can be assured will run for + // basically every program using upb. + const int x = 1; +#ifdef UPB_BIG_ENDIAN + assert(*(char*)&x != 1); +#else + assert(*(char*)&x == 1); +#endif +#endif + r->next = r; r->vtbl = vtbl; r->individual_count = 0; diff --git a/upb/table.int.h b/upb/table.int.h index 0a246d5..b6e8eb7 100644 --- a/upb/table.int.h +++ b/upb/table.int.h @@ -158,10 +158,14 @@ FUNCS(fptr, fptr, upb_func*, UPB_CTYPE_FPTR); // length into a byte-wise string representation, so code generation needs to // help it along. // -// "len1" is the low byte and len4 is the high byte. For big endian we'll need -// to define a version of this that flips it around. +// "len1" is the low byte and len4 is the high byte. +#ifdef UPB_BIG_ENDIAN +#define UPB_TABKEY_STR(len1, len2, len3, len4, strval) \ + (uintptr_t)(len4 len3 len2 len1 strval) +#else #define UPB_TABKEY_STR(len1, len2, len3, len4, strval) \ (uintptr_t)(len1 len2 len3 len4 strval) +#endif // Either: // 1. an actual integer key, or @@ -25,6 +25,12 @@ #define UPB_INLINE static inline #endif +// Define this 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 + // For use in C/C++ source files (not headers), forces inlining within the file. #ifdef __GNUC__ #define UPB_FORCEINLINE inline __attribute__((always_inline)) |