I was working with an exotic architecture where ABSL_CACHELINE_SIZE of abseil was less than 64, so I got a compilation error about redefined symbols. I think the cc file should be adapted to the header file, so here is my change.
Closes#18193
COPYBARA_INTEGRATE_REVIEW=https://github.com/protocolbuffers/protobuf/pull/18193 from jagub2:raw_ptr_fix 4958e0f85e
PiperOrigin-RevId: 676543711
To be able to run this check on protobuf generated sources.
Also changed string_field.cc from using a variable to using
the SuppressWarnings annotation, because that takes less
bytecode.
PiperOrigin-RevId: 676534547
We have been relying on a per-message generated `placement_new` function for
implementing map insertion, but this CL simplifies things by removing that.
Instead, we do a reflective swap if possible, or else fall back on a copy.
This will probably make insertions a bit slower, but I think it may be worth it
because it should make it much simpler to have a blanket implementation for
ProxedInMapValue that works for all map types.
It looks like it should be possible to make this faster in the future by
implementing a bitwise move that will work for any message.
PiperOrigin-RevId: 676495920
The .proto.h is not emitted by default from the cc generator in OSS, rather than try to force it to emit we can just use the .pb.h
PiperOrigin-RevId: 676464651
It's possible to operate on a `Map<K, V>` without necessarily knowing at
compile time what `K` and `V` are. The way to do this is by using
`UntypedMapBase`, which `proto2::Map` inherits from. However, to do anything
useful with the map you need two important bits of information: the size of the
map entry, which is represented as a `std::pair<K, V>`, and the offset of the
value within that. These are combined together into the `MapNodeSizeInfoT`
type.
For Rust to wrap C++ maps, we currently need to store in C++ generated code an
array of `MapNodeSizeInfoT` for each message type. The Rust code has to call
into C++ to ask for the appropriate `MapNodeSizeInfoT` and then pass that back
into C++ for map operations.
Dealing with these message-specific constants is pretty awkward, so this CL
introduces a way around that. By making each message's alignment available
through the `MessageLite*` interface, we make it possible to compute the
necessary size info on the fly, instead of requiring the Rust implementation to
store it in generated code. Luckily the existing padding inside
`MessageCreator` provided enough room to store the alignment. Although this
change is mostly for the benefit of Rust, it doesn't cost C++ anything.
This change doesn't actually simplify the Rust implementation yet, but I will
leave that for a follow-up.
PiperOrigin-RevId: 676456011
`UntypedMapIterator::next_unchecked` currently expects to be passed a pointer
to a C++ function that it can use to dereference an iterator. However, this is
awkward because it's not natural for this C++ function to have the same
signature for every map type. Maps with a message as value need a
`MapNodeSizeInfo`, but other map types do not. We are working around this by
sometimes passing an ignored placeholder constant, but this is messy.
This CL replaces the `extern "C"` functions with closures. This way, we can
capture the `MapNodeSizeInfo` in the closure in cases where we need it, but
otherwise we no longer need to pass around placeholder values.
(Note: `MapNodeSizeInfo` is going away soon, but this is still relevant because
it will likely need to be replaced by a message default instance pointer.)
PiperOrigin-RevId: 676438640
Maps behave in a very interesting way if they are set to be implicit-presence
fields.
They present the possibility that the key or value (or both) can be the default
zero value. When that happens, access to the key or the value is unaffected. In
this case, presence is a bit of a meaningless concept. Zero keys are valid as
map indices, and if a map entry is set to zero, it just always exists.
Reflection is a little weird too.
- If you do reflection on a normal integer field and ask if a zero-valued field
exists, it will tell you that it doesn't exist. This is consistent with what
"implicit presence" means.
- If you do reflection on a zero integer field that happens to be a map key, it
will tell you that it exists. Fetching the value of map[0] is equally valid.
(Note that this is not exactly *intended*, but it's just hard to change... and
this implementation results in simpler gencode.)
I'm adding unit tests in no_field_presence_test to cover this quirk.
PiperOrigin-RevId: 676268392
```
hpb::Arena arena;
auto foo = hpb::CreateMessage<Foo>(arena);
foo.GetInternalArena(); // this call will now be impossible
```
Before this CL, any Proxy/Ptr could get its internal arena. This
unnecessarily leaks upb internals when they should be
interacted with via hpb::interop::upb::*.
PiperOrigin-RevId: 676038573
This is a very narrow edge case where touching a packed extension via generated APIs first, and then doing so reflectively will trigger a DCHECK. Otherwise, reflective APIs will work but not use packed encoding for the extension. This was likely a pre-existing bug dating back to proto3, where it would only be visible on custom options (the only extensions allowed in proto3).
To help qualify this and uncover similar issues, unittest.proto was migrated to editions. This turned up some other minor issues in DebugString and python.
PiperOrigin-RevId: 675785611
This can be used by dynamic messages to validate enums instead of going through
reflection.
This removes one of the few cases where dynamic messages have to fall back to
reflection during table-driven parsing.
PiperOrigin-RevId: 675630939