Support non-canonical extensions in Python upb unknown fields.

PiperOrigin-RevId: 970866648
This commit is contained in:
Protobuf Team Bot 2026-08-25 16:17:54 -07:00 committed by Copybara-Service
parent 67322442bd
commit b6ca8b9fb1
2 changed files with 8 additions and 1 deletions

View file

@ -124,6 +124,7 @@ py_extension(
"//upb/message",
"//upb/message:compare",
"//upb/message:copy",
"//upb/message:message_unknowns",
"//upb/mini_table",
"//upb/port",
"//upb/reflection",
@ -131,6 +132,7 @@ py_extension(
"//upb/util:def_to_proto",
"//upb/util:required_fields",
"//upb/wire",
"//upb/wire:encode_extension",
"//upb/wire:eps_copy_input_stream",
"//upb/wire:reader",
"@abseil-cpp//absl/base:core_headers",

View file

@ -13,7 +13,9 @@
#include "python/message.h"
#include "python/protobuf.h"
#include "upb/base/string_view.h"
#include "upb/mem/arena.h"
#include "upb/message/message.h"
#include "upb/message/unknown_fields.h"
#include "upb/reflection/def.h"
#include "upb/wire/eps_copy_input_stream.h"
#include "upb/wire/reader.h"
@ -266,7 +268,8 @@ static PyObject* PyUpb_UnknownFieldSet_New(PyTypeObject* type, PyObject* args,
uintptr_t iter = kUpb_Message_UnknownBegin;
upb_StringView view;
while (upb_Message_NextUnknown(msg, &view, &iter)) {
upb_Arena* upb_arena = NULL;
while (upb_Message_NextWireFormatUnknown(msg, &upb_arena, &view, &iter)) {
const char* ptr = view.data;
upb_EpsCopyInputStream stream;
upb_EpsCopyInputStream_Init(&stream, &ptr, view.size);
@ -280,11 +283,13 @@ static PyObject* PyUpb_UnknownFieldSet_New(PyTypeObject* type, PyObject* args,
}
if (!ok) {
if (upb_arena) upb_Arena_Free(upb_arena);
Py_DECREF(&self->ob_base);
return NULL;
}
}
if (upb_arena) upb_Arena_Free(upb_arena);
return &self->ob_base;
}