From fd9d19d6659fa4b3331974debcd4420d1ff1e9b0 Mon Sep 17 00:00:00 2001 From: Joshua Haberman Date: Tue, 23 Nov 2021 18:56:37 -0800 Subject: [PATCH] Properly compare Python unknown fields. --- python/BUILD | 1 + python/convert.c | 7 ++----- upb/util/BUILD | 1 + 3 files changed, 4 insertions(+), 5 deletions(-) diff --git a/python/BUILD b/python/BUILD index 594643dd48..72b4aaba0c 100644 --- a/python/BUILD +++ b/python/BUILD @@ -63,6 +63,7 @@ cc_binary( ":version_script.lds", "//:reflection", "//:upb", + "//upb/util:compare", "@system_python//:python_headers", ], ) diff --git a/python/convert.c b/python/convert.c index c581100e92..0b611e8d42 100644 --- a/python/convert.c +++ b/python/convert.c @@ -29,6 +29,7 @@ #include "python/protobuf.h" #include "upb/reflection.h" +#include "upb/util/compare.h" PyObject* PyUpb_UpbToPy(upb_msgval val, const upb_fielddef *f, PyObject *arena) { switch (upb_fielddef_type(f)) { @@ -330,9 +331,5 @@ bool PyUpb_Message_IsEqual(const upb_msg *msg1, const upb_msg *msg2, size_t usize1, usize2; const char *uf1 = upb_msg_getunknown(msg1, &usize1); const char *uf2 = upb_msg_getunknown(msg2, &usize2); - // TODO(haberman): compare unknown fields one by one. - if (usize1 != usize2) return false; - if (memcmp(uf1, uf2, usize1)) return false; - - return true; + return upb_Message_UnknownFieldsAreEqual(uf1, usize1, uf2, usize2, 100); } diff --git a/upb/util/BUILD b/upb/util/BUILD index 355e6b7c5c..07649dedcb 100644 --- a/upb/util/BUILD +++ b/upb/util/BUILD @@ -94,6 +94,7 @@ cc_library( srcs = ["compare.c"], hdrs = ["compare.h"], deps = ["//:reflection"], + visibility = ["//visibility:public"], ) cc_test(