Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

upb: fix NULL pointer bug in Python FFI #693

Merged
merged 1 commit into from
Jul 13, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 21 additions & 0 deletions python/message.c
Original file line number Diff line number Diff line change
Expand Up @@ -556,6 +556,21 @@ static PyObject* PyUpb_Message_NewStub(PyObject* parent, const upb_FieldDef* f,
return &msg->ob_base;
}

static bool PyUpb_Message_IsEmpty(const upb_Message* msg,
const upb_MessageDef* m,
const upb_DefPool* ext_pool) {
if (!msg) return true;

size_t iter = kUpb_Message_Begin;
const upb_FieldDef* f;
upb_MessageValue val;
if (upb_Message_Next(msg, m, ext_pool, &f, &val, &iter)) return false;

size_t len;
(void)upb_Message_GetUnknown(msg, &len);
return len == 0;
}

static bool PyUpb_Message_IsEqual(PyUpb_Message* m1, PyObject* _m2) {
PyUpb_Message* m2 = (void*)_m2;
if (m1 == m2) return true;
Expand All @@ -569,6 +584,12 @@ static bool PyUpb_Message_IsEqual(PyUpb_Message* m1, PyObject* _m2) {
#endif
const upb_Message* m1_msg = PyUpb_Message_GetIfReified((PyObject*)m1);
const upb_Message* m2_msg = PyUpb_Message_GetIfReified(_m2);
const upb_DefPool* symtab = upb_FileDef_Pool(upb_MessageDef_File(m1_msgdef));

const bool e1 = PyUpb_Message_IsEmpty(m1_msg, m1_msgdef, symtab);
const bool e2 = PyUpb_Message_IsEmpty(m2_msg, m1_msgdef, symtab);
if (e1 || e2) return e1 && e2;

return upb_Message_IsEqual(m1_msg, m2_msg, m1_msgdef);
}

Expand Down