diff --git a/upb/def.c b/upb/def.c index 91d7586bf1..b92f6176ac 100644 --- a/upb/def.c +++ b/upb/def.c @@ -99,8 +99,8 @@ struct upb_msgdef { /* Is this a map-entry message? */ bool map_entry; - upb_wellknowntype_t well_known_type; bool is_message_set; + upb_wellknowntype_t well_known_type; const upb_fielddef *message_set_ext; }; @@ -161,6 +161,8 @@ struct upb_symtab { /* Inside a symtab we store tagged pointers to specific def types. */ typedef enum { + UPB_DEFTYPE_MASK = 7, + UPB_DEFTYPE_FIELD = 0, /* Only inside symtab table. */ @@ -175,16 +177,20 @@ typedef enum { static upb_deftype_t deftype(upb_value 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) { 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) { - 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); } diff --git a/upb/msg_test.cc b/upb/msg_test.cc index be438438e5..636fbcb9b4 100644 --- a/upb/msg_test.cc +++ b/upb/msg_test.cc @@ -92,7 +92,6 @@ TEST(MessageTest, Extensions) { upb_json_encode(ext_msg, m.ptr(), symtab.ptr(), 0, json_buf, json_size + 1, status.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(), symtab.ptr(), 0, arena.ptr(), status.ptr())) << 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, status.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(), symtab.ptr(), 0, arena.ptr(), status.ptr())) << status.error_message();