Propagate aliasing option to parse of unknown fields

No implementation hooked up yet.

PiperOrigin-RevId: 698144846
pull/19287/head
Protobuf Team Bot 1 week ago committed by Copybara-Service
parent 8a17c53a5c
commit b428e53016
  1. 2
      upb/message/copy.c
  2. 2
      upb/message/copy_test.cc
  3. 4
      upb/message/internal/compare_unknown_test.cc
  4. 2
      upb/message/internal/message.h
  5. 3
      upb/message/message.c
  6. 7
      upb/wire/decode.c

@ -286,7 +286,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
while (upb_Message_NextUnknown(src, &unknowns, &iter)) { while (upb_Message_NextUnknown(src, &unknowns, &iter)) {
// Make a copy into destination arena. // Make a copy into destination arena.
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, unknowns.data, unknowns.size, if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, unknowns.data, unknowns.size,
arena)) { arena, false)) {
return NULL; return NULL;
} }
} }

@ -314,7 +314,7 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) {
std::string unknown_data(data, len); std::string unknown_data(data, len);
// Add unknown data. // Add unknown data.
UPB_PRIVATE(_upb_Message_AddUnknown) UPB_PRIVATE(_upb_Message_AddUnknown)
(UPB_UPCAST(msg), data, len, source_arena); (UPB_UPCAST(msg), data, len, source_arena, false);
// Create clone. // Create clone.
upb_Arena* clone_arena = upb_Arena_New(); upb_Arena* clone_arena = upb_Arena_New();
protobuf_test_messages_proto2_TestAllTypesProto2* clone = protobuf_test_messages_proto2_TestAllTypesProto2* clone =

@ -116,9 +116,9 @@ upb_UnknownCompareResult CompareUnknownWithMaxDepth(UnknownFields uf1,
std::string buf1 = ToBinaryPayload(uf1); std::string buf1 = ToBinaryPayload(uf1);
std::string buf2 = ToBinaryPayload(uf2); std::string buf2 = ToBinaryPayload(uf2);
UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(msg1), buf1.data(), UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(msg1), buf1.data(),
buf1.size(), arena1.ptr()); buf1.size(), arena1.ptr(), false);
UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(msg2), buf2.data(), UPB_PRIVATE(_upb_Message_AddUnknown)(UPB_UPCAST(msg2), buf2.data(),
buf2.size(), arena2.ptr()); buf2.size(), arena2.ptr(), false);
return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)( return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
UPB_UPCAST(msg1), UPB_UPCAST(msg2), max_depth); UPB_UPCAST(msg1), UPB_UPCAST(msg2), max_depth);
} }

@ -88,7 +88,7 @@ void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg);
// The data is copied into the message instance. // The data is copied into the message instance.
bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg, bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg,
const char* data, size_t len, const char* data, size_t len,
upb_Arena* arena); upb_Arena* arena, bool alias);
// Adds unknown data (serialized protobuf data) to the given message. // Adds unknown data (serialized protobuf data) to the given message.
// The data is copied into the message instance. Data when concatenated together // The data is copied into the message instance. Data when concatenated together

@ -37,7 +37,8 @@ upb_Message* upb_Message_New(const upb_MiniTable* m, upb_Arena* a) {
} }
bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data, bool UPB_PRIVATE(_upb_Message_AddUnknown)(upb_Message* msg, const char* data,
size_t len, upb_Arena* arena) { size_t len, upb_Arena* arena,
bool alias) {
UPB_ASSERT(!upb_Message_IsFrozen(msg)); UPB_ASSERT(!upb_Message_IsFrozen(msg));
// TODO: b/376969853 - Add debug check that the unknown field is an overall // TODO: b/376969853 - Add debug check that the unknown field is an overall
// valid proto field // valid proto field

@ -402,7 +402,7 @@ bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, upb_Message* msg,
end = upb_Decoder_EncodeVarint32(v, end); end = upb_Decoder_EncodeVarint32(v, end);
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(unknown_msg, buf, end - buf, if (!UPB_PRIVATE(_upb_Message_AddUnknown)(unknown_msg, buf, end - buf,
&d->arena)) { &d->arena, false)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
} }
return false; return false;
@ -1265,8 +1265,9 @@ static const char* _upb_Decoder_DecodeUnknownField(upb_Decoder* d,
// bounds checks are needed before adding the unknown field. // bounds checks are needed before adding the unknown field.
_upb_Decoder_IsDone(d, &ptr); _upb_Decoder_IsDone(d, &ptr);
const char* input_ptr = upb_EpsCopyInputStream_GetInputPtr(&d->input, ptr); const char* input_ptr = upb_EpsCopyInputStream_GetInputPtr(&d->input, ptr);
if (!UPB_PRIVATE(_upb_Message_AddUnknown)( if (!UPB_PRIVATE(_upb_Message_AddUnknown)(msg, input_start,
msg, input_start, input_ptr - input_start, &d->arena)) { input_ptr - input_start,
&d->arena, d->input.aliasing)) {
_upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory); _upb_Decoder_ErrorJmp(d, kUpb_DecodeStatus_OutOfMemory);
} }
} else if (wire_type == kUpb_WireType_StartGroup) { } else if (wire_type == kUpb_WireType_StartGroup) {

Loading…
Cancel
Save