remove 'platform' param from upb_MiniTable_Build()

_upb_MiniTable_Build() is now the general version of the function;
upb_MiniTable_Build() calls it and sets the platform to default/native.

PiperOrigin-RevId: 491091021
pull/13171/head
Eric Salo 2 years ago committed by Copybara-Service
parent 0a2c988286
commit 32f28fcdc6
  1. 6
      upb/fuzz_test_util.cc
  2. 3
      upb/message/accessors_test.cc
  3. 6
      upb/mini_table/decode.c
  4. 13
      upb/mini_table/decode.h
  5. 20
      upb/mini_table/encode_test.cc
  6. 12
      upbc/file_layout.cc

@ -87,10 +87,8 @@ void Builder::BuildMessages() {
upb::Status status; upb::Status status;
mini_tables_.reserve(input_->mini_descriptors.size()); mini_tables_.reserve(input_->mini_descriptors.size());
for (const auto& d : input_->mini_descriptors) { for (const auto& d : input_->mini_descriptors) {
upb_MiniTable* table; upb_MiniTable* table =
table = upb_MiniTable_Build(d.data(), d.size(), arena_, status.ptr());
upb_MiniTable_Build(d.data(), d.size(), kUpb_MiniTablePlatform_Native,
arena_, status.ptr());
if (table) mini_tables_.push_back(table); if (table) mini_tables_.push_back(table);
} }
} }

@ -569,8 +569,7 @@ upb_MiniTable* CreateMiniTableWithEmptySubTables(upb_Arena* arena) {
upb_Status status; upb_Status status;
upb_Status_Clear(&status); upb_Status_Clear(&status);
upb_MiniTable* table = upb_MiniTable* table =
upb_MiniTable_Build(e.data().data(), e.data().size(), upb_MiniTable_Build(e.data().data(), e.data().size(), arena, &status);
kUpb_MiniTablePlatform_Native, arena, &status);
EXPECT_EQ(status.ok, true); EXPECT_EQ(status.ok, true);
// Initialize sub table to null. Not using upb_MiniTable_SetSubMessage // Initialize sub table to null. Not using upb_MiniTable_SetSubMessage
// since it checks ->ext on parameter. // since it checks ->ext on parameter.

@ -930,9 +930,9 @@ const char* _upb_MiniTableExtension_Build(const char* data, size_t len,
return ret; return ret;
} }
upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len, upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len,
upb_MiniTablePlatform platform, upb_MiniTablePlatform platform,
upb_Arena* arena, upb_Status* status) { upb_Arena* arena, upb_Status* status) {
void* buf = NULL; void* buf = NULL;
size_t size = 0; size_t size = 0;
upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena, upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena,

@ -50,9 +50,16 @@ extern "C" {
// errors occur, returns NULL and sets a status message. In the success case, // errors occur, returns NULL and sets a status message. In the success case,
// the caller must call upb_MiniTable_SetSub*() for all message or proto2 enum // the caller must call upb_MiniTable_SetSub*() for all message or proto2 enum
// fields to link the table to the appropriate sub-tables. // fields to link the table to the appropriate sub-tables.
upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len, upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len,
upb_MiniTablePlatform platform, upb_MiniTablePlatform platform,
upb_Arena* arena, upb_Status* status); upb_Arena* arena, upb_Status* status);
UPB_INLINE upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len,
upb_Arena* arena,
upb_Status* status) {
return _upb_MiniTable_Build(data, len, kUpb_MiniTablePlatform_Native, arena,
status);
}
// Links a sub-message field to a MiniTable for that sub-message. If a // Links a sub-message field to a MiniTable for that sub-message. If a
// sub-message field is not linked, it will be treated as an unknown field // sub-message field is not linked, it will be treated as an unknown field

