Addressed PR comments.

pull/13171/head
Joshua Haberman 3 years ago
parent 77c0381013
commit 2484d12c1c
  1. 14
      upb/def.c
  2. 2
      upb/msg_test.cc

@ -99,8 +99,8 @@ struct upb_msgdef {
/* Is this a map-entry message? */ /* Is this a map-entry message? */
bool map_entry; bool map_entry;
upb_wellknowntype_t well_known_type;
bool is_message_set; bool is_message_set;
upb_wellknowntype_t well_known_type;
const upb_fielddef *message_set_ext; const upb_fielddef *message_set_ext;
}; };
@ -161,6 +161,8 @@ struct upb_symtab {
/* Inside a symtab we store tagged pointers to specific def types. */ /* Inside a symtab we store tagged pointers to specific def types. */
typedef enum { typedef enum {
UPB_DEFTYPE_MASK = 7,
UPB_DEFTYPE_FIELD = 0, UPB_DEFTYPE_FIELD = 0,
/* Only inside symtab table. */ /* Only inside symtab table. */
@ -175,16 +177,20 @@ typedef enum {
static upb_deftype_t deftype(upb_value v) { static upb_deftype_t deftype(upb_value v) {
uintptr_t num = (uintptr_t)upb_value_getconstptr(v); uintptr_t num = (uintptr_t)upb_value_getconstptr(v);
return num & 7; return num & UPB_DEFTYPE_MASK;
} }
static const void *unpack_def(upb_value v, upb_deftype_t type) { static const void *unpack_def(upb_value v, upb_deftype_t type) {
uintptr_t num = (uintptr_t)upb_value_getconstptr(v); uintptr_t num = (uintptr_t)upb_value_getconstptr(v);
return (num & 3) == type ? (const void*)(num & ~3) : NULL; return (num & UPB_DEFTYPE_MASK) == type
? (const void *)(num & ~UPB_DEFTYPE_MASK)
: NULL;
} }
static upb_value pack_def(const void *ptr, upb_deftype_t type) { static upb_value pack_def(const void *ptr, upb_deftype_t type) {
uintptr_t num = (uintptr_t)ptr | type; uintptr_t num = (uintptr_t)ptr;
UPB_ASSERT((num & UPB_DEFTYPE_MASK) == 0);
num |= type;
return upb_value_constptr((const void*)num); return upb_value_constptr((const void*)num);
} }

@ -92,7 +92,6 @@ TEST(MessageTest, Extensions) {
upb_json_encode(ext_msg, m.ptr(), symtab.ptr(), 0, json_buf, json_size + 1, upb_json_encode(ext_msg, m.ptr(), symtab.ptr(), 0, json_buf, json_size + 1,
status.ptr()); status.ptr());
upb_test_TestExtensions *ext_msg3 = upb_test_TestExtensions_new(arena.ptr()); upb_test_TestExtensions *ext_msg3 = upb_test_TestExtensions_new(arena.ptr());
fprintf(stderr, "%.*s\n", (int)json_size, json_buf);
EXPECT_TRUE(upb_json_decode(json_buf, json_size, ext_msg3, m.ptr(), EXPECT_TRUE(upb_json_decode(json_buf, json_size, ext_msg3, m.ptr(),
symtab.ptr(), 0, arena.ptr(), status.ptr())) symtab.ptr(), 0, arena.ptr(), status.ptr()))
<< status.error_message(); << status.error_message();
@ -148,7 +147,6 @@ TEST(MessageTest, MessageSet) {
upb_json_encode(ext_msg, m.ptr(), symtab.ptr(), 0, json_buf, json_size + 1, upb_json_encode(ext_msg, m.ptr(), symtab.ptr(), 0, json_buf, json_size + 1,
status.ptr()); status.ptr());
upb_test_TestMessageSet *ext_msg3 = upb_test_TestMessageSet_new(arena.ptr()); upb_test_TestMessageSet *ext_msg3 = upb_test_TestMessageSet_new(arena.ptr());
fprintf(stderr, "%.*s\n", (int)json_size, json_buf);
EXPECT_TRUE(upb_json_decode(json_buf, json_size, ext_msg3, m.ptr(), EXPECT_TRUE(upb_json_decode(json_buf, json_size, ext_msg3, m.ptr(),
symtab.ptr(), 0, arena.ptr(), status.ptr())) symtab.ptr(), 0, arena.ptr(), status.ptr()))
<< status.error_message(); << status.error_message();

Loading…
Cancel
Save