rename upb::SymbolTable as upb::DefPool

PiperOrigin-RevId: 456147709
pull/13171/head
Protobuf Team Bot 3 years ago committed by Copybara-Service
parent 88047d90ba
commit 97993b219d
  1. 8
      benchmarks/benchmark.cc
  2. 59
      upb/bindings/lua/def.c
  3. 30
      upb/bindings/lua/test_upb.lua
  4. 2
      upb/bindings/lua/upb.lua
  5. 11
      upb/def.hpp
  6. 8
      upb/json_test.cc
  7. 38
      upb/msg_test.cc
  8. 16
      upb/test_cpp.cc
  9. 17
      upb/util/def_to_proto_test.cc
  10. 10
      upb/util/required_fields_test.cc

@ -136,15 +136,15 @@ template <LoadDescriptorMode Mode>
static void BM_LoadAdsDescriptor_Upb(benchmark::State& state) {
size_t bytes_per_iter = 0;
for (auto _ : state) {
upb::SymbolTable symtab;
upb::DefPool defpool;
if (Mode == NoLayout) {
google_ads_googleads_v11_services_SearchGoogleAdsRequest_getmsgdef(
symtab.ptr());
bytes_per_iter = _upb_DefPool_BytesLoaded(symtab.ptr());
defpool.ptr());
bytes_per_iter = _upb_DefPool_BytesLoaded(defpool.ptr());
} else {
bytes_per_iter = 0;
LoadDefInit_BuildLayout(
symtab.ptr(),
defpool.ptr(),
&google_ads_googleads_v11_services_google_ads_service_proto_upbdefinit,
&bytes_per_iter);
}

@ -42,7 +42,7 @@
#define LUPB_FILEDEF "lupb.filedef"
#define LUPB_MSGDEF "lupb.msgdef"
#define LUPB_ONEOFDEF "lupb.oneof"
#define LUPB_SYMTAB "lupb.symtab"
#define LUPB_SYMTAB "lupb.defpool"
#define LUPB_OBJCACHE "lupb.objcache"
static void lupb_DefPool_pushwrapper(lua_State* L, int narg, const void* def,
@ -51,7 +51,7 @@ static void lupb_DefPool_pushwrapper(lua_State* L, int narg, const void* def,
/* lupb_wrapper ***************************************************************/
/* Wrappers around upb def objects. The userval contains a reference to the
* symtab. */
* defpool. */
#define LUPB_SYMTAB_INDEX 1
@ -65,19 +65,19 @@ static const void* lupb_wrapper_check(lua_State* L, int narg,
return w->def;
}
static void lupb_wrapper_pushsymtab(lua_State* L, int narg) {
static void lupb_wrapper_pushdefpool(lua_State* L, int narg) {
lua_getiuservalue(L, narg, LUPB_SYMTAB_INDEX);
}
/* lupb_wrapper_pushwrapper()
*
* For a given def wrapper at index |narg|, pushes a wrapper for the given |def|
* and the given |type|. The new wrapper will be part of the same symtab. */
* and the given |type|. The new wrapper will be part of the same defpool. */
static void lupb_wrapper_pushwrapper(lua_State* L, int narg, const void* def,
const char* type) {
lupb_wrapper_pushsymtab(L, narg);
lupb_wrapper_pushdefpool(L, narg);
lupb_DefPool_pushwrapper(L, -1, def, type);
lua_replace(L, -2); /* Remove symtab from stack. */
lua_replace(L, -2); /* Remove defpool from stack. */
}
/* lupb_MessageDef_pushsubmsgdef()
@ -337,8 +337,8 @@ static int lupb_MessageDef_OneofCount(lua_State* L) {
static bool lupb_MessageDef_pushnested(lua_State* L, int msgdef, int name) {
const upb_MessageDef* m = lupb_MessageDef_check(L, msgdef);
lupb_wrapper_pushsymtab(L, msgdef);
upb_DefPool* symtab = lupb_DefPool_check(L, -1);
lupb_wrapper_pushdefpool(L, msgdef);
upb_DefPool* defpool = lupb_DefPool_check(L, -1);
lua_pop(L, 1);
/* Construct full package.Message.SubMessage name. */
@ -350,7 +350,7 @@ static bool lupb_MessageDef_pushnested(lua_State* L, int msgdef, int name) {
/* Try lookup. */
const upb_MessageDef* nested =
upb_DefPool_FindMessageByName(symtab, nested_name);
upb_DefPool_FindMessageByName(defpool, nested_name);
if (!nested) return false;
lupb_wrapper_pushwrapper(L, msgdef, nested, LUPB_MSGDEF);
return true;
@ -671,8 +671,8 @@ static int lupb_FileDef_Package(lua_State* L) {
static int lupb_FileDef_Pool(lua_State* L) {
const upb_FileDef* f = lupb_FileDef_check(L, 1);
const upb_DefPool* symtab = upb_FileDef_Pool(f);
lupb_wrapper_pushwrapper(L, 1, symtab, LUPB_SYMTAB);
const upb_DefPool* defpool = upb_FileDef_Pool(f);
lupb_wrapper_pushwrapper(L, 1, defpool, LUPB_SYMTAB);
return 1;
}
@ -691,30 +691,30 @@ static const struct luaL_Reg lupb_FileDef_m[] = {
{"msgcount", lupb_FileDef_msgcount},
{"name", lupb_FileDef_Name},
{"package", lupb_FileDef_Package},
{"symtab", lupb_FileDef_Pool},
{"defpool", lupb_FileDef_Pool},
{"syntax", lupb_FileDef_Syntax},
{NULL, NULL}};
/* lupb_DefPool
* ****************************************************************/
/* The symtab owns all defs. Thus GC-rooting the symtab ensures that all
/* The defpool owns all defs. Thus GC-rooting the defpool ensures that all
* underlying defs stay alive.
*
* The symtab's userval is a cache of def* -> object. */
* The defpool's userval is a cache of def* -> object. */
#define LUPB_CACHE_INDEX 1
typedef struct {
upb_DefPool* symtab;
upb_DefPool* defpool;
} lupb_DefPool;
upb_DefPool* lupb_DefPool_check(lua_State* L, int narg) {
lupb_DefPool* lsymtab = luaL_checkudata(L, narg, LUPB_SYMTAB);
if (!lsymtab->symtab) {
lupb_DefPool* ldefpool = luaL_checkudata(L, narg, LUPB_SYMTAB);
if (!ldefpool->defpool) {
luaL_error(L, "called into dead object");
}
return lsymtab->symtab;
return ldefpool->defpool;
}
void lupb_DefPool_pushwrapper(lua_State* L, int narg, const void* def,
@ -739,7 +739,7 @@ void lupb_DefPool_pushwrapper(lua_State* L, int narg, const void* def,
w->def = def;
lua_replace(L, -2); /* Replace nil */
/* Set symtab as userval. */
/* Set defpool as userval. */
lua_pushvalue(L, narg);
lua_setiuservalue(L, -2, LUPB_SYMTAB_INDEX);
@ -754,11 +754,12 @@ void lupb_DefPool_pushwrapper(lua_State* L, int narg, const void* def,
/* upb_DefPool_New()
*
* Handles:
* upb.SymbolTable() -> <new instance>
* upb.DefPool() -> <new instance>
*/
static int lupb_DefPool_New(lua_State* L) {
lupb_DefPool* lsymtab = lupb_newuserdata(L, sizeof(*lsymtab), 1, LUPB_SYMTAB);
lsymtab->symtab = upb_DefPool_New();
lupb_DefPool* ldefpool =
lupb_newuserdata(L, sizeof(*ldefpool), 1, LUPB_SYMTAB);
ldefpool->defpool = upb_DefPool_New();
/* Create our object cache. */
lua_newtable(L);
@ -769,9 +770,9 @@ static int lupb_DefPool_New(lua_State* L) {
lua_setfield(L, -2, "__mode");
lua_setmetatable(L, -2);
/* Put the symtab itself in the cache metatable. */
/* Put the defpool itself in the cache metatable. */
lua_pushvalue(L, -2);
lua_rawsetp(L, -2, lsymtab->symtab);
lua_rawsetp(L, -2, ldefpool->defpool);
/* Set the cache as our userval. */
lua_setiuservalue(L, -2, LUPB_CACHE_INDEX);
@ -780,9 +781,9 @@ static int lupb_DefPool_New(lua_State* L) {
}
static int lupb_DefPool_gc(lua_State* L) {
lupb_DefPool* lsymtab = luaL_checkudata(L, 1, LUPB_SYMTAB);
upb_DefPool_Free(lsymtab->symtab);
lsymtab->symtab = NULL;
lupb_DefPool* ldefpool = luaL_checkudata(L, 1, LUPB_SYMTAB);
upb_DefPool_Free(ldefpool->defpool);
ldefpool->defpool = NULL;
return 0;
}
@ -859,7 +860,7 @@ static int lupb_DefPool_FindEnumByNameval(lua_State* L) {
}
static int lupb_DefPool_tostring(lua_State* L) {
lua_pushfstring(L, "<upb.SymbolTable>");
lua_pushfstring(L, "<upb.DefPool>");
return 1;
}
@ -884,7 +885,7 @@ static void lupb_setfieldi(lua_State* L, const char* field, int i) {
}
static const struct luaL_Reg lupbdef_toplevel_m[] = {
{"SymbolTable", lupb_DefPool_New}, {NULL, NULL}};
{"DefPool", lupb_DefPool_New}, {NULL, NULL}};
void lupb_def_registertypes(lua_State* L) {
lupb_setfuncs(L, lupbdef_toplevel_m);

@ -408,7 +408,7 @@ function test_finalizer()
end)
end)
t = {
upb.SymbolTable(),
upb.DefPool(),
}
end
collectgarbage()
@ -666,14 +666,14 @@ function test_unknown()
end
function test_foo()
local symtab = upb.SymbolTable()
local defpool = upb.DefPool()
local filename = "external/com_google_protobuf/descriptor_proto-descriptor-set.proto.bin"
local file = io.open(filename, "rb") or io.open("bazel-bin/" .. filename, "rb")
assert_not_nil(file)
local descriptor = file:read("*a")
assert_true(#descriptor > 0)
symtab:add_set(descriptor)
local FileDescriptorSet = symtab:lookup_msg("google.protobuf.FileDescriptorSet")
defpool:add_set(descriptor)
local FileDescriptorSet = defpool:lookup_msg("google.protobuf.FileDescriptorSet")
assert_not_nil(FileDescriptorSet)
set = FileDescriptorSet()
assert_equal(#set.file, 0)
@ -690,7 +690,7 @@ function test_foo()
end
function test_descriptor()
local symtab = upb.SymbolTable()
local defpool = upb.DefPool()
local file_proto = descriptor.FileDescriptorProto {
name = "test.proto",
message_type = upb.Array(descriptor.DescriptorProto, {
@ -699,12 +699,12 @@ function test_descriptor()
},
})
}
local file = symtab:add_file(upb.encode(file_proto))
assert_equal(file:symtab(), symtab)
local file = defpool:add_file(upb.encode(file_proto))
assert_equal(file:defpool(), defpool)
end
function test_descriptor_error()
local symtab = upb.SymbolTable()
local defpool = upb.DefPool()
local file = descriptor.FileDescriptorProto()
file.name = "test.proto"
file.message_type[1] = descriptor.DescriptorProto{
@ -713,12 +713,12 @@ function test_descriptor_error()
file.message_type[2] = descriptor.DescriptorProto{
name = "BC."
}
assert_error(function () symtab:add_file(upb.encode(file)) end)
assert_nil(symtab:lookup_msg("ABC"))
assert_error(function () defpool:add_file(upb.encode(file)) end)
assert_nil(defpool:lookup_msg("ABC"))
end
function test_duplicate_enumval()
local symtab = upb.SymbolTable()
local defpool = upb.DefPool()
local file_proto = descriptor.FileDescriptorProto {
name = "test.proto",
message_type = upb.Array(descriptor.DescriptorProto, {
@ -738,16 +738,16 @@ function test_duplicate_enumval()
},
})
}
assert_error(function () symtab:add_file(upb.encode(file_proto)) end)
assert_error(function () defpool:add_file(upb.encode(file_proto)) end)
end
function test_duplicate_filename_error()
local symtab = upb.SymbolTable()
local defpool = upb.DefPool()
local file = descriptor.FileDescriptorProto()
file.name = "test.proto"
symtab:add_file(upb.encode(file))
defpool:add_file(upb.encode(file))
-- Second add with the same filename fails.
assert_error(function () symtab:add_file(upb.encode(file)) end)
assert_error(function () defpool:add_file(upb.encode(file)) end)
end
function test_encode_skipunknown()

@ -29,7 +29,7 @@
local upb = require("lupb")
upb.generated_pool = upb.SymbolTable()
upb.generated_pool = upb.DefPool()
local module_metatable = {
__index = function(t, k)

@ -373,11 +373,11 @@ class FileDefPtr {
const upb_FileDef* ptr_;
};
// Non-const methods in upb::SymbolTable are NOT thread-safe.
class SymbolTable {
// Non-const methods in upb::DefPool are NOT thread-safe.
class DefPool {
public:
SymbolTable() : ptr_(upb_DefPool_New(), upb_DefPool_Free) {}
explicit SymbolTable(upb_DefPool* s) : ptr_(s, upb_DefPool_Free) {}
DefPool() : ptr_(upb_DefPool_New(), upb_DefPool_Free) {}
explicit DefPool(upb_DefPool* s) : ptr_(s, upb_DefPool_Free) {}
const upb_DefPool* ptr() const { return ptr_.get(); }
upb_DefPool* ptr() { return ptr_.get(); }
@ -409,6 +409,9 @@ class SymbolTable {
std::unique_ptr<upb_DefPool, decltype(&upb_DefPool_Free)> ptr_;
};
// TODO(b/236632406): This typedef is deprecated. Delete it.
using SymbolTable = DefPool;
inline FileDefPtr MessageDefPtr::file() const {
return FileDefPtr(upb_MessageDef_File(ptr_));
}

@ -36,15 +36,15 @@
static std::string JsonEncode(const upb_test_Box* msg, int options) {
upb::Arena a;
upb::Status status;
upb::SymbolTable symtab;
upb::MessageDefPtr m(upb_test_Box_getmsgdef(symtab.ptr()));
upb::DefPool defpool;
upb::MessageDefPtr m(upb_test_Box_getmsgdef(defpool.ptr()));
EXPECT_TRUE(m.ptr() != nullptr);
size_t json_size = upb_JsonEncode(msg, m.ptr(), symtab.ptr(), options, NULL,
size_t json_size = upb_JsonEncode(msg, m.ptr(), defpool.ptr(), options, NULL,
0, status.ptr());
char* json_buf = (char*)upb_Arena_Malloc(a.ptr(), json_size + 1);
size_t size = upb_JsonEncode(msg, m.ptr(), symtab.ptr(), options, json_buf,
size_t size = upb_JsonEncode(msg, m.ptr(), defpool.ptr(), options, json_buf,
json_size + 1, status.ptr());
EXPECT_EQ(size, json_size);
return std::string(json_buf, json_size);

@ -57,8 +57,8 @@ TEST(MessageTest, Extensions) {
// EXPECT_FALSE(upb_test_TestExtensions_Nested_has_optional_int32_ext(ext_msg));
EXPECT_FALSE(upb_test_has_optional_msg_ext(ext_msg));
upb::SymbolTable symtab;
upb::MessageDefPtr m(upb_test_TestExtensions_getmsgdef(symtab.ptr()));
upb::DefPool defpool;
upb::MessageDefPtr m(upb_test_TestExtensions_getmsgdef(defpool.ptr()));
EXPECT_TRUE(m.ptr() != nullptr);
std::string json = R"json(
@ -70,7 +70,7 @@ TEST(MessageTest, Extensions) {
)json";
upb::Status status;
EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), ext_msg, m.ptr(),
symtab.ptr(), 0, arena.ptr(), status.ptr()))
defpool.ptr(), 0, arena.ptr(), status.ptr()))
<< status.error_message();
VerifyMessage(ext_msg);
@ -83,20 +83,20 @@ TEST(MessageTest, Extensions) {
ASSERT_GE(size, 0);
upb_test_TestExtensions* ext_msg2 = upb_test_TestExtensions_parse_ex(
serialized, size, upb_DefPool_ExtensionRegistry(symtab.ptr()), 0,
serialized, size, upb_DefPool_ExtensionRegistry(defpool.ptr()), 0,
arena.ptr());
VerifyMessage(ext_msg2);
// Test round-trip through JSON format.
size_t json_size =
upb_JsonEncode(ext_msg, m.ptr(), symtab.ptr(), 0, NULL, 0, status.ptr());
upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, NULL, 0, status.ptr());
char* json_buf =
static_cast<char*>(upb_Arena_Malloc(arena.ptr(), json_size + 1));
upb_JsonEncode(ext_msg, m.ptr(), symtab.ptr(), 0, json_buf, json_size + 1,
upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, json_buf, json_size + 1,
status.ptr());
upb_test_TestExtensions* ext_msg3 = upb_test_TestExtensions_new(arena.ptr());
EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, ext_msg3, m.ptr(),
symtab.ptr(), 0, arena.ptr(), status.ptr()))
defpool.ptr(), 0, arena.ptr(), status.ptr()))
<< status.error_message();
VerifyMessage(ext_msg3);
}
@ -119,8 +119,8 @@ TEST(MessageTest, MessageSet) {
EXPECT_FALSE(upb_test_MessageSetMember_has_message_set_extension(ext_msg));
upb::SymbolTable symtab;
upb::MessageDefPtr m(upb_test_TestMessageSet_getmsgdef(symtab.ptr()));
upb::DefPool defpool;
upb::MessageDefPtr m(upb_test_TestMessageSet_getmsgdef(defpool.ptr()));
EXPECT_TRUE(m.ptr() != nullptr);
std::string json = R"json(
@ -130,7 +130,7 @@ TEST(MessageTest, MessageSet) {
)json";
upb::Status status;
EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), ext_msg, m.ptr(),
symtab.ptr(), 0, arena.ptr(), status.ptr()))
defpool.ptr(), 0, arena.ptr(), status.ptr()))
<< status.error_message();
VerifyMessageSet(ext_msg);
@ -143,20 +143,20 @@ TEST(MessageTest, MessageSet) {
ASSERT_GE(size, 0);
upb_test_TestMessageSet* ext_msg2 = upb_test_TestMessageSet_parse_ex(
serialized, size, upb_DefPool_ExtensionRegistry(symtab.ptr()), 0,
serialized, size, upb_DefPool_ExtensionRegistry(defpool.ptr()), 0,
arena.ptr());
VerifyMessageSet(ext_msg2);
// Test round-trip through JSON format.
size_t json_size =
upb_JsonEncode(ext_msg, m.ptr(), symtab.ptr(), 0, NULL, 0, status.ptr());
upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, NULL, 0, status.ptr());
char* json_buf =
static_cast<char*>(upb_Arena_Malloc(arena.ptr(), json_size + 1));
upb_JsonEncode(ext_msg, m.ptr(), symtab.ptr(), 0, json_buf, json_size + 1,
upb_JsonEncode(ext_msg, m.ptr(), defpool.ptr(), 0, json_buf, json_size + 1,
status.ptr());
upb_test_TestMessageSet* ext_msg3 = upb_test_TestMessageSet_new(arena.ptr());
EXPECT_TRUE(upb_JsonDecode(json_buf, json_size, ext_msg3, m.ptr(),
symtab.ptr(), 0, arena.ptr(), status.ptr()))
defpool.ptr(), 0, arena.ptr(), status.ptr()))
<< status.error_message();
VerifyMessageSet(ext_msg3);
}
@ -188,11 +188,11 @@ TEST(MessageTest, UnknownMessageSet) {
ASSERT_TRUE(serialized != nullptr);
ASSERT_GE(size, 0);
upb::SymbolTable symtab;
upb::MessageDefPtr m(upb_test_TestMessageSet_getmsgdef(symtab.ptr()));
upb::DefPool defpool;
upb::MessageDefPtr m(upb_test_TestMessageSet_getmsgdef(defpool.ptr()));
EXPECT_TRUE(m.ptr() != nullptr);
upb_test_TestMessageSet* message_set = upb_test_TestMessageSet_parse_ex(
serialized, size, upb_DefPool_ExtensionRegistry(symtab.ptr()), 0,
serialized, size, upb_DefPool_ExtensionRegistry(defpool.ptr()), 0,
arena.ptr());
ASSERT_TRUE(message_set != nullptr);
@ -437,8 +437,8 @@ TEST(MessageTest, MaxRequiredFields) {
test_msg, kUpb_EncodeOption_CheckRequired, arena.ptr(), &size);
ASSERT_TRUE(serialized == nullptr);
upb::SymbolTable symtab;
upb::MessageDefPtr m(upb_test_TestMaxRequiredFields_getmsgdef(symtab.ptr()));
upb::DefPool defpool;
upb::MessageDefPtr m(upb_test_TestMaxRequiredFields_getmsgdef(defpool.ptr()));
upb_MessageValue val;
val.int32_val = 1;
for (int i = 1; i <= 61; i++) {

@ -50,8 +50,8 @@
#include "upb/port_def.inc"
TEST(Cpp, Iteration) {
upb::SymbolTable symtab;
upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(symtab.ptr()));
upb::DefPool defpool;
upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(defpool.ptr()));
// Test range-based for on both fields and oneofs (with the iterator adaptor).
int field_count = 0;
@ -131,17 +131,17 @@ TEST(Cpp, InlinedArena) {
}
TEST(Cpp, Default) {
upb::SymbolTable symtab;
upb::DefPool defpool;
upb::Arena arena;
upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(symtab.ptr()));
upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(defpool.ptr()));
upb_test_TestMessage* msg = upb_test_TestMessage_new(arena.ptr());
size_t size = upb_JsonEncode(msg, md.ptr(), NULL, 0, NULL, 0, NULL);
EXPECT_EQ(2, size); // "{}"
}
TEST(Cpp, JsonNull) {
upb::SymbolTable symtab;
upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(symtab.ptr()));
upb::DefPool defpool;
upb::MessageDefPtr md(upb_test_TestMessage_getmsgdef(defpool.ptr()));
upb::FieldDefPtr i32_f = md.FindFieldByName("i32");
upb::FieldDefPtr str_f = md.FindFieldByName("str");
ASSERT_TRUE(i32_f);
@ -152,9 +152,9 @@ TEST(Cpp, JsonNull) {
}
TEST(Cpp, TimestampEncoder) {
upb::SymbolTable symtab;
upb::DefPool defpool;
upb::Arena arena;
upb::MessageDefPtr md(google_protobuf_Timestamp_getmsgdef(symtab.ptr()));
upb::MessageDefPtr md(google_protobuf_Timestamp_getmsgdef(defpool.ptr()));
google_protobuf_Timestamp* timestamp_upb =
google_protobuf_Timestamp_new(arena.ptr());
google_protobuf_Timestamp* timestamp_upb_decoded =

@ -76,13 +76,13 @@ std::unique_ptr<google::protobuf::Message> ToProto(
// A gtest matcher that verifies that a proto is equal to `proto`. Both `proto`
// and `arg` must be messages of type `msgdef_func` (a .upbdefs.h function that
// loads a known msgdef into the given symtab).
// loads a known msgdef into the given defpool).
MATCHER_P2(EqualsUpbProto, proto, msgdef_func,
negation ? "are not equal" : "are equal") {
upb::SymbolTable symtab;
upb::DefPool defpool;
google::protobuf::DescriptorPool pool;
google::protobuf::DynamicMessageFactory factory;
upb::MessageDefPtr msgdef(msgdef_func(symtab.ptr()));
upb::MessageDefPtr msgdef(msgdef_func(defpool.ptr()));
EXPECT_TRUE(msgdef.ptr() != nullptr);
const google::protobuf::Descriptor* desc =
AddMessageDescriptor(msgdef, &pool);
@ -117,13 +117,13 @@ void CheckFile(const upb::FileDefPtr file,
// serialized descriptor -> upb def -> serialized descriptor
TEST(DefToProto, Test) {
upb::Arena arena;
upb::SymbolTable symtab;
upb::DefPool defpool;
upb_StringView test_file_desc =
upb_util_def_to_proto_test_proto_upbdefinit.descriptor;
const auto* file_desc = google_protobuf_FileDescriptorProto_parse(
test_file_desc.data, test_file_desc.size, arena.ptr());
upb::MessageDefPtr msgdef(pkg_Message_getmsgdef(symtab.ptr()));
upb::MessageDefPtr msgdef(pkg_Message_getmsgdef(defpool.ptr()));
upb::FileDefPtr file = msgdef.file();
CheckFile(file, file_desc);
}
@ -131,15 +131,16 @@ TEST(DefToProto, Test) {
// Like the previous test, but uses a message layout built at runtime.
TEST(DefToProto, TestRuntimeReflection) {
upb::Arena arena;
upb::SymbolTable symtab;
upb::DefPool defpool;
upb_StringView test_file_desc =
upb_util_def_to_proto_test_proto_upbdefinit.descriptor;
const auto* file_desc = google_protobuf_FileDescriptorProto_parse(
test_file_desc.data, test_file_desc.size, arena.ptr());
_upb_DefPool_LoadDefInitEx(
symtab.ptr(), &upb_util_def_to_proto_test_proto_upbdefinit, true);
upb::FileDefPtr file = symtab.FindFileByName(
defpool.ptr(),
&upb_util_def_to_proto_test_proto_upbdefinit, true);
upb::FileDefPtr file = defpool.FindFileByName(
upb_util_def_to_proto_test_proto_upbdefinit.filename);
CheckFile(file, file_desc);
}

@ -60,25 +60,25 @@ std::vector<std::string> PathsToText(upb_FieldPathEntry* entry) {
void CheckRequired(absl::string_view json,
const std::vector<std::string>& missing) {
upb::Arena arena;
upb::SymbolTable symtab;
upb::DefPool defpool;
upb_util_test_TestRequiredFields* test_msg =
upb_util_test_TestRequiredFields_new(arena.ptr());
upb::MessageDefPtr m(
upb_util_test_TestRequiredFields_getmsgdef(symtab.ptr()));
upb_util_test_TestRequiredFields_getmsgdef(defpool.ptr()));
upb::Status status;
EXPECT_TRUE(upb_JsonDecode(json.data(), json.size(), test_msg, m.ptr(),
symtab.ptr(), 0, arena.ptr(), status.ptr()))
defpool.ptr(), 0, arena.ptr(), status.ptr()))
<< status.error_message();
upb_FieldPathEntry* entries;
EXPECT_EQ(!missing.empty(), upb_util_HasUnsetRequired(
test_msg, m.ptr(), symtab.ptr(), &entries));
test_msg, m.ptr(), defpool.ptr(), &entries));
EXPECT_EQ(missing, PathsToText(entries));
free(entries);
// Verify that we can pass a NULL pointer to entries when we don't care about
// them.
EXPECT_EQ(!missing.empty(),
upb_util_HasUnsetRequired(test_msg, m.ptr(), symtab.ptr(), NULL));
upb_util_HasUnsetRequired(test_msg, m.ptr(), defpool.ptr(), NULL));
}
// message HasRequiredField {

Loading…
Cancel
Save