Skip to content

Commit

Permalink
upb CopyFrom the default empty message should just clear instead of d…
Browse files Browse the repository at this point in the history
…eep copy

from memory

fix protocolbuffers/protobuf#13485

PiperOrigin-RevId: 559643466
  • Loading branch information
anandolee authored and copybara-github committed Aug 24, 2023
1 parent 475ec4c commit e76d827
Showing 1 changed file with 9 additions and 6 deletions.
15 changes: 9 additions & 6 deletions python/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -1237,12 +1237,15 @@ static PyObject* PyUpb_Message_CopyFrom(PyObject* _self, PyObject* arg) {
PyUpb_Message* other = (void*)arg;
PyUpb_Message_EnsureReified(self);

PyObject* tmp = PyUpb_Message_Clear(self);
Py_DECREF(tmp);

upb_Message_DeepCopy(self->ptr.msg, other->ptr.msg,
upb_MessageDef_MiniTable(other->def),
PyUpb_Arena_Get(self->arena));
const upb_Message* other_msg = PyUpb_Message_GetIfReified((PyObject*)other);
if (other_msg) {
upb_Message_DeepCopy(self->ptr.msg, other_msg,
upb_MessageDef_MiniTable(other->def),
PyUpb_Arena_Get(self->arena));
} else {
PyObject* tmp = PyUpb_Message_Clear(self);
Py_DECREF(tmp);
}
PyUpb_Message_SyncSubobjs(self);

Py_RETURN_NONE;
Expand Down

0 comments on commit e76d827

Please sign in to comment.