Skip to content

Commit

Permalink
patch upb CopyFrom error in protobuf-python 4.24.0
Browse files Browse the repository at this point in the history
  • Loading branch information
jfgrimm committed Jan 22, 2024
1 parent 8bb7c62 commit cdc8537
Show file tree
Hide file tree
Showing 2 changed files with 45 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,12 @@ toolchain = {'name': 'GCCcore', 'version': '12.3.0'}

source_urls = ['https://pypi.python.org/packages/source/p/protobuf']
sources = ['protobuf-%(version)s.tar.gz']
checksums = ['5d0ceb9de6e08311832169e601d1fc71bd8e8c779f3ee38a97a78554945ecb85']
patches = ['%(name)s-%(version)s_fix-upb-copyfrom.patch']
checksums = [
{'protobuf-4.24.0.tar.gz': '5d0ceb9de6e08311832169e601d1fc71bd8e8c779f3ee38a97a78554945ecb85'},
{'protobuf-python-4.24.0_fix-upb-copyfrom.patch':
'9afea4c68ee54d7278ec61a7e7d91c0aad2e7b0d63ba22f2200d0df2fac34de7'},
]

builddependencies = [('binutils', '2.40')]

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
From 57636ce03ac1e2aab3a362a61a6664981e21cda5 Mon Sep 17 00:00:00 2001
From: Jie Luo <[email protected]>
Date: Thu, 24 Aug 2023 14:27:41 -0700
Subject: [PATCH] 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
---
python/message.c | 15 +++++++++------
1 file changed, 9 insertions(+), 6 deletions(-)

diff --git a/python/message.c b/python/message.c
index afdd4311a..e61eebb23 100644
--- a/python/message.c
+++ b/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;

0 comments on commit cdc8537

Please sign in to comment.