Skip to content

Commit

Permalink
fix version for protobuf 27.x
Browse files Browse the repository at this point in the history
  • Loading branch information
oathdruid committed Jun 22, 2024
1 parent 36e6001 commit e672c28
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 17 deletions.
28 changes: 14 additions & 14 deletions test/reusable/test_memory_resource.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -338,11 +338,11 @@ TEST(SwissMemoryResource, compatible_with_protobuf_in_asan_mode) {
SwissMemoryResource resource(page_heap);
for (int j = 0; j < 10; ++j) {
Arena& arena = resource;
#if GOOGLE_PROTOBUF_VERSION >= 4260000
auto message = Arena::Create<ArenaExample>(&arena);
#else // GOOGLE_PROTOBUF_VERSION < 4260000
auto message = Arena::CreateMessage<ArenaExample>(&arena);
#endif // GOOGLE_PROTOBUF_VERSION < 4260000
#if GOOGLE_PROTOBUF_VERSION >= 5026000
auto message = Arena::Create<ArenaExample>(&arena);
#else // GOOGLE_PROTOBUF_VERSION < 5026000
auto message = Arena::CreateMessage<ArenaExample>(&arena);
#endif // GOOGLE_PROTOBUF_VERSION < 5026000
// 反复reserve会触发protobuf 4.x的重用功能
// 内部有对应的asan poison标记动作
// 验证和MemoryResource的标记可兼容
Expand Down Expand Up @@ -427,11 +427,11 @@ TEST(memory_resource, can_use_as_arena_with_protobuf) {
resource.allocate<1>(128);
auto* ptr_in_resource = (char*)resource.allocate<1>(128);
Arena& arena = resource;
#if GOOGLE_PROTOBUF_VERSION >= 4260000
#if GOOGLE_PROTOBUF_VERSION >= 5026000
auto message = Arena::Create<ArenaExample>(&arena);
#else // GOOGLE_PROTOBUF_VERSION < 4260000
#else // GOOGLE_PROTOBUF_VERSION < 5026000
auto message = Arena::CreateMessage<ArenaExample>(&arena);
#endif // GOOGLE_PROTOBUF_VERSION < 4260000
#endif // GOOGLE_PROTOBUF_VERSION < 5026000
for (size_t i = 0; i < 1024; ++i) {
message->add_rs("10086");
message->add_rp(10086);
Expand Down Expand Up @@ -484,11 +484,11 @@ TEST(memory_resource, release_also_clear_arena) {
resource.allocate<1>(128);
auto* ptr_in_resource = (char*)resource.allocate<1>(128);
Arena& arena = resource;
#if GOOGLE_PROTOBUF_VERSION >= 4260000
#if GOOGLE_PROTOBUF_VERSION >= 5026000
auto message = Arena::Create<ArenaExample>(&arena);
#else // GOOGLE_PROTOBUF_VERSION < 4260000
#else // GOOGLE_PROTOBUF_VERSION < 5026000
auto message = Arena::CreateMessage<ArenaExample>(&arena);
#endif // GOOGLE_PROTOBUF_VERSION < 4260000
#endif // GOOGLE_PROTOBUF_VERSION < 5026000
ASSERT_EQ(&arena, message->GetArena());
ASSERT_EQ(&arena, message->mutable_m()->GetArena());
ASSERT_LE(ptr_in_resource + 128, (char*)message);
Expand All @@ -500,11 +500,11 @@ TEST(memory_resource, release_also_clear_arena) {
resource.allocate<1>(128);
auto* ptr_in_resource = (char*)resource.allocate<1>(128);
Arena& arena = resource;
#if GOOGLE_PROTOBUF_VERSION >= 4260000
#if GOOGLE_PROTOBUF_VERSION >= 5026000
auto message = Arena::Create<ArenaExample>(&arena);
#else // GOOGLE_PROTOBUF_VERSION < 4260000
#else // GOOGLE_PROTOBUF_VERSION < 5026000
auto message = Arena::CreateMessage<ArenaExample>(&arena);
#endif // GOOGLE_PROTOBUF_VERSION < 4260000
#endif // GOOGLE_PROTOBUF_VERSION < 5026000
ASSERT_EQ(&arena, message->GetArena());
ASSERT_EQ(&arena, message->mutable_m()->GetArena());
ASSERT_LE(ptr_in_resource + 128, (char*)message);
Expand Down
6 changes: 3 additions & 3 deletions test/reusable/test_message.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -181,11 +181,11 @@ TEST_F(ReusableMessage,
auto message = manager.create_object<Message>(
[](::babylon::SwissMemoryResource& resource) {
Arena& arena = resource;
#if GOOGLE_PROTOBUF_VERSION >= 4260000
#if GOOGLE_PROTOBUF_VERSION >= 5026000
Message* result = Arena::Create<ArenaExample>(&arena);
#else // GOOGLE_PROTOBUF_VERSION < 4260000
#else // GOOGLE_PROTOBUF_VERSION < 5026000
Message* result = Arena::CreateMessage<ArenaExample>(&arena);
#endif // GOOGLE_PROTOBUF_VERSION < 4260000
#endif // GOOGLE_PROTOBUF_VERSION < 5026000
return result;
});
auto pmessage = static_cast<ArenaExample*>(message.get());
Expand Down

0 comments on commit e672c28

Please sign in to comment.