From 32f28fcdc6a028955dceb2a09eddc9a3bd82ff6c Mon Sep 17 00:00:00 2001 From: Eric Salo Date: Sat, 26 Nov 2022 17:35:48 -0800 Subject: [PATCH] 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 --- upb/fuzz_test_util.cc | 6 ++---- upb/message/accessors_test.cc | 3 +-- upb/mini_table/decode.c | 6 +++--- upb/mini_table/decode.h | 13 ++++++++++--- upb/mini_table/encode_test.cc | 20 ++++++++++---------- upbc/file_layout.cc | 12 ++++++------ 6 files changed, 32 insertions(+), 28 deletions(-) diff --git a/upb/fuzz_test_util.cc b/upb/fuzz_test_util.cc index 02f3f39c2e..6963efdad2 100644 --- a/upb/fuzz_test_util.cc +++ b/upb/fuzz_test_util.cc @@ -87,10 +87,8 @@ void Builder::BuildMessages() { upb::Status status; mini_tables_.reserve(input_->mini_descriptors.size()); for (const auto& d : input_->mini_descriptors) { - upb_MiniTable* table; - table = - upb_MiniTable_Build(d.data(), d.size(), kUpb_MiniTablePlatform_Native, - arena_, status.ptr()); + upb_MiniTable* table = + upb_MiniTable_Build(d.data(), d.size(), arena_, status.ptr()); if (table) mini_tables_.push_back(table); } } diff --git a/upb/message/accessors_test.cc b/upb/message/accessors_test.cc index a36e0da7ec..fcc4bf2e5a 100644 --- a/upb/message/accessors_test.cc +++ b/upb/message/accessors_test.cc @@ -569,8 +569,7 @@ upb_MiniTable* CreateMiniTableWithEmptySubTables(upb_Arena* arena) { upb_Status status; upb_Status_Clear(&status); upb_MiniTable* table = - upb_MiniTable_Build(e.data().data(), e.data().size(), - kUpb_MiniTablePlatform_Native, arena, &status); + upb_MiniTable_Build(e.data().data(), e.data().size(), arena, &status); EXPECT_EQ(status.ok, true); // Initialize sub table to null. Not using upb_MiniTable_SetSubMessage // since it checks ->ext on parameter. diff --git a/upb/mini_table/decode.c b/upb/mini_table/decode.c index e66716b206..ab798fba2a 100644 --- a/upb/mini_table/decode.c +++ b/upb/mini_table/decode.c @@ -930,9 +930,9 @@ const char* _upb_MiniTableExtension_Build(const char* data, size_t len, return ret; } -upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len, - upb_MiniTablePlatform platform, - upb_Arena* arena, upb_Status* status) { +upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len, + upb_MiniTablePlatform platform, + upb_Arena* arena, upb_Status* status) { void* buf = NULL; size_t size = 0; upb_MiniTable* ret = upb_MiniTable_BuildWithBuf(data, len, platform, arena, diff --git a/upb/mini_table/decode.h b/upb/mini_table/decode.h index 4587d32cf6..f7219d4406 100644 --- a/upb/mini_table/decode.h +++ b/upb/mini_table/decode.h @@ -50,9 +50,16 @@ extern "C" { // 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 // fields to link the table to the appropriate sub-tables. -upb_MiniTable* upb_MiniTable_Build(const char* data, size_t len, - upb_MiniTablePlatform platform, - upb_Arena* arena, upb_Status* status); +upb_MiniTable* _upb_MiniTable_Build(const char* data, size_t len, + upb_MiniTablePlatform platform, + 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 // sub-message field is not linked, it will be treated as an unknown field diff --git a/upb/mini_table/encode_test.cc b/upb/mini_table/encode_test.cc index d18523eab1..b53584fb9a 100644 --- a/upb/mini_table/encode_test.cc +++ b/upb/mini_table/encode_test.cc @@ -49,7 +49,7 @@ TEST_P(MiniTableTest, Empty) { upb::Arena arena; upb::Status status; 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); EXPECT_EQ(0, table->field_count); EXPECT_EQ(0, table->required_count); @@ -65,7 +65,7 @@ TEST_P(MiniTableTest, AllScalarTypes) { count++; } 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()); ASSERT_NE(nullptr, table); EXPECT_EQ(count, table->field_count); @@ -91,7 +91,7 @@ TEST_P(MiniTableTest, AllRepeatedTypes) { count++; } 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()); ASSERT_NE(nullptr, table); EXPECT_EQ(count, table->field_count); @@ -119,7 +119,7 @@ TEST_P(MiniTableTest, Skips) { count++; } 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()); ASSERT_NE(nullptr, table); EXPECT_EQ(count, table->field_count); @@ -149,7 +149,7 @@ TEST_P(MiniTableTest, AllScalarTypesOneof) { ASSERT_TRUE(e.PutOneofField(i)); } 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()); ASSERT_NE(nullptr, table) << status.error_message(); EXPECT_EQ(count, table->field_count); @@ -182,7 +182,7 @@ TEST_P(MiniTableTest, SizeOverflow) { ASSERT_TRUE(e.PutField(kUpb_FieldType_Double, i, 0)); } 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()); 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++) { 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()); 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, 16, 0)); 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()); ASSERT_NE(nullptr, table); EXPECT_EQ(table->field_count, 2); @@ -288,7 +288,7 @@ TEST_P(MiniTableTest, Extendible) { count++; } 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()); ASSERT_NE(nullptr, table); 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) { // upb::Arena arena; // upb::Status status; -// upb_MiniTable_Build( +// _upb_MiniTable_Build( // s.data(), s.size(), // is_32bit ? kUpb_MiniTablePlatform_32Bit : kUpb_MiniTablePlatform_64Bit, // arena.ptr(), status.ptr()); diff --git a/upbc/file_layout.cc b/upbc/file_layout.cc index 361a72a805..8535f4691e 100644 --- a/upbc/file_layout.cc +++ b/upbc/file_layout.cc @@ -306,8 +306,8 @@ upb_MiniTable* FilePlatformLayout::MakeMapMiniTable( const absl::string_view str = e.data(); upb::Status status; - upb_MiniTable* ret = upb_MiniTable_Build(str.data(), str.size(), platform_, - arena_.ptr(), status.ptr()); + upb_MiniTable* ret = _upb_MiniTable_Build(str.data(), str.size(), platform_, + arena_.ptr(), status.ptr()); if (!ret) { 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(); upb::Status status; - upb_MiniTable* ret = upb_MiniTable_Build(str.data(), str.size(), platform_, - arena_.ptr(), status.ptr()); + upb_MiniTable* ret = _upb_MiniTable_Build(str.data(), str.size(), platform_, + arena_.ptr(), status.ptr()); if (!ret) { 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(); upb::Status status; - upb_MiniTable* ret = upb_MiniTable_Build(str.data(), str.size(), platform_, - arena_.ptr(), status.ptr()); + upb_MiniTable* ret = _upb_MiniTable_Build(str.data(), str.size(), platform_, + arena_.ptr(), status.ptr()); if (!ret) { fprintf(stderr, "Error building mini-table: %s\n", status.error_message()); }