On Thu, Apr 3, 2025 at 10:44 AM Vanegicloh J <[email protected]> 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 [email protected].
> To view this discussion visit
> https://groups.google.com/d/msgid/protobuf/343c244e-55f5-4c24-ad9d-5951179a2640n%40googlegroups.com
> <https://groups.google.com/d/msgid/protobuf/343c244e-55f5-4c24-ad9d-5951179a2640n%40googlegroups.com?utm_medium=email&utm_source=footer>
> .
>
--
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 [email protected].
To view this discussion visit
https://groups.google.com/d/msgid/protobuf/CAM9aRsJrm0-6qkc-XNZNMgHSD9VgkTEa3BJOJJaxk%2BrQXb2sjA%40mail.gmail.com.