Updates from code review comments.

pull/13171/head
Josh Haberman 10 years ago
parent e2840a4aa1
commit 2cff15d35e
  1. 3
      tests/test_table.cc
  2. 12
      upb/refcounted.c
  3. 8
      upb/table.int.h
  4. 6
      upb/upb.h

@ -62,8 +62,7 @@ void test_strtable(const vector<std::string>& keys, uint32_t num_to_insert) {
upb_strtable_next(&iter)) { upb_strtable_next(&iter)) {
const char *key = upb_strtable_iter_key(&iter); const char *key = upb_strtable_iter_key(&iter);
std::string tmp(key, strlen(key)); std::string tmp(key, strlen(key));
std::string tmp2(key, upb_strtable_iter_keylength(&iter)); ASSERT(strlen(key) == upb_strtable_iter_keylength(&iter));
ASSERT(tmp == tmp2);
std::set<std::string>::iterator i = all.find(tmp); std::set<std::string>::iterator i = all.find(tmp);
ASSERT(i != all.end()); ASSERT(i != all.end());
all.erase(i); all.erase(i);

@ -726,6 +726,18 @@ static void freeobj(upb_refcounted *o) {
bool upb_refcounted_init(upb_refcounted *r, bool upb_refcounted_init(upb_refcounted *r,
const struct upb_refcounted_vtbl *vtbl, const struct upb_refcounted_vtbl *vtbl,
const void *owner) { 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->next = r;
r->vtbl = vtbl; r->vtbl = vtbl;
r->individual_count = 0; r->individual_count = 0;

@ -158,10 +158,14 @@ FUNCS(fptr, fptr, upb_func*, UPB_CTYPE_FPTR);
// length into a byte-wise string representation, so code generation needs to // length into a byte-wise string representation, so code generation needs to
// help it along. // help it along.
// //
// "len1" is the low byte and len4 is the high byte. For big endian we'll need // "len1" is the low byte and len4 is the high byte.
// to define a version of this that flips it around. #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) \ #define UPB_TABKEY_STR(len1, len2, len3, len4, strval) \
(uintptr_t)(len1 len2 len3 len4 strval) (uintptr_t)(len1 len2 len3 len4 strval)
#endif
// Either: // Either:
// 1. an actual integer key, or // 1. an actual integer key, or

@ -25,6 +25,12 @@
#define UPB_INLINE static inline #define UPB_INLINE static inline
#endif #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. // For use in C/C++ source files (not headers), forces inlining within the file.
#ifdef __GNUC__ #ifdef __GNUC__
#define UPB_FORCEINLINE inline __attribute__((always_inline)) #define UPB_FORCEINLINE inline __attribute__((always_inline))

Loading…
Cancel
Save