-Make message __deepcopy__ call UPB code instead of default implementation for

python UPB (splitted change 2)

PiperOrigin-RevId: 528614850
pull/13171/head
Jie Luo 2 years ago committed by Copybara-Service
parent 2282505327
commit 60be96e0bf
  1. 4
      bazel/workspace_deps.bzl
  2. 17
      python/message.c

@ -23,8 +23,8 @@ def upb_deps():
_github_archive, _github_archive,
name = "com_google_protobuf", name = "com_google_protobuf",
repo = "https://github.com/protocolbuffers/protobuf", repo = "https://github.com/protocolbuffers/protobuf",
commit = "e202f31b78a9189fbebe25c3cae8e7a1733d6316", commit = "65e047d098bfdbed787b39d8facc0b74cf3cff73",
sha256 = "fc2eb31c2fef530c305dad5c4b38b3afcd90dd3955368c1acab8cfe38b7ecb03", sha256 = "807c22ebfb865aa35c17bae77b8f8ecc19c9509c122dbc36f6262cb3c83f1f3c",
patches = ["@upb//bazel:protobuf.patch"], patches = ["@upb//bazel:protobuf.patch"],
) )

@ -1601,6 +1601,19 @@ static PyObject* PyUpb_Message_WhichOneof(PyObject* _self, PyObject* name) {
return PyUnicode_FromString(upb_FieldDef_Name(f)); return PyUnicode_FromString(upb_FieldDef_Name(f));
} }
PyObject* DeepCopy(PyObject* _self, PyObject* arg) {
PyUpb_Message* self = (void*)_self;
PyObject* arena = PyUpb_Arena_New();
upb_Message* clone =
upb_Message_DeepClone(self->ptr.msg, upb_MessageDef_MiniTable(self->def),
PyUpb_Arena_Get(arena));
PyObject* ret = PyUpb_Message_Get(clone, self->def, arena);
Py_DECREF(arena);
return ret;
}
void PyUpb_Message_ClearExtensionDict(PyObject* _self) { void PyUpb_Message_ClearExtensionDict(PyObject* _self) {
PyUpb_Message* self = (void*)_self; PyUpb_Message* self = (void*)_self;
assert(self->ext_dict); assert(self->ext_dict);
@ -1630,9 +1643,9 @@ static PyGetSetDef PyUpb_Message_Getters[] = {
{NULL}}; {NULL}};
static PyMethodDef PyUpb_Message_Methods[] = { static PyMethodDef PyUpb_Message_Methods[] = {
{"__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
"Makes a deep copy of the class."},
// TODO(https://github.com/protocolbuffers/upb/issues/459) // TODO(https://github.com/protocolbuffers/upb/issues/459)
//{ "__deepcopy__", (PyCFunction)DeepCopy, METH_VARARGS,
// "Makes a deep copy of the class." },
//{ "__unicode__", (PyCFunction)ToUnicode, METH_NOARGS, //{ "__unicode__", (PyCFunction)ToUnicode, METH_NOARGS,
// "Outputs a unicode representation of the message." }, // "Outputs a unicode representation of the message." },
{"ByteSize", (PyCFunction)PyUpb_Message_ByteSize, METH_NOARGS, {"ByteSize", (PyCFunction)PyUpb_Message_ByteSize, METH_NOARGS,

Loading…
Cancel
Save