Skip to content

Commit

Permalink
Propagate aliasing option to parse of unknown fields
Browse files Browse the repository at this point in the history
No implementation hooked up yet.

PiperOrigin-RevId: 698144846
  • Loading branch information
protobuf-github-bot authored and copybara-github committed Nov 19, 2024
1 parent 8a17c53 commit b428e53
Show file tree
Hide file tree
Showing 6 changed files with 11 additions and 9 deletions.
2 changes: 1 addition & 1 deletion upb/message/copy.c
Original file line number Diff line number Diff line change
Expand Up @@ -286,7 +286,7 @@ upb_Message* _upb_Message_Copy(upb_Message* dst, const upb_Message* src,
while (upb_Message_NextUnknown(src, &unknowns, &iter)) {
// Make a copy into destination arena.
if (!UPB_PRIVATE(_upb_Message_AddUnknown)(dst, unknowns.data, unknowns.size,
arena)) {
arena, false)) {
return NULL;
}
}
Expand Down
2 changes: 1 addition & 1 deletion upb/message/copy_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -314,7 +314,7 @@ TEST(GeneratedCode, DeepCloneMessageWithUnknowns) {
std::string unknown_data(data, len);
// Add unknown data.
UPB_PRIVATE(_upb_Message_AddUnknown)
(UPB_UPCAST(msg), data, len, source_arena);
(UPB_UPCAST(msg), data, len, source_arena, false);
// Create clone.
upb_Arena* clone_arena = upb_Arena_New();
protobuf_test_messages_proto2_TestAllTypesProto2* clone =
Expand Down
4 changes: 2 additions & 2 deletions upb/message/internal/compare_unknown_test.cc
Original file line number Diff line number Diff line change
Expand Up @@ -116,9 +116,9 @@ upb_UnknownCompareResult CompareUnknownWithMaxDepth(UnknownFields uf1,
std::string buf1 = ToBinaryPayload(uf1);
std::string buf2 = ToBinaryPayload(uf2);
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(),
buf2.size(), arena2.ptr());
buf2.size(), arena2.ptr(), false);
return UPB_PRIVATE(_upb_Message_UnknownFieldsAreEqual)(
UPB_UPCAST(msg1), UPB_UPCAST(msg2), max_depth);
}
Expand Down
2 changes: 1 addition & 1 deletion upb/message/internal/message.h
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ void _upb_Message_DiscardUnknown_shallow(struct upb_Message* msg);
// The data is copied into the message instance.
bool UPB_PRIVATE(_upb_Message_AddUnknown)(struct upb_Message* msg,
const char* data, size_t len,
upb_Arena* arena);
upb_Arena* arena, bool alias);

// Adds unknown data (serialized protobuf data) to the given message.
// The data is copied into the message instance. Data when concatenated together
Expand Down
3 changes: 2 additions & 1 deletion upb/message/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -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,
size_t len, upb_Arena* arena) {
size_t len, upb_Arena* arena,
bool alias) {
UPB_ASSERT(!upb_Message_IsFrozen(msg));
// TODO: b/376969853 - Add debug check that the unknown field is an overall
// valid proto field
Expand Down
7 changes: 4 additions & 3 deletions upb/wire/decode.c
Original file line number Diff line number Diff line change
Expand Up @@ -402,7 +402,7 @@ bool _upb_Decoder_CheckEnum(upb_Decoder* d, const char* ptr, upb_Message* msg,
end = upb_Decoder_EncodeVarint32(v, end);

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

0 comments on commit b428e53

Please sign in to comment.