summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--tests/test_table.cc3
-rw-r--r--upb/refcounted.c12
-rw-r--r--upb/table.int.h8
-rw-r--r--upb/upb.h6
4 files changed, 25 insertions, 4 deletions
diff --git a/tests/test_table.cc b/tests/test_table.cc
index 30c5c94..c70ef08 100644
--- a/tests/test_table.cc
+++ b/tests/test_table.cc
@@ -62,8 +62,7 @@ void test_strtable(const vector<std::string>& keys, uint32_t num_to_insert) {
upb_strtable_next(&iter)) {
const char *key = upb_strtable_iter_key(&iter);
std::string tmp(key, strlen(key));
- std::string tmp2(key, upb_strtable_iter_keylength(&iter));
- ASSERT(tmp == tmp2);
+ ASSERT(strlen(key) == upb_strtable_iter_keylength(&iter));
std::set<std::string>::iterator i = all.find(tmp);
ASSERT(i != all.end());
all.erase(i);
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
diff --git a/upb/upb.h b/upb/upb.h
index 13efaed..b62ac36 100644
--- a/upb/upb.h
+++ b/upb/upb.h
@@ -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))
generated by cgit on debian on lair
contact matthew@masot.net with questions or feedback