@ -49,7 +49,7 @@ TEST_P(MiniTableTest, Empty) {
upb::Arena arena; upb::Arena arena;
upb::Status status; upb::Status status;
upb_MiniTable* table = upb_MiniTable* table =
upb_MiniTable_Build(NULL, 0, GetParam(), arena.ptr(), status.ptr()); _upb_MiniTable_Build(NULL, 0, GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table); ASSERT_NE(nullptr, table);
EXPECT_EQ(0, table->field_count); EXPECT_EQ(0, table->field_count);
EXPECT_EQ(0, table->required_count); EXPECT_EQ(0, table->required_count);
@ -65,7 +65,7 @@ TEST_P(MiniTableTest, AllScalarTypes) {
count++; count++;
} }
upb::Status status; upb::Status status;
upb_MiniTable* table = upb_MiniTable_Build( upb_MiniTable* table = _upb_MiniTable_Build(
e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table); ASSERT_NE(nullptr, table);
EXPECT_EQ(count, table->field_count); EXPECT_EQ(count, table->field_count);
@ -91,7 +91,7 @@ TEST_P(MiniTableTest, AllRepeatedTypes) {
count++; count++;
} }
upb::Status status; upb::Status status;
upb_MiniTable* table = upb_MiniTable_Build( upb_MiniTable* table = _upb_MiniTable_Build(
e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table); ASSERT_NE(nullptr, table);
EXPECT_EQ(count, table->field_count); EXPECT_EQ(count, table->field_count);
@ -119,7 +119,7 @@ TEST_P(MiniTableTest, Skips) {
count++; count++;
} }
upb::Status status; upb::Status status;
upb_MiniTable* table = upb_MiniTable_Build( upb_MiniTable* table = _upb_MiniTable_Build(
e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table); ASSERT_NE(nullptr, table);
EXPECT_EQ(count, table->field_count); EXPECT_EQ(count, table->field_count);
@ -149,7 +149,7 @@ TEST_P(MiniTableTest, AllScalarTypesOneof) {
ASSERT_TRUE(e.PutOneofField(i)); ASSERT_TRUE(e.PutOneofField(i));
} }
upb::Status status; upb::Status status;
upb_MiniTable* table = upb_MiniTable_Build( upb_MiniTable* table = _upb_MiniTable_Build(
e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table) << status.error_message(); ASSERT_NE(nullptr, table) << status.error_message();
EXPECT_EQ(count, table->field_count); EXPECT_EQ(count, table->field_count);
@ -182,7 +182,7 @@ TEST_P(MiniTableTest, SizeOverflow) {
ASSERT_TRUE(e.PutField(kUpb_FieldType_Double, i, 0)); ASSERT_TRUE(e.PutField(kUpb_FieldType_Double, i, 0));
} }
upb::Status status; upb::Status status;
upb_MiniTable* table = upb_MiniTable_Build( upb_MiniTable* table = _upb_MiniTable_Build(
e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table) << status.error_message(); ASSERT_NE(nullptr, table) << status.error_message();
@ -191,7 +191,7 @@ TEST_P(MiniTableTest, SizeOverflow) {
for (size_t i = 1; i < max_double_fields + 2; i++) { for (size_t i = 1; i < max_double_fields + 2; i++) {
ASSERT_TRUE(e.PutField(kUpb_FieldType_Double, i, 0)); ASSERT_TRUE(e.PutField(kUpb_FieldType_Double, i, 0));
} }
upb_MiniTable* table2 = upb_MiniTable_Build( upb_MiniTable* table2 = _upb_MiniTable_Build(
e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr());
ASSERT_EQ(nullptr, table2) << status.error_message(); ASSERT_EQ(nullptr, table2) << status.error_message();
} }
@ -244,7 +244,7 @@ TEST_P(MiniTableTest, SubsInitializedToNull) {
ASSERT_TRUE(e.PutField(kUpb_FieldType_Message, 15, 0)); ASSERT_TRUE(e.PutField(kUpb_FieldType_Message, 15, 0));
ASSERT_TRUE(e.PutField(kUpb_FieldType_Message, 16, 0)); ASSERT_TRUE(e.PutField(kUpb_FieldType_Message, 16, 0));
upb::Status status; upb::Status status;
upb_MiniTable* table = upb_MiniTable_Build( upb_MiniTable* table = _upb_MiniTable_Build(
e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table); ASSERT_NE(nullptr, table);
EXPECT_EQ(table->field_count, 2); EXPECT_EQ(table->field_count, 2);
@ -288,7 +288,7 @@ TEST_P(MiniTableTest, Extendible) {
count++; count++;
} }
upb::Status status; upb::Status status;
upb_MiniTable* table = upb_MiniTable_Build( upb_MiniTable* table = _upb_MiniTable_Build(
e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr()); e.data().data(), e.data().size(), GetParam(), arena.ptr(), status.ptr());
ASSERT_NE(nullptr, table); ASSERT_NE(nullptr, table);
EXPECT_EQ(kUpb_ExtMode_Extendable, table->ext & kUpb_ExtMode_Extendable); EXPECT_EQ(kUpb_ExtMode_Extendable, table->ext & kUpb_ExtMode_Extendable);
@ -299,7 +299,7 @@ TEST_P(MiniTableTest, Extendible) {
// static void BuildMiniTable(std::string_view s, bool is_32bit) { // static void BuildMiniTable(std::string_view s, bool is_32bit) {
// upb::Arena arena; // upb::Arena arena;
// upb::Status status; // upb::Status status;
// upb_MiniTable_Build( // _upb_MiniTable_Build(
// s.data(), s.size(), // s.data(), s.size(),
// is_32bit ? kUpb_MiniTablePlatform_32Bit : kUpb_MiniTablePlatform_64Bit, // is_32bit ? kUpb_MiniTablePlatform_32Bit : kUpb_MiniTablePlatform_64Bit,
// arena.ptr(), status.ptr()); // arena.ptr(), status.ptr());

@ -306,8 +306,8 @@ upb_MiniTable* FilePlatformLayout::MakeMapMiniTable(
const absl::string_view str = e.data(); const absl::string_view str = e.data();
upb::Status status; upb::Status status;
upb_MiniTable* ret = upb_MiniTable_Build(str.data(), str.size(), platform_, upb_MiniTable* ret = _upb_MiniTable_Build(str.data(), str.size(), platform_,
arena_.ptr(), status.ptr()); arena_.ptr(), status.ptr());
if (!ret) { if (!ret) {
fprintf(stderr, "Error building mini-table: %s\n", status.error_message()); fprintf(stderr, "Error building mini-table: %s\n", status.error_message());
} }
@ -322,8 +322,8 @@ upb_MiniTable* FilePlatformLayout::MakeMessageSetMiniTable(
const absl::string_view str = e.data(); const absl::string_view str = e.data();
upb::Status status; upb::Status status;
upb_MiniTable* ret = upb_MiniTable_Build(str.data(), str.size(), platform_, upb_MiniTable* ret = _upb_MiniTable_Build(str.data(), str.size(), platform_,
arena_.ptr(), status.ptr()); arena_.ptr(), status.ptr());
if (!ret) { if (!ret) {
fprintf(stderr, "Error building mini-table: %s\n", status.error_message()); fprintf(stderr, "Error building mini-table: %s\n", status.error_message());
} }
@ -349,8 +349,8 @@ upb_MiniTable* FilePlatformLayout::MakeRegularMiniTable(
} }
absl::string_view str = e.data(); absl::string_view str = e.data();
upb::Status status; upb::Status status;
upb_MiniTable* ret = upb_MiniTable_Build(str.data(), str.size(), platform_, upb_MiniTable* ret = _upb_MiniTable_Build(str.data(), str.size(), platform_,
arena_.ptr(), status.ptr()); arena_.ptr(), status.ptr());
if (!ret) { if (!ret) {
fprintf(stderr, "Error building mini-table: %s\n", status.error_message()); fprintf(stderr, "Error building mini-table: %s\n", status.error_message());
} }

Loading…
Cancel
Save