Groups keyboard shortcuts have been updated
Dismiss
See shortcuts

Help to figure out meaning of assert

56 views
Skip to first unread message

Vanegicloh J

unread,
Apr 3, 2025, 10:44:03 AMApr 3
to Protocol Buffers
Hello. I'm trying to use arena in protobuf with C++ but keep getting weird assertion fail. I create std::array<char, 1024> on the stack and pass it to the arena as the initial block like this:
google::protobuf::Arena m_arena{arenaBuf.data(), arenaBuf.size()}.

During arena construction i get "CHECK failed: (reinterpret_cast<uintptr_t>(mem) & 7) == (0u)". Could you please help me to figure out what does it mean? What should i do to fix it?

P.s. it's very weird because only in 1 test file this assert fails. I do the same everywhere in the project, but only 1 test doesn't want to run and fails with this assert.

Also, we got some old protobuf code. Not one that in github master. The function with weird assert is this:

void ThreadSafeArena::InitializeFrom(void* mem, size_t size)
{
GOOGLE_DCHECK_EQ(reinterpret_cast<uintptr_t>(mem) & 7, 0u);
GOOGLE_DCHECK(!AllocPolicy());
// Reset should call InitializeWithPolicy instead. Init();
// Ignore initial block if it is too small.
if (mem != nullptr && size >= kBlockHeaderSize + kSerialArenaSize) 
{ 
alloc_policy_.set_is_user_owned_initial_block(true); SetInitialBlock(mem, size); 
}
}

Samuel Benzaquen

unread,
Apr 3, 2025, 10:48:57 AMApr 3
to Vanegicloh J, Protocol Buffers
On Thu, Apr 3, 2025 at 10:44 AM Vanegicloh J <vaneg...@gmail.com> wrote:
Hello. I'm trying to use arena in protobuf with C++ but keep getting weird assertion fail. I create std::array<char, 1024> on the stack and pass it to the arena as the initial block like this:
google::protobuf::Arena m_arena{arenaBuf.data(), arenaBuf.size()}.

During arena construction i get "CHECK failed: (reinterpret_cast<uintptr_t>(mem) & 7) == (0u)". Could you please help me to figure out what does it mean? What should i do to fix it?

The buffer is not properly aligned.
The arena requires the provided input buffer to be at least 8-byte aligned.
You can solve this by declaring your variable with `alignas(8)`, or use a type that is already aligned.
 

P.s. it's very weird because only in 1 test file this assert fails. I do the same everywhere in the project, but only 1 test doesn't want to run and fails with this assert.

Also, we got some old protobuf code. Not one that in github master. The function with weird assert is this:

void ThreadSafeArena::InitializeFrom(void* mem, size_t size)
{
GOOGLE_DCHECK_EQ(reinterpret_cast<uintptr_t>(mem) & 7, 0u);
GOOGLE_DCHECK(!AllocPolicy());
// Reset should call InitializeWithPolicy instead. Init();
// Ignore initial block if it is too small.
if (mem != nullptr && size >= kBlockHeaderSize + kSerialArenaSize) 
{ 
alloc_policy_.set_is_user_owned_initial_block(true); SetInitialBlock(mem, size); 
}
}

--
You received this message because you are subscribed to the Google Groups "Protocol Buffers" group.
To unsubscribe from this group and stop receiving emails from it, send an email to protobuf+u...@googlegroups.com.
To view this discussion visit https://groups.google.com/d/msgid/protobuf/343c244e-55f5-4c24-ad9d-5951179a2640n%40googlegroups.com.
Reply all
Reply to author
Forward
0 new messages