upb CopyFrom the default empty message should just clear instead of deep copy

from memory

fix https://github.com/protocolbuffers/protobuf/issues/13485

PiperOrigin-RevId: 559870202
pull/13686/head
Jie Luo 1 year ago committed by Copybara-Service
parent 475ec4c02e
commit 57636ce03a
  1. 15
      python/message.c

@ -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;

Loading…
Cancel
Save